Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/oxlint/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ describe('oxlint CLI', () => {
await testFixture('missing_custom_plugin');
});

it('should report an error if a custom plugin has a reserved name', async () => {
await testFixture('reserved_name');
});

it('should report an error if a custom plugin throws an error during import', async () => {
await testFixture('custom_plugin_import_error');
});
Expand Down
3 changes: 3 additions & 0 deletions apps/oxlint/test/fixtures/reserved_name/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"jsPlugins": ["./plugin.ts"]
}
15 changes: 15 additions & 0 deletions apps/oxlint/test/fixtures/reserved_name/output.snap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Exit code
1

# stdout
```
Failed to parse configuration file.

x Plugin name 'import' is reserved, and cannot be used for JS plugins
```

# stderr
```
WARNING: JS plugins are experimental and not subject to semver.
Breaking changes are possible while JS plugins support is under development.
```
10 changes: 10 additions & 0 deletions apps/oxlint/test/fixtures/reserved_name/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Plugin } from '../../../dist/index.js';

const plugin: Plugin = {
meta: {
name: 'import', // Reserved name
},
rules: {},
};

export default plugin;
18 changes: 16 additions & 2 deletions crates/oxc_linter/src/config/config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,12 @@ impl ConfigStoreBuilder {

match result {
PluginLoadResult::Success { name, offset, rule_names } => {
external_plugin_store.register_plugin(plugin_path, name, offset, rule_names);
Ok(())
if name != "eslint" && LintPlugins::from(name.as_str()) == LintPlugins::empty() {
external_plugin_store.register_plugin(plugin_path, name, offset, rule_names);
Ok(())
} else {
Err(ConfigBuilderError::ReservedExternalPluginName { plugin_name: name })
Comment thread
overlookmotel marked this conversation as resolved.
}
}
PluginLoadResult::Failure(e) => Err(ConfigBuilderError::PluginLoadFailed {
plugin_specifier: plugin_specifier.to_string(),
Expand Down Expand Up @@ -580,6 +584,9 @@ pub enum ConfigBuilderError {
NoExternalLinterConfigured {
plugin_specifier: String,
},
ReservedExternalPluginName {
plugin_name: String,
},
}

impl Display for ConfigBuilderError {
Expand Down Expand Up @@ -610,6 +617,13 @@ impl Display for ConfigBuilderError {
)?;
Ok(())
}
ConfigBuilderError::ReservedExternalPluginName { plugin_name } => {
write!(
f,
"Plugin name '{plugin_name}' is reserved, and cannot be used for JS plugins",
)?;
Ok(())
}
ConfigBuilderError::ExternalRuleLookupError(e) => std::fmt::Display::fmt(&e, f),
}
}
Expand Down
Loading