From 6d1b2bb012c05d29a64c1b9bce0479579b62e861 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Sat, 23 Nov 2024 16:46:55 +0000 Subject: [PATCH 1/8] feat(linter): rule --- .../src/categories.rs | 1 + crates/biome_js_analyze/src/lint/nursery.rs | 2 + .../src/lint/nursery/no_ts_ignore.rs | 135 +++++++++++++++ crates/biome_js_analyze/src/options.rs | 1 + .../tests/specs/nursery/noTsIgnore/invalid.ts | 20 +++ .../specs/nursery/noTsIgnore/invalid.ts.snap | 163 ++++++++++++++++++ .../@biomejs/backend-jsonrpc/src/workspace.ts | 5 + .../@biomejs/biome/configuration_schema.json | 7 + 8 files changed, 334 insertions(+) create mode 100644 crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs create mode 100644 crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts create mode 100644 crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts.snap diff --git a/crates/biome_diagnostics_categories/src/categories.rs b/crates/biome_diagnostics_categories/src/categories.rs index b0cce49bded5..9cfc3d64fa44 100644 --- a/crates/biome_diagnostics_categories/src/categories.rs +++ b/crates/biome_diagnostics_categories/src/categories.rs @@ -171,6 +171,7 @@ define_categories! { "lint/nursery/noStaticElementInteractions": "https://biomejs.dev/linter/rules/no-static-element-interactions", "lint/nursery/noSubstr": "https://biomejs.dev/linter/rules/no-substr", "lint/nursery/noTemplateCurlyInString": "https://biomejs.dev/linter/rules/no-template-curly-in-string", + "lint/nursery/noTsIgnore": "https://biomejs.dev/linter/rules/no-ts-ignore", "lint/nursery/noUndeclaredDependencies": "https://biomejs.dev/linter/rules/no-undeclared-dependencies", "lint/nursery/noUnknownFunction": "https://biomejs.dev/linter/rules/no-unknown-function", "lint/nursery/noUnknownMediaFeatureName": "https://biomejs.dev/linter/rules/no-unknown-media-feature-name", diff --git a/crates/biome_js_analyze/src/lint/nursery.rs b/crates/biome_js_analyze/src/lint/nursery.rs index 168a7462f36c..6da7a927f26e 100644 --- a/crates/biome_js_analyze/src/lint/nursery.rs +++ b/crates/biome_js_analyze/src/lint/nursery.rs @@ -24,6 +24,7 @@ pub mod no_secrets; pub mod no_static_element_interactions; pub mod no_substr; pub mod no_template_curly_in_string; +pub mod no_ts_ignore; pub mod no_useless_escape_in_regex; pub mod no_useless_string_raw; pub mod no_useless_undefined; @@ -69,6 +70,7 @@ declare_lint_group! { self :: no_static_element_interactions :: NoStaticElementInteractions , self :: no_substr :: NoSubstr , self :: no_template_curly_in_string :: NoTemplateCurlyInString , + self :: no_ts_ignore :: NoTsIgnore , self :: no_useless_escape_in_regex :: NoUselessEscapeInRegex , self :: no_useless_string_raw :: NoUselessStringRaw , self :: no_useless_undefined :: NoUselessUndefined , diff --git a/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs b/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs new file mode 100644 index 000000000000..d22f1dd8a0a5 --- /dev/null +++ b/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs @@ -0,0 +1,135 @@ +use crate::JsRuleAction; +use biome_analyze::{ + context::RuleContext, declare_lint_rule, Ast, FixKind, Rule, RuleDiagnostic, RuleSource, + RuleSourceKind, +}; +use biome_console::markup; +use biome_js_syntax::{JsModule, JsSyntaxToken, TextLen}; +use biome_rowan::{AstNode, BatchMutationExt, Direction, TextRange, TextSize, TriviaPiece}; + +declare_lint_rule! { + /// Prevents the use of the TypeScript directive `@ts-ignore`. + /// + /// The directive `@ts-ignore` shuts down all compilation errors, even ones that could be considered bugs + /// coming from an upstream library or the compiler itself. If you use `@ts-ignore`, it won't be possible to know + /// when and if the bug is fixed. + /// + /// The rule promotes the use the directive `@ts-expect-error`, which is meant to raise an error if there aren't any errors. + /// This means that once the bug is fixed, you can delete the directive, safely. + /// + /// ## Examples + /// + /// ### Invalid + /// + /// ```ts,expect_diagnostic + /// // @ts-ignore + /// let foo; + /// ``` + /// + pub NoTsIgnore { + version: "next", + name: "noTsIgnore", + language: "js", + sources: &[RuleSource::Eslint("ban-ts-comment")], + recommended: true, + source_kind: RuleSourceKind::Inspired, + fix_kind: FixKind::Safe, + } +} + +/// We track the token that has the trivia, and the range when the incorrect comment is the document +type RuleState = (JsSyntaxToken, TextRange); + +impl Rule for NoTsIgnore { + type Query = Ast; + type State = RuleState; + type Signals = Vec; + type Options = (); + + fn run(ctx: &RuleContext) -> Self::Signals { + let module = ctx.query(); + + let mut tokens = vec![]; + for token in module.syntax().descendants_tokens(Direction::Next) { + let leading_trivia = token.leading_trivia(); + let comments: Vec<_> = leading_trivia + .pieces() + .filter_map(|trivia| { + if let Some(comment) = trivia.as_comments() { + for (index, _) in comment.text().match_indices("@ts-ignore") { + return Some(( + token.clone(), + comment.text_range().add_start(TextSize::from(index as u32)), + )); + } + } + None + }) + .collect(); + + tokens.extend(comments); + } + + tokens + } + + fn diagnostic(_ctx: &RuleContext, state: &Self::State) -> Option { + let (token, range) = state; + + Some( + RuleDiagnostic::new( + rule_category!(), + range, + markup! { + "Unsafe use of the ""@ts-ignore"" directive found in this comment." + }, + ) + .detail( + token.text_trimmed_range(), + markup! { + "The directive is applied to this line." + }, + ) + .note(markup! { + "The directive ""@ts-ignore"" shuts down any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself." + }), + ) + } + + fn action(ctx: &RuleContext, state: &Self::State) -> Option { + let (token, _) = state; + let token = token.clone(); + let mut mutation = ctx.root().begin(); + let mut new_trivia = vec![]; + let mut text = String::from(""); + for trivia in token.clone().leading_trivia().pieces() { + let kind = trivia.kind(); + if let Some(comment) = trivia.as_comments() { + if comment.text().contains("@ts-ignore") { + let new_comment = comment.text().replace("@ts-ignore", "@ts-expect-error"); + new_trivia.push(TriviaPiece::new(kind, new_comment.text_len())); + text.push_str(new_comment.as_str()); + } else { + new_trivia.push(TriviaPiece::new(kind, comment.text_len())); + text.push_str(comment.text()); + } + } else { + new_trivia.push(TriviaPiece::new(kind, trivia.text_len())); + text.push_str(trivia.text()); + } + } + text.push_str(token.text_trimmed()); + let new_token = JsSyntaxToken::new_detached(token.kind(), text.as_str(), new_trivia, []) + .with_trailing_trivia_pieces(token.trailing_trivia().pieces()); + + mutation.replace_token_discard_trivia(token, new_token); + + Some(JsRuleAction::new( + ctx.metadata().action_category(ctx.category(), ctx.group()), + ctx.metadata().applicability(), + markup! { "Use the directive ""@ts-expect-error"" instead." } + .to_owned(), + mutation, + )) + } +} diff --git a/crates/biome_js_analyze/src/options.rs b/crates/biome_js_analyze/src/options.rs index eda882c7bdd7..e5ebac46bf61 100644 --- a/crates/biome_js_analyze/src/options.rs +++ b/crates/biome_js_analyze/src/options.rs @@ -223,6 +223,7 @@ pub type NoThenProperty = ::Options; pub type NoThisInStatic = ::Options; +pub type NoTsIgnore = ::Options; pub type NoUndeclaredDependencies = < lint :: correctness :: no_undeclared_dependencies :: NoUndeclaredDependencies as biome_analyze :: Rule > :: Options ; pub type NoUndeclaredVariables = < lint :: correctness :: no_undeclared_variables :: NoUndeclaredVariables as biome_analyze :: Rule > :: Options ; pub type NoUnnecessaryContinue = < lint :: correctness :: no_unnecessary_continue :: NoUnnecessaryContinue as biome_analyze :: Rule > :: Options ; diff --git a/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts b/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts new file mode 100644 index 000000000000..8c79cb2646b4 --- /dev/null +++ b/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts @@ -0,0 +1,20 @@ + +// @ts-ignore +let found; + +/** + * @ts-ignore + * more comments + */ +let foo; + + +// Some comment +// @ts-ignore +// Some other comment +let bar; + + +// Some comment +// @ts-ignore Some other comment +let someTextAfter; diff --git a/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts.snap b/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts.snap new file mode 100644 index 000000000000..55537beb6ab7 --- /dev/null +++ b/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts.snap @@ -0,0 +1,163 @@ +--- +source: crates/biome_js_analyze/tests/spec_tests.rs +expression: invalid.ts +snapshot_kind: text +--- +# Input +```ts + +// @ts-ignore +let found; + +/** + * @ts-ignore + * more comments + */ +let foo; + + +// Some comment +// @ts-ignore +// Some other comment +let bar; + + +// Some comment +// @ts-ignore Some other comment +let someTextAfter; + +``` + +# Diagnostics +``` +invalid.ts:2:4 lint/nursery/noTsIgnore FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unsafe use of the @ts-ignore directive found in this comment. + + > 2 │ // @ts-ignore + │ ^^^^^^^^^^ + 3 │ let found; + 4 │ + + i The directive is applied to this line. + + 2 │ // @ts-ignore + > 3 │ let found; + │ ^^^ + 4 │ + 5 │ /** + + i The directive @ts-ignore shuts down any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. + + i Safe fix: Use the directive @ts-expect-error instead. + + 1 1 │ + 2 │ - //·@ts-ignore + 2 │ + //·@ts-expect-error + 3 3 │ let found; + 4 4 │ + + +``` + +``` +invalid.ts:6:4 lint/nursery/noTsIgnore FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unsafe use of the @ts-ignore directive found in this comment. + + 5 │ /** + > 6 │ * @ts-ignore + │ ^^^^^^^^^^ + > 7 │ * more comments + > 8 │ */ + │ ^^ + 9 │ let foo; + 10 │ + + i The directive is applied to this line. + + 7 │ * more comments + 8 │ */ + > 9 │ let foo; + │ ^^^ + 10 │ + + i The directive @ts-ignore shuts down any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. + + i Safe fix: Use the directive @ts-expect-error instead. + + 4 4 │ + 5 5 │ /** + 6 │ - ·*·@ts-ignore + 6 │ + ·*·@ts-expect-error + 7 7 │ * more comments + 8 8 │ */ + + +``` + +``` +invalid.ts:13:4 lint/nursery/noTsIgnore FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unsafe use of the @ts-ignore directive found in this comment. + + 12 │ // Some comment + > 13 │ // @ts-ignore + │ ^^^^^^^^^^ + 14 │ // Some other comment + 15 │ let bar; + + i The directive is applied to this line. + + 13 │ // @ts-ignore + 14 │ // Some other comment + > 15 │ let bar; + │ ^^^ + 16 │ + + i The directive @ts-ignore shuts down any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. + + i Safe fix: Use the directive @ts-expect-error instead. + + 11 11 │ + 12 12 │ // Some comment + 13 │ - //·@ts-ignore + 13 │ + //·@ts-expect-error + 14 14 │ // Some other comment + 15 15 │ let bar; + + +``` + +``` +invalid.ts:19:4 lint/nursery/noTsIgnore FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unsafe use of the @ts-ignore directive found in this comment. + + 18 │ // Some comment + > 19 │ // @ts-ignore Some other comment + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 20 │ let someTextAfter; + 21 │ + + i The directive is applied to this line. + + 18 │ // Some comment + 19 │ // @ts-ignore Some other comment + > 20 │ let someTextAfter; + │ ^^^ + 21 │ + + i The directive @ts-ignore shuts down any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. + + i Safe fix: Use the directive @ts-expect-error instead. + + 17 17 │ + 18 18 │ // Some comment + 19 │ - //·@ts-ignore·Some·other·comment + 19 │ + //·@ts-expect-error·Some·other·comment + 20 20 │ let someTextAfter; + 21 21 │ + + +``` diff --git a/packages/@biomejs/backend-jsonrpc/src/workspace.ts b/packages/@biomejs/backend-jsonrpc/src/workspace.ts index 89cf29c87c86..044851a6459f 100644 --- a/packages/@biomejs/backend-jsonrpc/src/workspace.ts +++ b/packages/@biomejs/backend-jsonrpc/src/workspace.ts @@ -1323,6 +1323,10 @@ export interface Nursery { * Disallow template literal placeholder syntax in regular strings. */ noTemplateCurlyInString?: RuleConfiguration_for_Null; + /** + * Succinct description of the rule. + */ + noTsIgnore?: RuleConfiguration_for_Null; /** * Disallow unknown pseudo-class selectors. */ @@ -3088,6 +3092,7 @@ export type Category = | "lint/nursery/noStaticElementInteractions" | "lint/nursery/noSubstr" | "lint/nursery/noTemplateCurlyInString" + | "lint/nursery/noTsIgnore" | "lint/nursery/noUndeclaredDependencies" | "lint/nursery/noUnknownFunction" | "lint/nursery/noUnknownMediaFeatureName" diff --git a/packages/@biomejs/biome/configuration_schema.json b/packages/@biomejs/biome/configuration_schema.json index 6cedca2c8c53..9718d144969a 100644 --- a/packages/@biomejs/biome/configuration_schema.json +++ b/packages/@biomejs/biome/configuration_schema.json @@ -2358,6 +2358,13 @@ { "type": "null" } ] }, + "noTsIgnore": { + "description": "Succinct description of the rule.", + "anyOf": [ + { "$ref": "#/definitions/RuleConfiguration" }, + { "type": "null" } + ] + }, "noUnknownPseudoClass": { "description": "Disallow unknown pseudo-class selectors.", "anyOf": [ From 2e12a27806abd14e24bef058e433458a841f8219 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 27 Nov 2024 16:06:28 +0000 Subject: [PATCH 2/8] Update crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs Co-authored-by: Arend van Beelen jr. --- crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs b/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs index d22f1dd8a0a5..3f7059ec5151 100644 --- a/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs +++ b/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs @@ -10,7 +10,7 @@ use biome_rowan::{AstNode, BatchMutationExt, Direction, TextRange, TextSize, Tri declare_lint_rule! { /// Prevents the use of the TypeScript directive `@ts-ignore`. /// - /// The directive `@ts-ignore` shuts down all compilation errors, even ones that could be considered bugs + /// The directive `@ts-ignore` suppresses all compilation errors, even ones that could be considered bugs /// coming from an upstream library or the compiler itself. If you use `@ts-ignore`, it won't be possible to know /// when and if the bug is fixed. /// From 5e2fcf4d39d4d6578027a936123364a1b6333558 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 27 Nov 2024 16:06:43 +0000 Subject: [PATCH 3/8] Apply suggestions from code review Co-authored-by: Arend van Beelen jr. --- crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs b/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs index 3f7059ec5151..518adfc5d0ef 100644 --- a/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs +++ b/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs @@ -91,7 +91,7 @@ impl Rule for NoTsIgnore { }, ) .note(markup! { - "The directive ""@ts-ignore"" shuts down any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself." + "The directive ""@ts-ignore"" suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself." }), ) } From 924b9097930da4a488256153046602d112603aaf Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 27 Nov 2024 16:12:31 +0000 Subject: [PATCH 4/8] apply suggestions --- crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs | 9 +++++++++ .../tests/specs/nursery/noTsIgnore/invalid.ts.snap | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs b/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs index 518adfc5d0ef..d1c95317ddaf 100644 --- a/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs +++ b/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs @@ -4,6 +4,7 @@ use biome_analyze::{ RuleSourceKind, }; use biome_console::markup; +use biome_diagnostics::Severity; use biome_js_syntax::{JsModule, JsSyntaxToken, TextLen}; use biome_rowan::{AstNode, BatchMutationExt, Direction, TextRange, TextSize, TriviaPiece}; @@ -26,6 +27,13 @@ declare_lint_rule! { /// let foo; /// ``` /// + /// ### Valid + /// + /// ```ts + /// // @ts-expect-error + /// let foo; + /// ``` + /// pub NoTsIgnore { version: "next", name: "noTsIgnore", @@ -34,6 +42,7 @@ declare_lint_rule! { recommended: true, source_kind: RuleSourceKind::Inspired, fix_kind: FixKind::Safe, + severity: Severity::Warning, } } diff --git a/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts.snap b/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts.snap index 55537beb6ab7..ea6897f9ed41 100644 --- a/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts.snap +++ b/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts.snap @@ -47,7 +47,7 @@ invalid.ts:2:4 lint/nursery/noTsIgnore FIXABLE ━━━━━━━━━━ 4 │ 5 │ /** - i The directive @ts-ignore shuts down any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. + i The directive @ts-ignore suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. i Safe fix: Use the directive @ts-expect-error instead. @@ -82,7 +82,7 @@ invalid.ts:6:4 lint/nursery/noTsIgnore FIXABLE ━━━━━━━━━━ │ ^^^ 10 │ - i The directive @ts-ignore shuts down any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. + i The directive @ts-ignore suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. i Safe fix: Use the directive @ts-expect-error instead. @@ -115,7 +115,7 @@ invalid.ts:13:4 lint/nursery/noTsIgnore FIXABLE ━━━━━━━━━━ │ ^^^ 16 │ - i The directive @ts-ignore shuts down any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. + i The directive @ts-ignore suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. i Safe fix: Use the directive @ts-expect-error instead. @@ -148,7 +148,7 @@ invalid.ts:19:4 lint/nursery/noTsIgnore FIXABLE ━━━━━━━━━━ │ ^^^ 21 │ - i The directive @ts-ignore shuts down any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. + i The directive @ts-ignore suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. i Safe fix: Use the directive @ts-expect-error instead. From e29a9a72155f84d01ecb229deadc3e233f7f3f6e Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 27 Nov 2024 17:38:58 +0000 Subject: [PATCH 5/8] update suggestion --- .../src/lint/nursery/no_ts_ignore.rs | 4 ++-- .../specs/nursery/noTsIgnore/invalid.ts.snap | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs b/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs index d1c95317ddaf..6760ff5d2b69 100644 --- a/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs +++ b/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs @@ -100,7 +100,7 @@ impl Rule for NoTsIgnore { }, ) .note(markup! { - "The directive ""@ts-ignore"" suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself." + "The ""@ts-ignore"" directive suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself." }), ) } @@ -136,7 +136,7 @@ impl Rule for NoTsIgnore { Some(JsRuleAction::new( ctx.metadata().action_category(ctx.category(), ctx.group()), ctx.metadata().applicability(), - markup! { "Use the directive ""@ts-expect-error"" instead." } + markup! { "Use the ""@ts-expect-error"" directive instead." } .to_owned(), mutation, )) diff --git a/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts.snap b/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts.snap index ea6897f9ed41..5c347c0e72e7 100644 --- a/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts.snap +++ b/crates/biome_js_analyze/tests/specs/nursery/noTsIgnore/invalid.ts.snap @@ -47,9 +47,9 @@ invalid.ts:2:4 lint/nursery/noTsIgnore FIXABLE ━━━━━━━━━━ 4 │ 5 │ /** - i The directive @ts-ignore suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. + i The @ts-ignore directive suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. - i Safe fix: Use the directive @ts-expect-error instead. + i Safe fix: Use the @ts-expect-error directive instead. 1 1 │ 2 │ - //·@ts-ignore @@ -82,9 +82,9 @@ invalid.ts:6:4 lint/nursery/noTsIgnore FIXABLE ━━━━━━━━━━ │ ^^^ 10 │ - i The directive @ts-ignore suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. + i The @ts-ignore directive suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. - i Safe fix: Use the directive @ts-expect-error instead. + i Safe fix: Use the @ts-expect-error directive instead. 4 4 │ 5 5 │ /** @@ -115,9 +115,9 @@ invalid.ts:13:4 lint/nursery/noTsIgnore FIXABLE ━━━━━━━━━━ │ ^^^ 16 │ - i The directive @ts-ignore suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. + i The @ts-ignore directive suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. - i Safe fix: Use the directive @ts-expect-error instead. + i Safe fix: Use the @ts-expect-error directive instead. 11 11 │ 12 12 │ // Some comment @@ -148,9 +148,9 @@ invalid.ts:19:4 lint/nursery/noTsIgnore FIXABLE ━━━━━━━━━━ │ ^^^ 21 │ - i The directive @ts-ignore suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. + i The @ts-ignore directive suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself. - i Safe fix: Use the directive @ts-expect-error instead. + i Safe fix: Use the @ts-expect-error directive instead. 17 17 │ 18 18 │ // Some comment From 376a89cd826222c0b089482c9f160894e0d3240b Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 27 Nov 2024 17:40:53 +0000 Subject: [PATCH 6/8] changeset --- .changeset/add_the_new_rule_notsignorehttps.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/add_the_new_rule_notsignorehttps.md diff --git a/.changeset/add_the_new_rule_notsignorehttps.md b/.changeset/add_the_new_rule_notsignorehttps.md new file mode 100644 index 000000000000..a6a09203a48b --- /dev/null +++ b/.changeset/add_the_new_rule_notsignorehttps.md @@ -0,0 +1,5 @@ +--- +cli: minor +--- + +# Add the new rule [`noTsIgnore`](https://biomejs.dev/linter/rules/no-ts-ignore) From 8742be02977f8d567ef6aec0f9bf5fd4ce59ffc2 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 27 Nov 2024 17:51:20 +0000 Subject: [PATCH 7/8] codegen --- .../src/execute/migrate/eslint_any_rule_to_biome.rs | 12 ++++++++++++ .../src/lint/nursery/no_ts_ignore.rs | 5 +++-- packages/@biomejs/backend-jsonrpc/src/workspace.ts | 4 ++-- packages/@biomejs/biome/configuration_schema.json | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) 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 b962c0f089ed..51164b4edc69 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 @@ -391,6 +391,18 @@ pub(crate) fn migrate_eslint_any_rule( let rule = group.use_await.get_or_insert(Default::default()); rule.set_level(rule.level().max(rule_severity.into())); } + "ban-ts-comment" => { + if !options.include_inspired { + results.has_inspired_rules = true; + return false; + } + if !options.include_nursery { + return false; + } + let group = rules.nursery.get_or_insert_with(Default::default); + let rule = group.no_ts_ignore.get_or_insert(Default::default()); + rule.set_level(rule.level().max(rule_severity.into())); + } "barrel-files/avoid-barrel-files" => { if !options.include_inspired { results.has_inspired_rules = true; diff --git a/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs b/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs index 6760ff5d2b69..bdf89ca63ead 100644 --- a/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs +++ b/crates/biome_js_analyze/src/lint/nursery/no_ts_ignore.rs @@ -65,7 +65,8 @@ impl Rule for NoTsIgnore { .pieces() .filter_map(|trivia| { if let Some(comment) = trivia.as_comments() { - for (index, _) in comment.text().match_indices("@ts-ignore") { + if let Some((index, _)) = comment.text().match_indices("@ts-ignore").next() + { return Some(( token.clone(), comment.text_range().add_start(TextSize::from(index as u32)), @@ -110,7 +111,7 @@ impl Rule for NoTsIgnore { let token = token.clone(); let mut mutation = ctx.root().begin(); let mut new_trivia = vec![]; - let mut text = String::from(""); + let mut text = String::new(); for trivia in token.clone().leading_trivia().pieces() { let kind = trivia.kind(); if let Some(comment) = trivia.as_comments() { diff --git a/packages/@biomejs/backend-jsonrpc/src/workspace.ts b/packages/@biomejs/backend-jsonrpc/src/workspace.ts index 044851a6459f..23c85ad4a0b8 100644 --- a/packages/@biomejs/backend-jsonrpc/src/workspace.ts +++ b/packages/@biomejs/backend-jsonrpc/src/workspace.ts @@ -1324,9 +1324,9 @@ export interface Nursery { */ noTemplateCurlyInString?: RuleConfiguration_for_Null; /** - * Succinct description of the rule. + * Prevents the use of the TypeScript directive @ts-ignore. */ - noTsIgnore?: RuleConfiguration_for_Null; + noTsIgnore?: RuleFixConfiguration_for_Null; /** * Disallow unknown pseudo-class selectors. */ diff --git a/packages/@biomejs/biome/configuration_schema.json b/packages/@biomejs/biome/configuration_schema.json index 9718d144969a..a637047c840c 100644 --- a/packages/@biomejs/biome/configuration_schema.json +++ b/packages/@biomejs/biome/configuration_schema.json @@ -2359,9 +2359,9 @@ ] }, "noTsIgnore": { - "description": "Succinct description of the rule.", + "description": "Prevents the use of the TypeScript directive @ts-ignore.", "anyOf": [ - { "$ref": "#/definitions/RuleConfiguration" }, + { "$ref": "#/definitions/RuleFixConfiguration" }, { "type": "null" } ] }, From 2c3df7f2bc86121ab3b3fb887661b8bb877f0420 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Thu, 28 Nov 2024 09:21:32 +0000 Subject: [PATCH 8/8] codegen --- .../migrate/eslint_any_rule_to_biome.rs | 2 +- .../src/analyzer/linter/rules.rs | 127 ++++++++++-------- .../@biomejs/backend-jsonrpc/src/workspace.ts | 10 +- .../@biomejs/biome/configuration_schema.json | 22 +-- 4 files changed, 77 insertions(+), 84 deletions(-) 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 51164b4edc69..5e7227f03245 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 @@ -491,7 +491,7 @@ pub(crate) fn migrate_eslint_any_rule( } let group = rules.nursery.get_or_insert_with(Default::default); let rule = group - .no_restricted_imports + .no_package_private_imports .get_or_insert(Default::default()); rule.set_level(rule.level().max(rule_severity.into())); } diff --git a/crates/biome_configuration/src/analyzer/linter/rules.rs b/crates/biome_configuration/src/analyzer/linter/rules.rs index cef83e05a2fa..5755eedacddf 100644 --- a/crates/biome_configuration/src/analyzer/linter/rules.rs +++ b/crates/biome_configuration/src/analyzer/linter/rules.rs @@ -3366,7 +3366,7 @@ pub struct Nursery { #[doc = "Disallow octal escape sequences in string literals"] #[serde(skip_serializing_if = "Option::is_none")] pub no_octal_escape: Option>, - #[doc = "Succinct description of the rule."] + #[doc = "Restricts imports of \"package private\" exports."] #[serde(skip_serializing_if = "Option::is_none")] pub no_package_private_imports: Option>, @@ -3395,6 +3395,9 @@ pub struct Nursery { #[serde(skip_serializing_if = "Option::is_none")] pub no_template_curly_in_string: Option>, + #[doc = "Prevents the use of the TypeScript directive @ts-ignore."] + #[serde(skip_serializing_if = "Option::is_none")] + pub no_ts_ignore: Option>, #[doc = "Disallow unknown pseudo-class selectors."] #[serde(skip_serializing_if = "Option::is_none")] pub no_unknown_pseudo_class: @@ -3530,6 +3533,7 @@ impl Nursery { "noStaticElementInteractions", "noSubstr", "noTemplateCurlyInString", + "noTsIgnore", "noUnknownPseudoClass", "noUnknownPseudoElement", "noUnknownTypeSelector", @@ -3562,6 +3566,7 @@ impl Nursery { "noDuplicateProperties", "noDuplicatedFields", "noMissingVarFunction", + "noTsIgnore", "noUnknownPseudoClass", "noUnknownPseudoElement", "noUnknownTypeSelector", @@ -3583,11 +3588,12 @@ impl Nursery { RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[29]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[30]), - RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[35]), - RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[40]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[31]), + 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[46]), - RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[48]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[42]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[47]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[49]), ]; const ALL_RULES_AS_FILTERS: &'static [RuleFilter<'static>] = &[ RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[0]), @@ -3641,6 +3647,7 @@ impl Nursery { RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[48]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[49]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[50]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[51]), ]; #[doc = r" Retrieves the recommended rules"] pub(crate) fn is_recommended_true(&self) -> bool { @@ -3792,126 +3799,131 @@ impl Nursery { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[26])); } } - if let Some(rule) = self.no_unknown_pseudo_class.as_ref() { + if let Some(rule) = self.no_ts_ignore.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[27])); } } - if let Some(rule) = self.no_unknown_pseudo_element.as_ref() { + if let Some(rule) = self.no_unknown_pseudo_class.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28])); } } - if let Some(rule) = self.no_unknown_type_selector.as_ref() { + if let Some(rule) = self.no_unknown_pseudo_element.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[29])); } } - if let Some(rule) = self.no_useless_escape_in_regex.as_ref() { + if let Some(rule) = self.no_unknown_type_selector.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[30])); } } - if let Some(rule) = self.no_useless_string_raw.as_ref() { + if let Some(rule) = self.no_useless_escape_in_regex.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[31])); } } - if let Some(rule) = self.no_useless_undefined.as_ref() { + if let Some(rule) = self.no_useless_string_raw.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[32])); } } - if let Some(rule) = self.no_value_at_rule.as_ref() { + if let Some(rule) = self.no_useless_undefined.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[33])); } } - if let Some(rule) = self.use_adjacent_overload_signatures.as_ref() { + if let Some(rule) = self.no_value_at_rule.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[34])); } } - if let Some(rule) = self.use_aria_props_supported_by_role.as_ref() { + if let Some(rule) = self.use_adjacent_overload_signatures.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[35])); } } - if let Some(rule) = self.use_at_index.as_ref() { + if let Some(rule) = self.use_aria_props_supported_by_role.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[36])); } } - if let Some(rule) = self.use_collapsed_if.as_ref() { + if let Some(rule) = self.use_at_index.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[37])); } } - if let Some(rule) = self.use_component_export_only_modules.as_ref() { + if let Some(rule) = self.use_collapsed_if.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[38])); } } - if let Some(rule) = self.use_consistent_curly_braces.as_ref() { + if let Some(rule) = self.use_component_export_only_modules.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[39])); } } - if let Some(rule) = self.use_consistent_member_accessibility.as_ref() { + if let Some(rule) = self.use_consistent_curly_braces.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[40])); } } - if let Some(rule) = self.use_deprecated_reason.as_ref() { + if let Some(rule) = self.use_consistent_member_accessibility.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[41])); } } - if let Some(rule) = self.use_explicit_type.as_ref() { + if let Some(rule) = self.use_deprecated_reason.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[42])); } } - if let Some(rule) = self.use_google_font_display.as_ref() { + if let Some(rule) = self.use_explicit_type.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[43])); } } - if let Some(rule) = self.use_google_font_preconnect.as_ref() { + if let Some(rule) = self.use_google_font_display.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[44])); } } - if let Some(rule) = self.use_guard_for_in.as_ref() { + if let Some(rule) = self.use_google_font_preconnect.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[45])); } } - if let Some(rule) = self.use_named_operation.as_ref() { + if let Some(rule) = self.use_guard_for_in.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[46])); } } - if let Some(rule) = self.use_sorted_classes.as_ref() { + if let Some(rule) = self.use_named_operation.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[47])); } } - 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[48])); } } - 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[49])); } } - 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[50])); } } + 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[51])); + } + } index_set } pub(crate) fn get_disabled_rules(&self) -> FxHashSet> { @@ -4051,126 +4063,131 @@ impl Nursery { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[26])); } } - if let Some(rule) = self.no_unknown_pseudo_class.as_ref() { + if let Some(rule) = self.no_ts_ignore.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[27])); } } - if let Some(rule) = self.no_unknown_pseudo_element.as_ref() { + if let Some(rule) = self.no_unknown_pseudo_class.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28])); } } - if let Some(rule) = self.no_unknown_type_selector.as_ref() { + if let Some(rule) = self.no_unknown_pseudo_element.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[29])); } } - if let Some(rule) = self.no_useless_escape_in_regex.as_ref() { + if let Some(rule) = self.no_unknown_type_selector.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[30])); } } - if let Some(rule) = self.no_useless_string_raw.as_ref() { + if let Some(rule) = self.no_useless_escape_in_regex.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[31])); } } - if let Some(rule) = self.no_useless_undefined.as_ref() { + if let Some(rule) = self.no_useless_string_raw.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[32])); } } - if let Some(rule) = self.no_value_at_rule.as_ref() { + if let Some(rule) = self.no_useless_undefined.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[33])); } } - if let Some(rule) = self.use_adjacent_overload_signatures.as_ref() { + if let Some(rule) = self.no_value_at_rule.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[34])); } } - if let Some(rule) = self.use_aria_props_supported_by_role.as_ref() { + if let Some(rule) = self.use_adjacent_overload_signatures.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[35])); } } - if let Some(rule) = self.use_at_index.as_ref() { + if let Some(rule) = self.use_aria_props_supported_by_role.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[36])); } } - if let Some(rule) = self.use_collapsed_if.as_ref() { + if let Some(rule) = self.use_at_index.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[37])); } } - if let Some(rule) = self.use_component_export_only_modules.as_ref() { + if let Some(rule) = self.use_collapsed_if.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[38])); } } - if let Some(rule) = self.use_consistent_curly_braces.as_ref() { + if let Some(rule) = self.use_component_export_only_modules.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[39])); } } - if let Some(rule) = self.use_consistent_member_accessibility.as_ref() { + if let Some(rule) = self.use_consistent_curly_braces.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[40])); } } - if let Some(rule) = self.use_deprecated_reason.as_ref() { + if let Some(rule) = self.use_consistent_member_accessibility.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[41])); } } - if let Some(rule) = self.use_explicit_type.as_ref() { + if let Some(rule) = self.use_deprecated_reason.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[42])); } } - if let Some(rule) = self.use_google_font_display.as_ref() { + if let Some(rule) = self.use_explicit_type.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[43])); } } - if let Some(rule) = self.use_google_font_preconnect.as_ref() { + if let Some(rule) = self.use_google_font_display.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[44])); } } - if let Some(rule) = self.use_guard_for_in.as_ref() { + if let Some(rule) = self.use_google_font_preconnect.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[45])); } } - if let Some(rule) = self.use_named_operation.as_ref() { + if let Some(rule) = self.use_guard_for_in.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[46])); } } - if let Some(rule) = self.use_sorted_classes.as_ref() { + if let Some(rule) = self.use_named_operation.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[47])); } } - 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[48])); } } - 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[49])); } } - 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[50])); } } + 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[51])); + } + } index_set } #[doc = r" Checks if, given a rule name, matches one of the rules contained in this category"] @@ -4315,6 +4332,10 @@ impl Nursery { .no_template_curly_in_string .as_ref() .map(|conf| (conf.level(), conf.get_options())), + "noTsIgnore" => self + .no_ts_ignore + .as_ref() + .map(|conf| (conf.level(), conf.get_options())), "noUnknownPseudoClass" => self .no_unknown_pseudo_class .as_ref() diff --git a/packages/@biomejs/backend-jsonrpc/src/workspace.ts b/packages/@biomejs/backend-jsonrpc/src/workspace.ts index 23c85ad4a0b8..38ccd55861b3 100644 --- a/packages/@biomejs/backend-jsonrpc/src/workspace.ts +++ b/packages/@biomejs/backend-jsonrpc/src/workspace.ts @@ -1292,7 +1292,7 @@ export interface Nursery { */ noOctalEscape?: RuleConfiguration_for_Null; /** - * Succinct description of the rule. + * Restricts imports of "package private" exports. */ noPackagePrivateImports?: RuleConfiguration_for_Null; /** @@ -2523,10 +2523,6 @@ export interface RestrictedImportsOptions { * A list of import paths that should trigger the rule. */ paths: {}; - /** - * Whether to place restrictions on the importing of "package private" symbols. - */ - restrictPackagePrivate?: PackagePrivateRestriction; } export interface NoRestrictedTypesOptions { types?: {}; @@ -2671,10 +2667,6 @@ For example, for React's `useRef()` hook the value would be `true`, while for `u */ stableResult?: StableHookResult; } -/** - * Allowed values for the `restrictPackagePrivate` option. - */ -export type PackagePrivateRestriction = "all" | "none"; export type Accessibility = "noPublic" | "explicit" | "none"; export type ConsistentArrayType = "shorthand" | "generic"; export type FilenameCases = FilenameCase[]; diff --git a/packages/@biomejs/biome/configuration_schema.json b/packages/@biomejs/biome/configuration_schema.json index a637047c840c..aa3c7fd0cdf5 100644 --- a/packages/@biomejs/biome/configuration_schema.json +++ b/packages/@biomejs/biome/configuration_schema.json @@ -2303,7 +2303,7 @@ ] }, "noPackagePrivateImports": { - "description": "Succinct description of the rule.", + "description": "Restricts imports of \"package private\" exports.", "anyOf": [ { "$ref": "#/definitions/RuleConfiguration" }, { "type": "null" } @@ -2710,21 +2710,6 @@ "type": "array", "items": { "$ref": "#/definitions/OverridePattern" } }, - "PackagePrivateRestriction": { - "description": "Allowed values for the `restrictPackagePrivate` option.", - "oneOf": [ - { - "description": "All exported symbols are assumed to be package private and may only be imported from sibling modules and their submodules.", - "type": "string", - "enum": ["all"] - }, - { - "description": "No restrictions are applied on importing package private symbols.", - "type": "string", - "enum": ["none"] - } - ] - }, "Performance": { "description": "A list of rules that belong to this group", "type": "object", @@ -2821,11 +2806,6 @@ "additionalProperties": { "$ref": "#/definitions/CustomRestrictedImport" } - }, - "restrictPackagePrivate": { - "description": "Whether to place restrictions on the importing of \"package private\" symbols.", - "default": "none", - "allOf": [{ "$ref": "#/definitions/PackagePrivateRestriction" }] } }, "additionalProperties": false