Skip to content

Commit 0e5fe19

Browse files
committed
feat(linter): support import-x plugin name
1 parent d266c29 commit 0e5fe19

6 files changed

+57
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"plugins": ["import"],
3+
"rules": {
4+
"import-x/no-default-export": "error",
5+
"import-x/namespace": "allow"
6+
}
7+
}

apps/oxlint/src/lint.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,12 @@ mod test {
678678

679679
#[test]
680680
fn test_import_plugin_enabled_in_config() {
681-
let args = &["-c", "fixtures/import/.oxlintrc.json", "fixtures/import/test.js"];
682-
Tester::new().test_and_snapshot(args);
681+
let args_1 = &["-c", ".oxlintrc.json", "test.js"];
682+
// support import-x namespace see #8779
683+
let args_2 = &["-c", ".oxlintrc-import-x.json", "test.js"];
684+
Tester::new()
685+
.with_cwd("fixtures/import".into())
686+
.test_and_snapshot_multiple(&[args_1, args_2]);
683687
}
684688

685689
#[test]

apps/oxlint/src/snapshots/_-c fixtures__import__.oxlintrc.json fixtures__import__test.js@oxlint.snap

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: -c .oxlintrc.json test.js
6+
working directory: fixtures/import
7+
----------
8+
9+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/import/no-default-export.html\eslint-plugin-import(no-default-export)]8;;\: Prefer named exports
10+
,-[test.js:7:8]
11+
6 | // import/no-default-export
12+
7 | export default function foo() {}
13+
: ^^^^^^^
14+
8 |
15+
`----
16+
17+
Found 0 warnings and 1 error.
18+
Finished in <variable>ms on 1 file with 50 rules using 1 threads.
19+
----------
20+
CLI result: LintFoundErrors
21+
----------
22+
23+
##########
24+
arguments: -c .oxlintrc-import-x.json test.js
25+
working directory: fixtures/import
26+
----------
27+
28+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/import/no-default-export.html\eslint-plugin-import(no-default-export)]8;;\: Prefer named exports
29+
,-[test.js:7:8]
30+
6 | // import/no-default-export
31+
7 | export default function foo() {}
32+
: ^^^^^^^
33+
8 |
34+
`----
35+
36+
Found 0 warnings and 1 error.
37+
Finished in <variable>ms on 1 file with 50 rules using 1 threads.
38+
----------
39+
CLI result: LintFoundErrors
40+
----------

crates/oxc_linter/src/config/plugins.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ impl From<&str> for LintPlugins {
103103
}
104104
// deepscan for backwards compatibility. Those rules have been moved into oxc
105105
"oxc" | "deepscan" => LintPlugins::OXC,
106-
"import" => LintPlugins::IMPORT,
106+
// import-x has the same rules but better performance
107+
"import" | "import-x" => LintPlugins::IMPORT,
107108
"jsdoc" => LintPlugins::JSDOC,
108109
"jest" => LintPlugins::JEST,
109110
"vitest" => LintPlugins::VITEST,

crates/oxc_linter/src/config/rules.rs

+2
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ fn parse_rule_key(name: &str) -> (String, String) {
282282

283283
let (oxlint_plugin_name, rule_name) = match plugin_name {
284284
"@typescript-eslint" => ("typescript", rule_name),
285+
// import-x has the same rules but better performance
286+
"import-x" => ("import", rule_name),
285287
"jsx-a11y" => ("jsx_a11y", rule_name),
286288
"react-perf" => ("react_perf", rule_name),
287289
// e.g. "@next/next/google-font-display"

0 commit comments

Comments
 (0)