refactor(linter): temporarily remove unknown rules checking (#7260)

I had intended to leave this in until we could rework some of the rule/plugin name resolution code, however this is causing issues with merging https://github.com/oxc-project/oxc/pull/6974. The mutability of `self` is difficult to resolve in that PR without more drastic changes. Since this isn't currently helping us out, I am simply removing the code for now until we can revisit this.
This commit is contained in:
camchenry 2024-11-13 03:41:03 +00:00
parent df5c535dd0
commit c6a48684c3
3 changed files with 6 additions and 54 deletions

View file

@ -82,7 +82,7 @@ impl LinterBuilder {
/// match any recognized rules.
pub fn from_oxlintrc(start_empty: bool, oxlintrc: Oxlintrc) -> Self {
// TODO: monorepo config merging, plugin-based extends, etc.
let Oxlintrc { plugins, settings, env, globals, categories, rules: mut oxlintrc_rules } =
let Oxlintrc { plugins, settings, env, globals, categories, rules: oxlintrc_rules } =
oxlintrc;
let config = LintConfig { plugins, settings, env, globals };

View file

@ -101,7 +101,7 @@ mod test {
fn test_vitest_rule_replace() {
let fixture_path: std::path::PathBuf =
env::current_dir().unwrap().join("fixtures/eslint_config_vitest_replace.json");
let mut config = Oxlintrc::from_file(&fixture_path).unwrap();
let config = Oxlintrc::from_file(&fixture_path).unwrap();
let mut set = FxHashSet::default();
config.rules.override_rules(&mut set, &RULES);

View file

@ -27,13 +27,11 @@ type RuleSet = FxHashSet<RuleWithSeverity>;
pub struct OxlintRules {
/// List of all configured rules
pub(crate) rules: Vec<ESLintRule>,
/// List of rules that didn't match any known rules
pub unknown_rules: Vec<ESLintRule>,
}
impl OxlintRules {
pub fn new(rules: Vec<ESLintRule>) -> Self {
Self { rules, unknown_rules: Vec::new() }
Self { rules }
}
/// Returns `true` if there are no rules.
@ -60,11 +58,7 @@ pub struct ESLintRule {
impl OxlintRules {
#[allow(clippy::option_if_let_else, clippy::print_stderr)]
pub(crate) fn override_rules(
&mut self,
rules_for_override: &mut RuleSet,
all_rules: &[RuleEnum],
) {
pub(crate) fn override_rules(&self, rules_for_override: &mut RuleSet, all_rules: &[RuleEnum]) {
use itertools::Itertools;
let mut rules_to_replace: Vec<RuleWithSeverity> = vec![];
let mut rules_to_remove: Vec<RuleWithSeverity> = vec![];
@ -91,13 +85,6 @@ impl OxlintRules {
let config = rule_config.config.clone().unwrap_or_default();
let rule = rule.read_json(config);
rules_to_replace.push(RuleWithSeverity::new(rule, severity));
} else {
self.unknown_rules.push(ESLintRule {
plugin_name: plugin_name.to_string(),
rule_name: rule_name.to_string(),
severity,
config: rule_config.config.clone(),
});
}
}
AllowWarnDeny::Allow => {
@ -117,13 +104,6 @@ impl OxlintRules {
let config = rule_config.config.clone().unwrap_or_default();
let rule = rule.read_json(config);
rules_to_remove.push(RuleWithSeverity::new(rule, severity));
} else {
self.unknown_rules.push(ESLintRule {
plugin_name: plugin_name.to_string(),
rule_name: rule_name.to_string(),
severity,
config: rule_config.config.clone(),
});
}
}
}
@ -262,7 +242,7 @@ impl<'de> Deserialize<'de> for OxlintRules {
rules.push(ESLintRule { plugin_name, rule_name, severity, config });
}
Ok(OxlintRules { rules, unknown_rules: Vec::new() })
Ok(OxlintRules { rules })
}
}
@ -402,34 +382,6 @@ mod test {
assert!(r4.config.is_none());
}
#[test]
fn test_parse_unknown_rules() {
let config = json!({
"no-console": "off",
"foo/no-unused-vars": [1],
"dummy": ["error", "arg1", "args2"],
});
let mut rules = OxlintRules::deserialize(&config).unwrap();
let mut rule_set = RuleSet::default();
rules.override_rules(&mut rule_set, &RULES);
rules.unknown_rules.sort_by(|a, b| a.rule_name.cmp(&b.rule_name));
let mut rules = rules.unknown_rules.iter();
let r = rules.next().unwrap();
assert_eq!(r.rule_name, "dummy");
assert_eq!(r.plugin_name, "unknown_plugin");
assert!(r.severity.is_warn_deny());
assert_eq!(r.config, Some(serde_json::json!(["arg1", "args2"])));
let r = rules.next().unwrap();
assert_eq!(r.rule_name, "no-unused-vars");
assert_eq!(r.plugin_name, "foo");
assert!(r.severity.is_warn_deny());
assert!(r.config.is_none());
}
#[test]
fn test_parse_rules_default() {
let rules = OxlintRules::default();
@ -437,7 +389,7 @@ mod test {
}
fn r#override(rules: &mut RuleSet, rules_rc: &Value) {
let mut rules_config = OxlintRules::deserialize(rules_rc).unwrap();
let rules_config = OxlintRules::deserialize(rules_rc).unwrap();
rules_config.override_rules(rules, &RULES);
}