From 7affe94f1fd8c0971e4c79c09aa05763e837b925 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Sun, 12 Oct 2025 09:20:46 +0800 Subject: [PATCH 1/4] fix(linter/plugins): resolve JS plugins with ESM condition names --- crates/oxc_linter/src/config/config_builder.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/oxc_linter/src/config/config_builder.rs b/crates/oxc_linter/src/config/config_builder.rs index 6d81043e89de1..7d12351162d44 100644 --- a/crates/oxc_linter/src/config/config_builder.rs +++ b/crates/oxc_linter/src/config/config_builder.rs @@ -4,7 +4,7 @@ use std::{ }; use itertools::Itertools; -use oxc_resolver::Resolver; +use oxc_resolver::{ResolveOptions, Resolver}; use rustc_hash::{FxHashMap, FxHashSet}; use oxc_span::{CompactStr, format_compact_str}; @@ -169,7 +169,10 @@ impl ConfigStoreBuilder { return Err(ConfigBuilderError::NoExternalLinterConfigured { plugin_specifier }); }; - let resolver = Resolver::default(); + let resolver = Resolver::new(ResolveOptions { + condition_names: vec!["node".into(), "import".into()], + ..Default::default() + }); #[expect(clippy::missing_panics_doc, reason = "oxlintrc.path is always a file path")] let oxlintrc_dir = oxlintrc.path.parent().unwrap(); From 25f08785cdebe0f17a9d47380a661c4ea64f641e Mon Sep 17 00:00:00 2001 From: magic-akari Date: Mon, 13 Oct 2025 13:05:41 +0800 Subject: [PATCH 2/4] chore: add test cases --- .../test/fixtures/load_paths/.oxlintrc.json | 6 ++++-- .../node_modules/plugin10/index.cjs | 21 +++++++++++++++++++ .../load_paths/node_modules/plugin10/index.js | 19 +++++++++++++++++ .../node_modules/plugin10/package.json | 10 +++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 apps/oxlint/test/fixtures/load_paths/node_modules/plugin10/index.cjs create mode 100644 apps/oxlint/test/fixtures/load_paths/node_modules/plugin10/index.js create mode 100644 apps/oxlint/test/fixtures/load_paths/node_modules/plugin10/package.json diff --git a/apps/oxlint/test/fixtures/load_paths/.oxlintrc.json b/apps/oxlint/test/fixtures/load_paths/.oxlintrc.json index 6feb262f80dd2..bb64a807ee6b5 100644 --- a/apps/oxlint/test/fixtures/load_paths/.oxlintrc.json +++ b/apps/oxlint/test/fixtures/load_paths/.oxlintrc.json @@ -8,7 +8,8 @@ "./plugins/plugin6.mts", "./plugins/plugin7", "plugin8", - "plugin9" + "plugin9", + "plugin10" ], "rules": { "plugin1/no-debugger": "error", @@ -19,6 +20,7 @@ "plugin6/no-debugger": "error", "plugin7/no-debugger": "error", "plugin8/no-debugger": "error", - "plugin9/no-debugger": "error" + "plugin9/no-debugger": "error", + "plugin10/no-debugger": "error" } } diff --git a/apps/oxlint/test/fixtures/load_paths/node_modules/plugin10/index.cjs b/apps/oxlint/test/fixtures/load_paths/node_modules/plugin10/index.cjs new file mode 100644 index 0000000000000..bbe364bee89b1 --- /dev/null +++ b/apps/oxlint/test/fixtures/load_paths/node_modules/plugin10/index.cjs @@ -0,0 +1,21 @@ +'use strict'; + +module.exports = { + meta: { + name: "plugin10", + }, + rules: { + "no-debugger": { + create(context) { + return { + DebuggerStatement(debuggerStatement) { + context.report({ + message: "Unexpected Debugger Statement", + node: debuggerStatement, + }); + }, + }; + }, + }, + }, +}; diff --git a/apps/oxlint/test/fixtures/load_paths/node_modules/plugin10/index.js b/apps/oxlint/test/fixtures/load_paths/node_modules/plugin10/index.js new file mode 100644 index 0000000000000..ee5a1a0ce4252 --- /dev/null +++ b/apps/oxlint/test/fixtures/load_paths/node_modules/plugin10/index.js @@ -0,0 +1,19 @@ +export default { + meta: { + name: "plugin10", + }, + rules: { + "no-debugger": { + create(context) { + return { + DebuggerStatement(debuggerStatement) { + context.report({ + message: "Unexpected Debugger Statement", + node: debuggerStatement, + }); + }, + }; + }, + }, + }, +}; diff --git a/apps/oxlint/test/fixtures/load_paths/node_modules/plugin10/package.json b/apps/oxlint/test/fixtures/load_paths/node_modules/plugin10/package.json new file mode 100644 index 0000000000000..1ef304dcda024 --- /dev/null +++ b/apps/oxlint/test/fixtures/load_paths/node_modules/plugin10/package.json @@ -0,0 +1,10 @@ +{ + "name": "plugin10", + "type": "module", + "exports": { + ".": { + "import": "./index.js", + "require": "./index.cjs" + } + } +} From 0fc2b0b5a65153b36926737e8505934cdf3c110a Mon Sep 17 00:00:00 2001 From: magic-akari Date: Mon, 13 Oct 2025 13:36:36 +0800 Subject: [PATCH 3/4] fix: correcrt `main_fields` and `condition_names` --- crates/oxc_linter/src/config/config_builder.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/oxc_linter/src/config/config_builder.rs b/crates/oxc_linter/src/config/config_builder.rs index 7d12351162d44..78319fcdccf27 100644 --- a/crates/oxc_linter/src/config/config_builder.rs +++ b/crates/oxc_linter/src/config/config_builder.rs @@ -170,7 +170,8 @@ impl ConfigStoreBuilder { }; let resolver = Resolver::new(ResolveOptions { - condition_names: vec!["node".into(), "import".into()], + main_fields: vec!["module".into(), "main".into()], + condition_names: vec!["module".into(), "import".into()], ..Default::default() }); From a77a8c23658e3efa2c3930657d0a7cc26a112a0f Mon Sep 17 00:00:00 2001 From: magic-akari Date: Mon, 13 Oct 2025 15:50:52 +0800 Subject: [PATCH 4/4] chore: update snapshot --- apps/oxlint/test/fixtures/load_paths/output.snap.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/oxlint/test/fixtures/load_paths/output.snap.md b/apps/oxlint/test/fixtures/load_paths/output.snap.md index 30e941bf52591..4779f03d15b3b 100644 --- a/apps/oxlint/test/fixtures/load_paths/output.snap.md +++ b/apps/oxlint/test/fixtures/load_paths/output.snap.md @@ -16,6 +16,12 @@ : ^^^^^^^^^ `---- + x plugin10(no-debugger): Unexpected Debugger Statement + ,-[files/index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + `---- + x plugin2(no-debugger): Unexpected Debugger Statement ,-[files/index.js:1:1] 1 | debugger; @@ -64,7 +70,7 @@ : ^^^^^^^^^ `---- -Found 1 warning and 9 errors. +Found 1 warning and 10 errors. Finished in Xms on 1 file using X threads. ```