Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(lint): add SonarJs and UnusedImports rule sources #3128

Merged
merged 1 commit into from
Jun 8, 2024
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
40 changes: 23 additions & 17 deletions crates/biome_analyze/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"),
}
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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}"),
Expand All @@ -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"),
Expand All @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_js_analyze/src/lint/style/use_while.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -42,6 +43,7 @@ declare_rule! {
name: "useWhile",
language: "js",
recommended: true,
sources: &[RuleSource::EslintSonarJs("prefer-while")],
fix_kind: FixKind::Safe,
}
}
Expand Down