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
3 changes: 3 additions & 0 deletions apps/oxlint/fixtures/extends_config/plugins/jest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["jest"]
}
3 changes: 3 additions & 0 deletions apps/oxlint/fixtures/extends_config/plugins/react.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["react"]
}
59 changes: 57 additions & 2 deletions crates/oxc_linter/src/config/config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ impl ConfigStoreBuilder {
.rules
.override_rules(&mut builder.rules, &builder.cache.borrow());
// Use `ConfigStoreBuilder` to load extended config files and then apply rules from those
let extended_config_store =
let mut extended_config_store =
ConfigStoreBuilder::from_oxlintrc(true, extended_config)?;
builder = builder.with_rules(extended_config_store.rules);
let rules = std::mem::take(&mut extended_config_store.rules);
builder = builder.with_rules(rules);
builder = builder.and_plugins(extended_config_store.plugins(), true);
}
Err(err) => {
return Err(ConfigBuilderError::InvalidConfigFile {
Expand Down Expand Up @@ -878,6 +880,59 @@ mod test {
}
}

#[test]
fn test_extends_plugins() {
let config = config_store_from_str(
r#"
{
"extends": [
"../../apps/oxlint/fixtures/extends_config/plugins/jest.json",
"../../apps/oxlint/fixtures/extends_config/plugins/react.json"
]
}
"#,
);
assert!(config.plugins().contains(LintPlugins::default()));
assert!(config.plugins().contains(LintPlugins::JEST));
assert!(config.plugins().contains(LintPlugins::REACT));

// Test adding more plugins
let config = config_store_from_str(
r#"
{
"extends": [
"../../apps/oxlint/fixtures/extends_config/plugins/jest.json",
"../../apps/oxlint/fixtures/extends_config/plugins/react.json"
],
"plugins": ["typescript"]
}
"#,
);
assert_eq!(
config.plugins(),
LintPlugins::JEST | LintPlugins::REACT | LintPlugins::TYPESCRIPT
);

// Test that extended a config with a plugin is the same as adding it directly
let plugin_config = config_store_from_str(r#"{ "plugins": ["jest", "react"] }"#);
let extends_plugin_config = config_store_from_str(
r#"
{
"extends": [
"../../apps/oxlint/fixtures/extends_config/plugins/jest.json",
"../../apps/oxlint/fixtures/extends_config/plugins/react.json"
],
"plugins": []
}
"#,
);
assert_eq!(
plugin_config.plugins(),
extends_plugin_config.plugins(),
"Extending a config with a plugin is the same as adding it directly"
);
}

fn config_store_from_path(path: &str) -> ConfigStore {
ConfigStoreBuilder::from_oxlintrc(true, Oxlintrc::from_file(&PathBuf::from(path)).unwrap())
.unwrap()
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/config/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ impl ConfigStore {
&self.base.base.rules
}

pub fn plugins(&self) -> LintPlugins {
self.base.base.config.plugins
}

pub(crate) fn resolve(&self, path: &Path) -> ResolvedLinterState {
// TODO: based on the `path` provided, resolve the configuration file to use.
let resolved_config = &self.base;
Expand Down
Loading