Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/oxlint/src-js/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/src-js/plugins/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/test/__snapshots__/e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions apps/oxlint/test/__snapshots__/eslint-compat.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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`] = `
"
<root>/apps/oxlint/test/fixtures/defineRule/files/1.js
<root>/apps/oxlint/test/fixtures/define/files/1.js
0:1 error create body:
this === rule: true testPlugin/create
0:1 error before hook:
Expand All @@ -22,7 +22,7 @@ filename: files/1.js testPlugin/create
identNum: 2
filename: files/1.js testPlugin/create-once

<root>/apps/oxlint/test/fixtures/defineRule/files/2.js
<root>/apps/oxlint/test/fixtures/define/files/2.js
0:1 error create body:
this === rule: true testPlugin/create
0:1 error before hook:
Expand Down
4 changes: 2 additions & 2 deletions apps/oxlint/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
4 changes: 2 additions & 2 deletions apps/oxlint/test/eslint-compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -100,12 +100,12 @@ const createOnceRule = defineRule({
},
});

export default {
export default definePlugin({
meta: {
name: "define-rule-plugin",
},
rules: {
create: createRule,
"create-once": createOnceRule,
},
};
});
Loading