Skip to content

Commit fac7624

Browse files
committed
fix(linter/plugins): improve error for no JS plugins (#13858)
Improve the error message when an unrecognised name is found in `plugins` config. Specify the offending entry in plugins. This should guide users to what the problem is, and avoid confusion like in #13739.
1 parent 7db4d35 commit fac7624

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ exports[`oxlint CLI > should report an error if a a rule is not found within a c
447447
exports[`oxlint CLI > should report an error if a custom plugin in config but JS plugins are not enabled 1`] = `
448448
"Failed to parse configuration file.
449449
450-
x JS plugins are not supported without \`--experimental-js-plugins\` CLI option
450+
x \`plugins\` config contains './test_plugin'. JS plugins are not supported without \`--experimental-js-plugins\` CLI option
451451
"
452452
`;
453453

crates/oxc_linter/src/config/config_builder.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,11 @@ impl ConfigStoreBuilder {
162162
}
163163

164164
if !external_plugins.is_empty() {
165-
let external_linter =
166-
external_linter.ok_or(ConfigBuilderError::NoExternalLinterConfigured)?;
165+
let Some(external_linter) = external_linter else {
166+
#[expect(clippy::missing_panics_doc, reason = "infallible")]
167+
let plugin_specifier = external_plugins.iter().next().unwrap().clone();
168+
return Err(ConfigBuilderError::NoExternalLinterConfigured { plugin_specifier });
169+
};
167170

168171
let resolver = Resolver::default();
169172

@@ -573,7 +576,9 @@ pub enum ConfigBuilderError {
573576
error: String,
574577
},
575578
ExternalRuleLookupError(ExternalRuleLookupError),
576-
NoExternalLinterConfigured,
579+
NoExternalLinterConfigured {
580+
plugin_specifier: String,
581+
},
577582
}
578583

579584
impl Display for ConfigBuilderError {
@@ -597,9 +602,10 @@ impl Display for ConfigBuilderError {
597602
write!(f, "Failed to load JS plugin: {plugin_specifier}\n {error}")?;
598603
Ok(())
599604
}
600-
ConfigBuilderError::NoExternalLinterConfigured => {
601-
f.write_str(
602-
"JS plugins are not supported without `--experimental-js-plugins` CLI option",
605+
ConfigBuilderError::NoExternalLinterConfigured { plugin_specifier } => {
606+
write!(
607+
f,
608+
"`plugins` config contains '{plugin_specifier}'. JS plugins are not supported without `--experimental-js-plugins` CLI option",
603609
)?;
604610
Ok(())
605611
}

0 commit comments

Comments
 (0)