diff --git a/crates/biome_analyze/src/rule.rs b/crates/biome_analyze/src/rule.rs index 4cbaeb44bddc..cfccb4a0d6d9 100644 --- a/crates/biome_analyze/src/rule.rs +++ b/crates/biome_analyze/src/rule.rs @@ -114,6 +114,8 @@ pub enum RuleSource { EslintTypeScript(&'static str), /// Rules from [Eslint Plugin Unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) EslintUnicorn(&'static str), + /// Rules from [Eslint Plugin Unused Imports](https://github.com/sweepline/eslint-plugin-unused-imports) + EslintUnusedImports(&'static str), /// Rules from [Eslint Plugin Mysticatea](https://github.com/mysticatea/eslint-plugin) EslintMysticatea(&'static str), /// Rules from [Eslint Plugin Barrel Files](https://github.com/thepassle/eslint-plugin-barrel-files) @@ -131,22 +133,23 @@ impl PartialEq for RuleSource { impl std::fmt::Display for RuleSource { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - RuleSource::Clippy(_) => write!(f, "Clippy"), - RuleSource::Eslint(_) => write!(f, "ESLint"), - RuleSource::EslintImport(_) => write!(f, "eslint-plugin-import"), - RuleSource::EslintImportAccess(_) => write!(f, "eslint-plugin-import-access"), - RuleSource::EslintJest(_) => write!(f, "eslint-plugin-jest"), - RuleSource::EslintJsxA11y(_) => write!(f, "eslint-plugin-jsx-a11y"), - RuleSource::EslintReact(_) => write!(f, "eslint-plugin-react"), - RuleSource::EslintReactHooks(_) => write!(f, "eslint-plugin-react-hooks"), - RuleSource::EslintSolid(_) => write!(f, "eslint-plugin-solid"), - RuleSource::EslintSonarJs(_) => write!(f, "eslint-plugin-sonarjs"), - RuleSource::EslintStylistic(_) => write!(f, "eslint-plugin-stylistic"), - RuleSource::EslintTypeScript(_) => write!(f, "typescript-eslint"), - RuleSource::EslintUnicorn(_) => write!(f, "eslint-plugin-unicorn"), - RuleSource::EslintMysticatea(_) => write!(f, "@mysticatea/eslint-plugin"), - RuleSource::EslintBarrelFiles(_) => write!(f, "eslint-plugin-barrel-files"), - RuleSource::Stylelint(_) => write!(f, "Stylelint"), + Self::Clippy(_) => write!(f, "Clippy"), + Self::Eslint(_) => write!(f, "ESLint"), + Self::EslintImport(_) => write!(f, "eslint-plugin-import"), + Self::EslintImportAccess(_) => write!(f, "eslint-plugin-import-access"), + Self::EslintJest(_) => write!(f, "eslint-plugin-jest"), + Self::EslintJsxA11y(_) => write!(f, "eslint-plugin-jsx-a11y"), + Self::EslintReact(_) => write!(f, "eslint-plugin-react"), + Self::EslintReactHooks(_) => write!(f, "eslint-plugin-react-hooks"), + Self::EslintSolid(_) => write!(f, "eslint-plugin-solid"), + Self::EslintSonarJs(_) => write!(f, "eslint-plugin-sonarjs"), + Self::EslintStylistic(_) => write!(f, "eslint-plugin-stylistic"), + Self::EslintTypeScript(_) => write!(f, "typescript-eslint"), + Self::EslintUnicorn(_) => write!(f, "eslint-plugin-unicorn"), + Self::EslintUnusedImports(_) => write!(f, "eslint-plugin-unused-imports"), + Self::EslintMysticatea(_) => write!(f, "@mysticatea/eslint-plugin"), + Self::EslintBarrelFiles(_) => write!(f, "eslint-plugin-barrel-files"), + Self::Stylelint(_) => write!(f, "Stylelint"), } } } @@ -189,6 +192,7 @@ impl RuleSource { | Self::EslintSonarJs(rule_name) | Self::EslintStylistic(rule_name) | Self::EslintUnicorn(rule_name) + | Self::EslintUnusedImports(rule_name) | Self::EslintMysticatea(rule_name) | Self::EslintBarrelFiles(rule_name) | Self::Stylelint(rule_name) => rule_name, @@ -209,6 +213,7 @@ impl RuleSource { Self::EslintSonarJs(rule_name) => format!("sonarjs/{rule_name}"), Self::EslintStylistic(rule_name) => format!("@stylistic/{rule_name}"), Self::EslintUnicorn(rule_name) => format!("unicorn/{rule_name}"), + Self::EslintUnusedImports(rule_name) => format!("unused-imports/{rule_name}"), Self::EslintMysticatea(rule_name) => format!("@mysticatea/{rule_name}"), Self::EslintBarrelFiles(rule_name) => format!("barrel-files/{rule_name}"), Self::Stylelint(rule_name) => format!("stylelint/{rule_name}"), @@ -230,6 +235,7 @@ impl RuleSource { Self::EslintSonarJs(rule_name) => format!("https://github.com/SonarSource/eslint-plugin-sonarjs/blob/HEAD/docs/rules/{rule_name}.md"), Self::EslintStylistic(rule_name) => format!("https://eslint.style/rules/default/{rule_name}"), Self::EslintUnicorn(rule_name) => format!("https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/{rule_name}.md"), + Self::EslintUnusedImports(rule_name) => format!("https://github.com/sweepline/eslint-plugin-unused-imports/blob/master/docs/rules/{rule_name}.md"), Self::EslintMysticatea(rule_name) => format!("https://github.com/mysticatea/eslint-plugin/blob/master/docs/rules/{rule_name}.md"), Self::EslintBarrelFiles(rule_name) => format!("https://github.com/thepassle/eslint-plugin-barrel-files/blob/main/docs/rules/{rule_name}.md"), Self::Stylelint(rule_name) => format!("https://github.com/stylelint/stylelint/blob/main/lib/rules/{rule_name}/README.md"), @@ -247,7 +253,7 @@ impl RuleSource { /// All ESLint plugins, exception for the TypeScript one pub const fn is_eslint_plugin(&self) -> bool { - !matches!(self, Self::Clippy(_) | Self::Eslint(_)) + !matches!(self, Self::Clippy(_) | Self::Eslint(_) | Self::Stylelint(_)) } pub const fn is_stylelint(&self) -> bool { diff --git a/crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs b/crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs index 40514d998a20..4b0dbcbdb837 100644 --- a/crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs +++ b/crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs @@ -1331,6 +1331,11 @@ pub(crate) fn migrate_eslint_any_rule( .get_or_insert(Default::default()); rule.set_level(rule_severity.into()); } + "sonarjs/prefer-while" => { + let group = rules.style.get_or_insert_with(Default::default); + let rule = group.use_while.get_or_insert(Default::default()); + rule.set_level(rule_severity.into()); + } "unicorn/error-message" => { if !options.include_nursery { return false; @@ -1449,6 +1454,16 @@ pub(crate) fn migrate_eslint_any_rule( let rule = group.use_throw_new_error.get_or_insert(Default::default()); rule.set_level(rule_severity.into()); } + "unused-imports/no-unused-imports" => { + let group = rules.correctness.get_or_insert_with(Default::default); + let rule = group.no_unused_imports.get_or_insert(Default::default()); + rule.set_level(rule_severity.into()); + } + "unused-imports/no-unused-vars" => { + let group = rules.correctness.get_or_insert_with(Default::default); + let rule = group.no_unused_variables.get_or_insert(Default::default()); + rule.set_level(rule_severity.into()); + } "use-isnan" => { let group = rules.correctness.get_or_insert_with(Default::default); let rule = group.use_is_nan.get_or_insert(Default::default()); diff --git a/crates/biome_js_analyze/src/lint/correctness/no_unused_imports.rs b/crates/biome_js_analyze/src/lint/correctness/no_unused_imports.rs index 87894c8866a3..63f05f83cdc9 100644 --- a/crates/biome_js_analyze/src/lint/correctness/no_unused_imports.rs +++ b/crates/biome_js_analyze/src/lint/correctness/no_unused_imports.rs @@ -5,7 +5,7 @@ use crate::{ }; use biome_analyze::{ context::RuleContext, declare_rule, options::JsxRuntime, ActionCategory, FixKind, Rule, - RuleDiagnostic, + RuleDiagnostic, RuleSource, }; use biome_console::markup; use biome_js_factory::make; @@ -79,6 +79,7 @@ declare_rule! { version: "1.3.0", name: "noUnusedImports", language: "js", + sources: &[RuleSource::EslintUnusedImports("no-unused-imports")], recommended: false, fix_kind: FixKind::Safe, } diff --git a/crates/biome_js_analyze/src/lint/correctness/no_unused_variables.rs b/crates/biome_js_analyze/src/lint/correctness/no_unused_variables.rs index f9c607318593..530a592efcd0 100644 --- a/crates/biome_js_analyze/src/lint/correctness/no_unused_variables.rs +++ b/crates/biome_js_analyze/src/lint/correctness/no_unused_variables.rs @@ -97,6 +97,7 @@ declare_rule! { sources: &[ RuleSource::Eslint("no-unused-vars"), RuleSource::EslintTypeScript("no-unused-vars"), + RuleSource::EslintUnusedImports("no-unused-vars") ], recommended: false, fix_kind: FixKind::Unsafe, diff --git a/crates/biome_js_analyze/src/lint/style/use_while.rs b/crates/biome_js_analyze/src/lint/style/use_while.rs index f56ca26e5148..85fa1b9b8a38 100644 --- a/crates/biome_js_analyze/src/lint/style/use_while.rs +++ b/crates/biome_js_analyze/src/lint/style/use_while.rs @@ -1,5 +1,6 @@ use biome_analyze::{ context::RuleContext, declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic, + RuleSource, }; use biome_console::markup; use biome_js_factory::make; @@ -42,6 +43,7 @@ declare_rule! { name: "useWhile", language: "js", recommended: true, + sources: &[RuleSource::EslintSonarJs("prefer-while")], fix_kind: FixKind::Safe, } }