Skip to content

Commit a0022c1

Browse files
committed
refactor(linter/plugins): improve error messages for JS plugins (#13699)
Amend error messages related to JS plugins. "external" is the term we use in the codebase, but it probably wouldn't make much sense to end users. Use the term "JS plugin" instead.
1 parent 9126c93 commit a0022c1

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

crates/oxc_linter/src/config/config_builder.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,13 @@ impl Display for ConfigBuilderError {
594594
write!(f, "invalid config file {file}: {reason}")
595595
}
596596
ConfigBuilderError::PluginLoadFailed { plugin_specifier, error } => {
597-
write!(f, "Failed to load external plugin: {plugin_specifier}\n {error}")?;
597+
write!(f, "Failed to load JS plugin: {plugin_specifier}\n {error}")?;
598598
Ok(())
599599
}
600600
ConfigBuilderError::NoExternalLinterConfigured => {
601-
f.write_str("Failed to load external plugin because no external linter was configured. This means the Oxlint binary was executed directly rather than via napi bindings.")?;
601+
f.write_str(
602+
"JS plugins are not supported without `--experimental-js-plugins` CLI option",
603+
)?;
602604
Ok(())
603605
}
604606
ConfigBuilderError::ExternalRuleLookupError(e) => std::fmt::Display::fmt(&e, f),

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,18 @@ 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 cannot be loaded 1`] = `
448448
"Failed to parse configuration file.
449449
450-
x Failed to load external plugin: ./test_plugin
450+
x Failed to load JS plugin: ./test_plugin
451451
| Cannot find module './test_plugin'
452452
"
453453
`;
454454

455+
exports[`oxlint CLI > should report an error if a custom plugin in config but JS plugins are not enabled 1`] = `
456+
"Failed to parse configuration file.
457+
458+
x JS plugins are not supported without \`--experimental-js-plugins\` CLI option
459+
"
460+
`;
461+
455462
exports[`oxlint CLI > should report an error if a rule is not found within a custom plugin 1`] = `
456463
"Failed to parse configuration file.
457464

napi/oxlint/test/e2e.test.ts

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

70+
it('should report an error if a custom plugin in config but JS plugins are not enabled', async () => {
71+
const { stdout, exitCode } = await runOxlintWithoutPlugins('test/fixtures/basic_custom_plugin');
72+
expect(exitCode).toBe(1);
73+
expect(normalizeOutput(stdout)).toMatchSnapshot();
74+
});
75+
7076
it('should report an error if a custom plugin cannot be loaded', async () => {
7177
const { stdout, exitCode } = await runOxlint('test/fixtures/missing_custom_plugin');
7278
expect(exitCode).toBe(1);

0 commit comments

Comments
 (0)