feat(linter): --deny all should not enable nursery rules

closes #3067
This commit is contained in:
Boshen 2024-04-22 12:32:47 +08:00
parent c2ad8f82de
commit 8d17bb4052
No known key found for this signature in database
GPG key ID: 234DA6A7079C6801
2 changed files with 34 additions and 21 deletions

View file

@ -308,7 +308,13 @@ mod test {
#[test]
fn eslintrc_no_undef() {
let args = &["-c", "fixtures/no_undef/eslintrc.json", "fixtures/no_undef/test.js"];
let args = &[
"-D",
"no-undef",
"-c",
"fixtures/no_undef/eslintrc.json",
"fixtures/no_undef/test.js",
];
let result = test(args);
assert_eq!(result.number_of_files, 1);
assert_eq!(result.number_of_warnings, 1);
@ -317,8 +323,13 @@ mod test {
#[test]
fn eslintrc_no_env() {
let args =
&["-c", "fixtures/eslintrc_env/eslintrc_no_env.json", "fixtures/eslintrc_env/test.js"];
let args = &[
"-D",
"no-undef",
"-c",
"fixtures/eslintrc_env/eslintrc_no_env.json",
"fixtures/eslintrc_env/test.js",
];
let result = test(args);
assert_eq!(result.number_of_files, 1);
assert_eq!(result.number_of_warnings, 1);

View file

@ -192,7 +192,7 @@ impl LintOptions {
rules.extend(all_rules.iter().cloned());
} else {
rules.extend(
all_rules
RULES
.iter()
.filter(|rule| rule.name() == name_or_category)
.cloned(),
@ -228,23 +228,25 @@ impl LintOptions {
Ok((rules, config.unwrap_or_default()))
}
// get final filtered rules by reading `self.xxx_plugin`
/// Get final filtered rules by reading `self.xxx_plugin`
fn get_filtered_rules(&self) -> Vec<RuleEnum> {
let mut rules = RULES.clone();
let mut may_exclude_plugin_rules = |yes: bool, name: &str| {
if !yes {
rules.retain(|rule| rule.plugin_name() != name);
}
};
may_exclude_plugin_rules(self.import_plugin, IMPORT_PLUGIN_NAME);
may_exclude_plugin_rules(self.jsdoc_plugin, JSDOC_PLUGIN_NAME);
may_exclude_plugin_rules(self.jest_plugin, JEST_PLUGIN_NAME);
may_exclude_plugin_rules(self.jsx_a11y_plugin, JSX_A11Y_PLUGIN_NAME);
may_exclude_plugin_rules(self.nextjs_plugin, NEXTJS_PLUGIN_NAME);
may_exclude_plugin_rules(self.react_perf_plugin, REACT_PERF_PLUGIN_NAME);
rules
RULES
.iter()
.filter(|rule| {
if rule.category() == RuleCategory::Nursery {
return false;
}
match rule.plugin_name() {
IMPORT_PLUGIN_NAME if !self.import_plugin => false,
JSDOC_PLUGIN_NAME if !self.jsdoc_plugin => false,
JEST_PLUGIN_NAME if !self.jest_plugin => false,
JSX_A11Y_PLUGIN_NAME if !self.jsx_a11y_plugin => false,
NEXTJS_PLUGIN_NAME if !self.nextjs_plugin => false,
REACT_PERF_PLUGIN_NAME if !self.react_perf_plugin => false,
_ => true,
}
})
.cloned()
.collect::<Vec<_>>()
}
}