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

feat(linter): implement solidjs usePerferFor #4295

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
37 changes: 28 additions & 9 deletions crates/biome_configuration/src/analyzer/linter/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3417,6 +3417,9 @@ pub struct Nursery {
#[serde(skip_serializing_if = "Option::is_none")]
pub use_import_restrictions:
Option<RuleConfiguration<biome_js_analyze::options::UseImportRestrictions>>,
#[doc = "Succinct description of the rule."]
#[serde(skip_serializing_if = "Option::is_none")]
pub use_perfer_for: Option<RuleConfiguration<biome_js_analyze::options::UsePerferFor>>,
#[doc = "Enforce the sorting of CSS utility classes."]
#[serde(skip_serializing_if = "Option::is_none")]
pub use_sorted_classes:
Expand Down Expand Up @@ -3490,6 +3493,7 @@ impl Nursery {
"useExplicitType",
"useGuardForIn",
"useImportRestrictions",
"usePerferFor",
"useSortedClasses",
"useStrictMode",
"useTrimStartEnd",
Expand Down Expand Up @@ -3525,7 +3529,7 @@ impl Nursery {
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[31]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[35]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[36]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[41]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[42]),
];
const ALL_RULES_AS_FILTERS: &'static [RuleFilter<'static>] = &[
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[0]),
Expand Down Expand Up @@ -3572,6 +3576,7 @@ impl Nursery {
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[41]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[42]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[43]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[44]),
];
#[doc = r" Retrieves the recommended rules"]
pub(crate) fn is_recommended_true(&self) -> bool {
Expand Down Expand Up @@ -3788,26 +3793,31 @@ impl Nursery {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[39]));
}
}
if let Some(rule) = self.use_sorted_classes.as_ref() {
if let Some(rule) = self.use_perfer_for.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[40]));
}
}
if let Some(rule) = self.use_strict_mode.as_ref() {
if let Some(rule) = self.use_sorted_classes.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[41]));
}
}
if let Some(rule) = self.use_trim_start_end.as_ref() {
if let Some(rule) = self.use_strict_mode.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[42]));
}
}
if let Some(rule) = self.use_valid_autocomplete.as_ref() {
if let Some(rule) = self.use_trim_start_end.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[43]));
}
}
if let Some(rule) = self.use_valid_autocomplete.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[44]));
}
}
index_set
}
pub(crate) fn get_disabled_rules(&self) -> FxHashSet<RuleFilter<'static>> {
Expand Down Expand Up @@ -4012,26 +4022,31 @@ impl Nursery {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[39]));
}
}
if let Some(rule) = self.use_sorted_classes.as_ref() {
if let Some(rule) = self.use_perfer_for.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[40]));
}
}
if let Some(rule) = self.use_strict_mode.as_ref() {
if let Some(rule) = self.use_sorted_classes.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[41]));
}
}
if let Some(rule) = self.use_trim_start_end.as_ref() {
if let Some(rule) = self.use_strict_mode.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[42]));
}
}
if let Some(rule) = self.use_valid_autocomplete.as_ref() {
if let Some(rule) = self.use_trim_start_end.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[43]));
}
}
if let Some(rule) = self.use_valid_autocomplete.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[44]));
}
}
index_set
}
#[doc = r" Checks if, given a rule name, matches one of the rules contained in this category"]
Expand Down Expand Up @@ -4228,6 +4243,10 @@ impl Nursery {
.use_import_restrictions
.as_ref()
.map(|conf| (conf.level(), conf.get_options())),
"usePerferFor" => self
.use_perfer_for
.as_ref()
.map(|conf| (conf.level(), conf.get_options())),
"useSortedClasses" => self
.use_sorted_classes
.as_ref()
Expand Down
1 change: 1 addition & 0 deletions crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ define_categories! {
"lint/nursery/useGuardForIn": "https://biomejs.dev/linter/rules/use-guard-for-in",
"lint/nursery/useImportRestrictions": "https://biomejs.dev/linter/rules/use-import-restrictions",
"lint/nursery/useJsxCurlyBraceConvention": "https://biomejs.dev/linter/rules/use-jsx-curly-brace-convention",
"lint/nursery/usePerferFor": "https://biomejs.dev/linter/rules/use-perfer-for",
"lint/nursery/useSortedClasses": "https://biomejs.dev/linter/rules/use-sorted-classes",
"lint/nursery/useStrictMode": "https://biomejs.dev/linter/rules/use-strict-mode",
"lint/nursery/useTrimStartEnd": "https://biomejs.dev/linter/rules/use-trim-start-end",
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_js_analyze/src/lint/nursery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub mod use_consistent_member_accessibility;
pub mod use_explicit_type;
pub mod use_guard_for_in;
pub mod use_import_restrictions;
pub mod use_perfer_for;
pub mod use_sorted_classes;
pub mod use_strict_mode;
pub mod use_trim_start_end;
Expand Down Expand Up @@ -71,6 +72,7 @@ declare_lint_group! {
self :: use_explicit_type :: UseExplicitType ,
self :: use_guard_for_in :: UseGuardForIn ,
self :: use_import_restrictions :: UseImportRestrictions ,
self :: use_perfer_for :: UsePerferFor ,
self :: use_sorted_classes :: UseSortedClasses ,
self :: use_strict_mode :: UseStrictMode ,
self :: use_trim_start_end :: UseTrimStartEnd ,
Expand Down
67 changes: 67 additions & 0 deletions crates/biome_js_analyze/src/lint/nursery/use_perfer_for.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use biome_analyze::{context::RuleContext, declare_lint_rule, Ast, Rule, RuleDiagnostic};
use biome_console::markup;
use biome_js_syntax::JsIdentifierBinding;
use biome_rowan::AstNode;

declare_lint_rule! {
/// Succinct description of the rule.
///
/// Put context and details about the rule.
/// As a starting point, you can take the description of the corresponding _ESLint_ rule (if any).
///
/// Try to stay consistent with the descriptions of implemented rules.
///
/// ## Examples
///
/// ### Invalid
///
/// ```js,expect_diagnostic
/// var a = 1;
/// a = 2;
/// ```
///
/// ### Valid
///
/// ```js
/// // var a = 1;
/// ```
///
pub UsePerferFor {
version: "next",
name: "usePerferFor",
language: "js",
recommended: false,
}
}

impl Rule for UsePerferFor {
type Query = Ast<JsIdentifierBinding>;
type State = ();
type Signals = Option<Self::State>;
type Options = ();

fn run(ctx: &RuleContext<Self>) -> Self::Signals {
let _binding = ctx.query();
Some(())
}

fn diagnostic(ctx: &RuleContext<Self>, _state: &Self::State) -> Option<RuleDiagnostic> {
//
// Read our guidelines to write great diagnostics:
// https://docs.rs/biome_analyze/latest/biome_analyze/#what-a-rule-should-say-to-the-user
//
let node = ctx.query();
Some(
RuleDiagnostic::new(
rule_category!(),
node.range(),
markup! {
"Variable is read here."
},
)
.note(markup! {
"This note will give you more information."
}),
)
}
}
2 changes: 2 additions & 0 deletions crates/biome_js_analyze/src/options.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
@@ -0,0 +1,9 @@
// See https://github.com/biomejs/biome/issues/3895
declare module "eslint-plugin-jsx-a11y" {
import type { Linter } from "eslint";

export const flatConfigs: {
readonly recommended: { readonly rules: Readonly<Linter.RulesRecord> };
readonly strict: { readonly rules: Readonly<Linter.RulesRecord> };
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: issue3895.ts
---
# Input
```ts
// See https://github.com/biomejs/biome/issues/3895
declare module "eslint-plugin-jsx-a11y" {
import type { Linter } from "eslint";

export const flatConfigs: {
readonly recommended: { readonly rules: Readonly<Linter.RulesRecord> };
readonly strict: { readonly rules: Readonly<Linter.RulesRecord> };
};
}
```

# Diagnostics
```
issue3895.ts:3:19 lint/correctness/noUnusedImports FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! This import is unused.

1 │ // See https://github.com/biomejs/biome/issues/3895
2 │ declare module "eslint-plugin-jsx-a11y" {
> 3 │ import type { Linter } from "eslint";
│ ^^^^^^
4 │
5 │ export const flatConfigs: {

i Unused imports might be the result of an incomplete refactoring.

i Safe fix: Remove the unused import.

1 1 │ // See https://github.com/biomejs/biome/issues/3895
2 2 │ declare module "eslint-plugin-jsx-a11y" {
3 │ - ····import·type·{·Linter·}·from·"eslint";
4 3 │
5 4 │ export const flatConfigs: {


```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var a = 1;
a = 2;
a = 3;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* should not generate diagnostics */
// var a = 1;
5 changes: 5 additions & 0 deletions packages/@biomejs/backend-jsonrpc/src/workspace.ts

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

7 changes: 7 additions & 0 deletions packages/@biomejs/biome/configuration_schema.json

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

Loading