Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"jsPlugins": [
{ "name": "custom", "specifier": "./plugin1.ts" },
{ "name": "custom", "specifier": "./plugin2.ts" }
],
"rules": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const x = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Exit code
1

# stdout
```
Failed to parse configuration file.

x Plugin name 'custom' is already in use.
|
| Multiple plugins cannot share the same name or alias.
| Each plugin must have a unique identifier to avoid conflicts.
|
| Please provide a different alias for one of the plugins:
|
| "jsPlugins": [
| { "name": "custom", "specifier": "plugin-one" },
| { "name": "custom-alt", "specifier": "plugin-two" }
| ]
```

# stderr
```
WARNING: JS plugins are experimental and not subject to semver.
Breaking changes are possible while JS plugins support is under development.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Plugin } from "#oxlint";

const plugin: Plugin = {
meta: {
name: "first-plugin",
},
rules: {
"rule-one": {
meta: {
type: "problem",
},
create(context) {
return {};
},
},
},
};

export default plugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Plugin } from "#oxlint";

const plugin: Plugin = {
meta: {
name: "second-plugin",
},
rules: {
"rule-two": {
meta: {
type: "problem",
},
create(context) {
return {};
},
},
},
};

export default plugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"jsPlugins": [
"./plugin.ts",
{ "name": "foo", "specifier": "./other.ts" }
],
"rules": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const x = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Plugin } from "#oxlint";

const plugin: Plugin = {
meta: {
name: "other-plugin",
},
rules: {},
};

export default plugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Exit code
1

# stdout
```
Failed to parse configuration file.

x Plugin name 'foo' is already in use.
|
| Multiple plugins cannot share the same name or alias.
| Each plugin must have a unique identifier to avoid conflicts.
|
| Please provide a different alias for one of the plugins:
|
| "jsPlugins": [
| { "name": "foo", "specifier": "plugin-one" },
| { "name": "foo-alt", "specifier": "plugin-two" }
| ]
```

# stderr
```
WARNING: JS plugins are experimental and not subject to semver.
Breaking changes are possible while JS plugins support is under development.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Plugin } from "#oxlint";

const plugin: Plugin = {
meta: {
name: "foo",
},
rules: {
"test-rule": {
meta: {
type: "problem",
},
create(context) {
return {};
},
},
},
};

export default plugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"jsPlugins": [
"./plugin1.ts",
"./plugin2.ts"
],
"rules": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const x = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Exit code
1

# stdout
```
Failed to parse configuration file.

x Plugin name 'shared-name' is already in use.
|
| Multiple plugins cannot share the same name or alias.
| Each plugin must have a unique identifier to avoid conflicts.
|
| Please provide a different alias for one of the plugins:
|
| "jsPlugins": [
| { "name": "shared-name", "specifier": "plugin-one" },
| { "name": "shared-name-alt", "specifier": "plugin-two" }
| ]
```

# stderr
```
WARNING: JS plugins are experimental and not subject to semver.
Breaking changes are possible while JS plugins support is under development.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Plugin } from "#oxlint";

const plugin: Plugin = {
meta: {
name: "shared-name",
},
rules: {
"rule-one": {
meta: {
type: "problem",
},
create(context) {
return {};
},
},
},
};

export default plugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Plugin } from "#oxlint";

const plugin: Plugin = {
meta: {
name: "shared-name",
},
rules: {
"rule-two": {
meta: {
type: "problem",
},
create(context) {
return {};
},
},
},
};

export default plugin;
44 changes: 34 additions & 10 deletions crates/oxc_linter/src/config/config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,17 +578,21 @@ impl ConfigStoreBuilder {
})?;
let plugin_name = result.name;

if LintPlugins::try_from(plugin_name.as_str()).is_err() {
external_plugin_store.register_plugin(
plugin_path,
plugin_name,
result.offset,
result.rule_names,
);
Ok(())
} else {
Err(ConfigBuilderError::ReservedExternalPluginName { plugin_name })
if LintPlugins::try_from(plugin_name.as_str()).is_ok() {
return Err(ConfigBuilderError::ReservedExternalPluginName { plugin_name });
}

if external_plugin_store.is_plugin_name_registered(&plugin_name) {
return Err(ConfigBuilderError::DuplicatePluginAlias { plugin_name });
}

external_plugin_store.register_plugin(
plugin_path,
plugin_name,
result.offset,
result.rule_names,
);
Ok(())
}
}

Expand Down Expand Up @@ -632,6 +636,9 @@ pub enum ConfigBuilderError {
ReservedExternalPluginName {
plugin_name: String,
},
DuplicatePluginAlias {
plugin_name: String,
},
}

impl Display for ConfigBuilderError {
Expand Down Expand Up @@ -682,6 +689,23 @@ impl Display for ConfigBuilderError {
)?;
Ok(())
}
ConfigBuilderError::DuplicatePluginAlias { plugin_name } => {
write!(
f,
"Plugin name '{plugin_name}' is already in use.\n\
\n\
Multiple plugins cannot share the same name or alias.\n\
Each plugin must have a unique identifier to avoid conflicts.\n\
\n\
Please provide a different alias for one of the plugins:\n\
\n\
\"jsPlugins\": [\n \
{{ \"name\": \"{plugin_name}\", \"specifier\": \"plugin-one\" }},\n \
{{ \"name\": \"{plugin_name}-alt\", \"specifier\": \"plugin-two\" }}\n\
]",
)?;
Ok(())
}
ConfigBuilderError::ExternalRuleLookupError(e) => std::fmt::Display::fmt(&e, f),
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/external_plugin_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ impl ExternalPluginStore {
self.registered_plugin_paths.contains(plugin_path)
}

pub fn is_plugin_name_registered(&self, plugin_name: &str) -> bool {
self.plugin_names.contains_key(plugin_name)
}

/// Register plugin.
///
/// # Panics
Expand Down