diff --git a/apps/oxlint/src-js/index.ts b/apps/oxlint/src-js/index.ts index b368a800140ff..de8c61267eec0 100644 --- a/apps/oxlint/src-js/index.ts +++ b/apps/oxlint/src-js/index.ts @@ -1,11 +1,16 @@ import type { Context } from './plugins/context.ts'; -import type { Rule } from './plugins/load.ts'; +import type { Plugin, Rule } from './plugins/load.ts'; const { defineProperty, getPrototypeOf, setPrototypeOf } = Object; const dummyOptions: unknown[] = [], dummyReport = () => {}; +// Define a plugin. +export function definePlugin(plugin: Plugin): Plugin { + return plugin; +} + // Define a rule. // If rule has `createOnce` method, add an ESLint-compatible `create` method which delegates to `createOnce`. export function defineRule(rule: Rule): Rule { diff --git a/apps/oxlint/src-js/plugins/load.ts b/apps/oxlint/src-js/plugins/load.ts index 7614d6643bce9..eec513ef0ba9d 100644 --- a/apps/oxlint/src-js/plugins/load.ts +++ b/apps/oxlint/src-js/plugins/load.ts @@ -4,7 +4,7 @@ import { getErrorMessage } from './utils.js'; import type { AfterHook, BeforeHook, Visitor, VisitorWithHooks } from './types.ts'; // Linter plugin, comprising multiple rules -interface Plugin { +export interface Plugin { meta: { name: string; }; diff --git a/apps/oxlint/test/__snapshots__/e2e.test.ts.snap b/apps/oxlint/test/__snapshots__/e2e.test.ts.snap index 6210f9725c162..717a4880346fb 100644 --- a/apps/oxlint/test/__snapshots__/e2e.test.ts.snap +++ b/apps/oxlint/test/__snapshots__/e2e.test.ts.snap @@ -800,7 +800,7 @@ Found 0 warnings and 26 errors. Finished in Xms on 2 files using X threads." `; -exports[`oxlint CLI > should support \`defineRule\` 1`] = ` +exports[`oxlint CLI > should support \`defineRule\` + \`definePlugin\` 1`] = ` " x define-rule-plugin(create): create body: | this === rule: true diff --git a/apps/oxlint/test/__snapshots__/eslint-compat.test.ts.snap b/apps/oxlint/test/__snapshots__/eslint-compat.test.ts.snap index 50ebc3818cf72..923475359e7cf 100644 --- a/apps/oxlint/test/__snapshots__/eslint-compat.test.ts.snap +++ b/apps/oxlint/test/__snapshots__/eslint-compat.test.ts.snap @@ -1,8 +1,8 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`ESLint compatibility > \`defineRule\` should work 1`] = ` +exports[`ESLint compatibility > \`defineRule\` + \`definePlugin\` should work 1`] = ` " -/apps/oxlint/test/fixtures/defineRule/files/1.js +/apps/oxlint/test/fixtures/define/files/1.js 0:1 error create body: this === rule: true testPlugin/create 0:1 error before hook: @@ -22,7 +22,7 @@ filename: files/1.js testPlugin/create identNum: 2 filename: files/1.js testPlugin/create-once -/apps/oxlint/test/fixtures/defineRule/files/2.js +/apps/oxlint/test/fixtures/define/files/2.js 0:1 error create body: this === rule: true testPlugin/create 0:1 error before hook: diff --git a/apps/oxlint/test/e2e.test.ts b/apps/oxlint/test/e2e.test.ts index 5903d124f7356..6e66c32bf55be 100644 --- a/apps/oxlint/test/e2e.test.ts +++ b/apps/oxlint/test/e2e.test.ts @@ -154,8 +154,8 @@ describe('oxlint CLI', () => { expect(normalizeOutput(stdout)).toMatchSnapshot(); }); - it('should support `defineRule`', async () => { - const { stdout, exitCode } = await runOxlint('test/fixtures/defineRule'); + it('should support `defineRule` + `definePlugin`', async () => { + const { stdout, exitCode } = await runOxlint('test/fixtures/define'); expect(exitCode).toBe(1); expect(normalizeOutput(stdout)).toMatchSnapshot(); }); diff --git a/apps/oxlint/test/eslint-compat.test.ts b/apps/oxlint/test/eslint-compat.test.ts index 8101d30a0d84e..a80e02b8687c8 100644 --- a/apps/oxlint/test/eslint-compat.test.ts +++ b/apps/oxlint/test/eslint-compat.test.ts @@ -24,8 +24,8 @@ function normalizeOutput(output: string): string { } describe('ESLint compatibility', () => { - it('`defineRule` should work', async () => { - const { stdout, exitCode } = await runEslint('test/fixtures/defineRule'); + it('`defineRule` + `definePlugin` should work', async () => { + const { stdout, exitCode } = await runEslint('test/fixtures/define'); expect(exitCode).toBe(1); expect(normalizeOutput(stdout)).toMatchSnapshot(); }); diff --git a/apps/oxlint/test/fixtures/defineRule/.oxlintrc.json b/apps/oxlint/test/fixtures/define/.oxlintrc.json similarity index 100% rename from apps/oxlint/test/fixtures/defineRule/.oxlintrc.json rename to apps/oxlint/test/fixtures/define/.oxlintrc.json diff --git a/apps/oxlint/test/fixtures/defineRule/eslint.config.js b/apps/oxlint/test/fixtures/define/eslint.config.js similarity index 100% rename from apps/oxlint/test/fixtures/defineRule/eslint.config.js rename to apps/oxlint/test/fixtures/define/eslint.config.js diff --git a/apps/oxlint/test/fixtures/defineRule/files/1.js b/apps/oxlint/test/fixtures/define/files/1.js similarity index 100% rename from apps/oxlint/test/fixtures/defineRule/files/1.js rename to apps/oxlint/test/fixtures/define/files/1.js diff --git a/apps/oxlint/test/fixtures/defineRule/files/2.js b/apps/oxlint/test/fixtures/define/files/2.js similarity index 100% rename from apps/oxlint/test/fixtures/defineRule/files/2.js rename to apps/oxlint/test/fixtures/define/files/2.js diff --git a/apps/oxlint/test/fixtures/defineRule/test_plugin/index.js b/apps/oxlint/test/fixtures/define/test_plugin/index.js similarity index 96% rename from apps/oxlint/test/fixtures/defineRule/test_plugin/index.js rename to apps/oxlint/test/fixtures/define/test_plugin/index.js index 84ccc57c94310..524eedbb14bd1 100644 --- a/apps/oxlint/test/fixtures/defineRule/test_plugin/index.js +++ b/apps/oxlint/test/fixtures/define/test_plugin/index.js @@ -1,5 +1,5 @@ import { dirname, sep } from 'node:path'; -import { defineRule } from '../../../../dist/index.js'; +import { defineRule, definePlugin } from '../../../../dist/index.js'; // `loc` field is required for ESLint. // TODO: Remove this workaround when AST nodes have a `loc` field. @@ -100,7 +100,7 @@ const createOnceRule = defineRule({ }, }); -export default { +export default definePlugin({ meta: { name: "define-rule-plugin", }, @@ -108,4 +108,4 @@ export default { create: createRule, "create-once": createOnceRule, }, -}; +});