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
8 changes: 6 additions & 2 deletions crates/oxc_linter/src/config/config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ impl ConfigStoreBuilder {
LintFilterKind::Category(category) => {
self.upsert_where(severity, |r| r.category() == *category);
}
LintFilterKind::Rule(_, name) => self.upsert_where(severity, |r| r.name() == name),
LintFilterKind::Rule(plugin, rule) => {
self.upsert_where(severity, |r| r.plugin_name() == plugin && r.name() == rule);
}
LintFilterKind::Generic(name) => self.upsert_where(severity, |r| r.name() == name),
LintFilterKind::All => {
self.upsert_where(severity, |r| r.category() != RuleCategory::Nursery);
Expand All @@ -264,7 +266,9 @@ impl ConfigStoreBuilder {
LintFilterKind::Category(category) => {
self.rules.retain(|rule| rule.category() != *category);
}
LintFilterKind::Rule(_, name) => self.rules.retain(|rule| rule.name() != name),
LintFilterKind::Rule(plugin, rule) => {
self.rules.retain(|r| r.plugin_name() != plugin || r.name() != rule);
}
LintFilterKind::Generic(name) => self.rules.retain(|rule| rule.name() != name),
LintFilterKind::All => self.rules.clear(),
},
Expand Down
19 changes: 8 additions & 11 deletions crates/oxc_linter/src/options/filter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{borrow::Cow, fmt};

use crate::{LintPlugins, RuleCategory};
use crate::RuleCategory;

use super::AllowWarnDeny;

Expand Down Expand Up @@ -82,7 +82,7 @@ pub enum LintFilterKind {
/// e.g. `no-const-assign`
Generic(Cow<'static, str>),
/// e.g. `eslint/no-const-assign`
Rule(LintPlugins, Cow<'static, str>),
Rule(Cow<'static, str>, Cow<'static, str>),
/// e.g. `correctness`
Category(RuleCategory),
// TODO: plugin + category? e.g `-A react:correctness`
Expand Down Expand Up @@ -119,7 +119,7 @@ impl LintFilterKind {
return Err(InvalidFilterKind::RuleMissing(Cow::Borrowed(filter)));
}

(LintPlugins::from(plugin), Cow::Borrowed(rule))
(Cow::Borrowed(plugin), Cow::Borrowed(rule))
}
Cow::Owned(filter) => {
let mut parts = filter.splitn(2, '/');
Expand All @@ -138,7 +138,7 @@ impl LintFilterKind {
return Err(InvalidFilterKind::RuleMissing(filter.into()));
}

(LintPlugins::from(plugin), Cow::Owned(rule.to_string()))
(Cow::Owned(plugin.to_string()), Cow::Owned(rule.to_string()))
}
};
Ok(LintFilterKind::Rule(plugin, rule))
Expand Down Expand Up @@ -239,19 +239,16 @@ mod test {

let filter = LintFilter::deny(LintFilterKind::try_from("eslint/no-const-assign").unwrap());
assert_eq!(filter.severity(), AllowWarnDeny::Deny);
assert_eq!(
filter.kind(),
&LintFilterKind::Rule(LintPlugins::from("eslint"), "no-const-assign".into())
);
assert_eq!(filter.kind(), &LintFilterKind::Rule("eslint".into(), "no-const-assign".into()));
}

#[test]
fn test_parse() {
#[rustfmt::skip]
let test_cases: Vec<(&'static str, LintFilterKind)> = vec![
("eslint/no-const-assign", LintFilterKind::Rule(LintPlugins::ESLINT, "no-const-assign".into())),
("import/namespace", LintFilterKind::Rule(LintPlugins::IMPORT, "namespace".into())),
("react-hooks/exhaustive-deps", LintFilterKind::Rule(LintPlugins::REACT, "exhaustive-deps".into())),
("eslint/no-const-assign", LintFilterKind::Rule("eslint".into(), "no-const-assign".into())),
("import/namespace", LintFilterKind::Rule("import".into(), "namespace".into())),
("react-hooks/exhaustive-deps", LintFilterKind::Rule("react-hooks".into(), "exhaustive-deps".into())),
// categories
("correctness", LintFilterKind::Category(RuleCategory::Correctness)),
("nursery", LintFilterKind::Category(RuleCategory::Nursery)),
Expand Down
Loading