Skip to content

Commit f51240e

Browse files
committed
test(linter/plugins): tests for different import styles (#13859)
Add tests for importing plugins via various path styles and module formats: * CommonJS * ESM * Relative path to file * Relative path to directory * Package in `node_modules`
1 parent fac7624 commit f51240e

File tree

13 files changed

+205
-2
lines changed

13 files changed

+205
-2
lines changed

apps/oxlint/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
node_modules/
1+
/node_modules/
2+
/dist/
23
*.node
3-
dist/

apps/oxlint/test/__snapshots__/e2e.test.ts.snap

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,55 @@ Found 20 warnings and 20 errors.
395395
Finished in Xms on 20 files using X threads."
396396
`;
397397

398+
exports[`oxlint CLI > should load a custom plugin with various import styles 1`] = `
399+
"
400+
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed
401+
,-[index.js:1:1]
402+
1 | debugger;
403+
: ^^^^^^^^^
404+
\`----
405+
help: Remove the debugger statement
406+
407+
x plugin1(no-debugger): Unexpected Debugger Statement
408+
,-[index.js:1:1]
409+
1 | debugger;
410+
: ^^^^^^^^^
411+
\`----
412+
413+
x plugin2(no-debugger): Unexpected Debugger Statement
414+
,-[index.js:1:1]
415+
1 | debugger;
416+
: ^^^^^^^^^
417+
\`----
418+
419+
x plugin3(no-debugger): Unexpected Debugger Statement
420+
,-[index.js:1:1]
421+
1 | debugger;
422+
: ^^^^^^^^^
423+
\`----
424+
425+
x plugin4(no-debugger): Unexpected Debugger Statement
426+
,-[index.js:1:1]
427+
1 | debugger;
428+
: ^^^^^^^^^
429+
\`----
430+
431+
x plugin5(no-debugger): Unexpected Debugger Statement
432+
,-[index.js:1:1]
433+
1 | debugger;
434+
: ^^^^^^^^^
435+
\`----
436+
437+
x plugin6(no-debugger): Unexpected Debugger Statement
438+
,-[index.js:1:1]
439+
1 | debugger;
440+
: ^^^^^^^^^
441+
\`----
442+
443+
Found 1 warning and 6 errors.
444+
Finished in Xms on 1 file using X threads."
445+
`;
446+
398447
exports[`oxlint CLI > should receive data via \`context\` 1`] = `
399448
"
400449
x context-plugin(log-context): id: context-plugin/log-context

apps/oxlint/test/e2e.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ describe('oxlint CLI', () => {
7676
expect(normalizeOutput(stdout)).toMatchSnapshot();
7777
});
7878

79+
it('should load a custom plugin with various import styles', async () => {
80+
const { stdout, exitCode } = await runOxlint('test/fixtures/load_paths');
81+
expect(exitCode).toBe(1);
82+
expect(normalizeOutput(stdout)).toMatchSnapshot();
83+
});
84+
7985
it('should load a custom plugin with multiple files', async () => {
8086
const { stdout, exitCode } = await runOxlint('test/fixtures/basic_custom_plugin_many_files');
8187
expect(exitCode).toBe(1);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"plugins": [
3+
"./plugins/test_plugin1.js",
4+
"./plugins/test_plugin2.cjs",
5+
"./plugins/test_plugin3.mjs",
6+
"./plugins/test_plugin4",
7+
"test_plugin5",
8+
"test_plugin6"
9+
],
10+
"rules": {
11+
"plugin1/no-debugger": "error",
12+
"plugin2/no-debugger": "error",
13+
"plugin3/no-debugger": "error",
14+
"plugin4/no-debugger": "error",
15+
"plugin5/no-debugger": "error",
16+
"plugin6/no-debugger": "error"
17+
},
18+
"ignorePatterns": ["plugins/**", "node_modules/**"]
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
debugger;

apps/oxlint/test/fixtures/load_paths/node_modules/test_plugin5/index.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/oxlint/test/fixtures/load_paths/node_modules/test_plugin5/package.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/oxlint/test/fixtures/load_paths/node_modules/test_plugin6/package.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/oxlint/test/fixtures/load_paths/node_modules/test_plugin6/plugin.js

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default {
2+
meta: {
3+
name: "plugin1",
4+
},
5+
rules: {
6+
"no-debugger": {
7+
create(context) {
8+
return {
9+
DebuggerStatement(debuggerStatement) {
10+
context.report({
11+
message: "Unexpected Debugger Statement",
12+
node: debuggerStatement,
13+
});
14+
},
15+
};
16+
},
17+
},
18+
},
19+
};

0 commit comments

Comments
 (0)