From 720f9abbf72c947b775ec5d2ac41f374b97b30e3 Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 01:54:10 -0300 Subject: [PATCH 01/14] feat(rome_js_analyzer): added no extra semicolons rule --- .../src/categories.rs | 1 + .../rome_js_analyze/src/analyzers/nursery.rs | 3 +- .../analyzers/nursery/no_extra_semicolons.rs | 173 ++++++++ .../nursery/noExtraSemicolons/invalid.js | 87 ++++ .../nursery/noExtraSemicolons/invalid.js.snap | 399 ++++++++++++++++++ .../specs/nursery/noExtraSemicolons/valid.js | 51 +++ .../nursery/noExtraSemicolons/valid.js.snap | 81 ++++ crates/rome_js_unicode_table/src/tables.rs | 8 +- .../src/configuration/linter/rules.rs | 11 +- npm/backend-jsonrpc/src/workspace.ts | 5 + npm/rome/configuration_schema.json | 11 + 11 files changed, 819 insertions(+), 11 deletions(-) create mode 100644 crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs create mode 100644 crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js create mode 100644 crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js.snap create mode 100644 crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js create mode 100644 crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js.snap diff --git a/crates/rome_diagnostics_categories/src/categories.rs b/crates/rome_diagnostics_categories/src/categories.rs index 8beb8c451f1..031da26c5b5 100644 --- a/crates/rome_diagnostics_categories/src/categories.rs +++ b/crates/rome_diagnostics_categories/src/categories.rs @@ -45,6 +45,7 @@ define_dategories! { "lint/nursery/noAccessKey": "https://docs.rome.tools/lint/rules/noAccessKey", "lint/nursery/noAssignInExpressions": "https://docs.rome.tools/lint/rules/noAssignInExpressions", "lint/nursery/noWith": "https://docs.rome.tools/lint/rules/noWith", + "lint/nursery/noExtraSemicolons": "https://docs.rome.tools/lint/rules/noExtraSemicolons", "lint/nursery/noBannedTypes":"https://docs.rome.tools/lint/rules/noBannedTypes", "lint/nursery/noConstEnum": "https://docs.rome.tools/lint/rules/noConstEnum", "lint/nursery/noConstructorReturn": "https://docs.rome.tools/lint/rules/noConstructorReturn", diff --git a/crates/rome_js_analyze/src/analyzers/nursery.rs b/crates/rome_js_analyze/src/analyzers/nursery.rs index e5f3250dbd6..29be2870618 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery.rs @@ -11,6 +11,7 @@ mod no_distracting_elements; mod no_duplicate_object_keys; mod no_empty_interface; mod no_extra_non_null_assertion; +mod no_extra_semicolons; mod no_header_scope; mod no_invalid_constructor_super; mod no_non_null_assertion; @@ -28,4 +29,4 @@ mod use_default_switch_clause_last; mod use_enum_initializers; mod use_exponentiation_operator; mod use_numeric_literals; -declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_access_key :: NoAccessKey , self :: no_assign_in_expressions :: NoAssignInExpressions , self :: no_banned_types :: NoBannedTypes , self :: no_comma_operator :: NoCommaOperator , self :: no_const_enum :: NoConstEnum , self :: no_constructor_return :: NoConstructorReturn , self :: no_distracting_elements :: NoDistractingElements , self :: no_duplicate_object_keys :: NoDuplicateObjectKeys , self :: no_empty_interface :: NoEmptyInterface , self :: no_extra_non_null_assertion :: NoExtraNonNullAssertion , self :: no_header_scope :: NoHeaderScope , self :: no_invalid_constructor_super :: NoInvalidConstructorSuper , self :: no_non_null_assertion :: NoNonNullAssertion , self :: no_precision_loss :: NoPrecisionLoss , self :: no_redundant_alt :: NoRedundantAlt , self :: no_redundant_use_strict :: NoRedundantUseStrict , self :: no_setter_return :: NoSetterReturn , self :: no_string_case_mismatch :: NoStringCaseMismatch , self :: no_unsafe_finally :: NoUnsafeFinally , self :: no_useless_switch_case :: NoUselessSwitchCase , self :: no_void_type_return :: NoVoidTypeReturn , self :: no_with :: NoWith , self :: use_default_parameter_last :: UseDefaultParameterLast , self :: use_default_switch_clause_last :: UseDefaultSwitchClauseLast , self :: use_enum_initializers :: UseEnumInitializers , self :: use_exponentiation_operator :: UseExponentiationOperator , self :: use_numeric_literals :: UseNumericLiterals ,] } } +declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_access_key :: NoAccessKey , self :: no_assign_in_expressions :: NoAssignInExpressions , self :: no_banned_types :: NoBannedTypes , self :: no_comma_operator :: NoCommaOperator , self :: no_const_enum :: NoConstEnum , self :: no_constructor_return :: NoConstructorReturn , self :: no_distracting_elements :: NoDistractingElements , self :: no_duplicate_object_keys :: NoDuplicateObjectKeys , self :: no_empty_interface :: NoEmptyInterface , self :: no_extra_non_null_assertion :: NoExtraNonNullAssertion , self :: no_extra_semicolons :: NoExtraSemicolons , self :: no_header_scope :: NoHeaderScope , self :: no_invalid_constructor_super :: NoInvalidConstructorSuper , self :: no_non_null_assertion :: NoNonNullAssertion , self :: no_precision_loss :: NoPrecisionLoss , self :: no_redundant_alt :: NoRedundantAlt , self :: no_redundant_use_strict :: NoRedundantUseStrict , self :: no_setter_return :: NoSetterReturn , self :: no_string_case_mismatch :: NoStringCaseMismatch , self :: no_unsafe_finally :: NoUnsafeFinally , self :: no_useless_switch_case :: NoUselessSwitchCase , self :: no_void_type_return :: NoVoidTypeReturn , self :: no_with :: NoWith , self :: use_default_parameter_last :: UseDefaultParameterLast , self :: use_default_switch_clause_last :: UseDefaultSwitchClauseLast , self :: use_enum_initializers :: UseEnumInitializers , self :: use_exponentiation_operator :: UseExponentiationOperator , self :: use_numeric_literals :: UseNumericLiterals ,] } } diff --git a/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs b/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs new file mode 100644 index 00000000000..d747b1a9f6c --- /dev/null +++ b/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs @@ -0,0 +1,173 @@ +use rome_analyze::context::RuleContext; +use rome_analyze::{declare_rule, ActionCategory, Ast, Rule, RuleAction, RuleDiagnostic}; +use rome_console::markup; +use rome_diagnostics::Applicability; +use rome_js_syntax::{JsEmptyClassMember, JsEmptyStatement, JsSyntaxKind}; + +use rome_rowan::{declare_node_union, AstNode, BatchMutationExt}; + +use crate::JsRuleAction; + +declare_rule! { + /// Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. + /// While not technically an error, extra semicolons can cause confusion when reading code. + /// + /// This rule disallows unnecessary semicolons. + /// + /// ## Examples + /// + /// ### Invalid + /// + ///```js,expect_diagnostic + /// const x = 5;; + ///``` + /// + ///```js,expect_diagnostic + /// function buzz() { + /// const x = 10;; + /// } + ///``` + /// + ///```js,expect_diagnostic + /// function foo() { + /// // code + /// }; + ///``` + /// + ///```js,expect_diagnostic + /// class C { + /// field;; + /// + /// method() { + /// // code + /// } + /// + /// static { + /// // code + /// } + /// } + /// ``` + /// + /// ```js,expect_diagnostic + /// class C { + /// field; + /// + /// method() { + /// // code + /// }; + /// + /// static { + /// // code + /// } + /// } + /// ``` + /// + /// ```js,expect_diagnostic + /// class C { + /// field; + /// + /// method() { + /// // code + /// } + /// + /// static { + /// // code + /// }; + /// } + /// ``` + /// + /// ```js,expect_diagnostic + /// class C { + /// field; + /// + /// method() { + /// // code + /// } + /// + /// static { + /// // code + /// } + /// }; + /// ``` + pub(crate) NoExtraSemicolons { + version: "12.0.0", + name: "noExtraSemicolons", + recommended: true, + } +} + +declare_node_union! { + pub(crate) AnyJsExtraSemicolon = JsEmptyStatement | JsEmptyClassMember +} + +impl Rule for NoExtraSemicolons { + type Query = Ast; + type State = AnyJsExtraSemicolonOptionType; + type Signals = Option; + type Options = (); + + fn run(ctx: &RuleContext) -> Option { + let node = ctx.query(); + + match node { + AnyJsExtraSemicolon::JsEmptyStatement(stmt) => { + let parent = stmt.syntax().parent()?; + let allowed_parent_kinds = vec![ + JsSyntaxKind::JS_FOR_STATEMENT, + JsSyntaxKind::JS_FOR_IN_STATEMENT, + JsSyntaxKind::JS_FOR_OF_STATEMENT, + JsSyntaxKind::JS_WHILE_STATEMENT, + JsSyntaxKind::JS_DO_WHILE_STATEMENT, + JsSyntaxKind::JS_IF_STATEMENT, + JsSyntaxKind::JS_LABELED_STATEMENT, + JsSyntaxKind::JS_WITH_STATEMENT, + ]; + let has_allowed_parent = allowed_parent_kinds.contains(&parent.kind()); + if !has_allowed_parent { + Some(AnyJsExtraSemicolonOptionType::JsEmptyStatement( + stmt.clone(), + )) + } else { + None + } + } + AnyJsExtraSemicolon::JsEmptyClassMember(stmt) => Some( + AnyJsExtraSemicolonOptionType::JsEmptyClassMember(stmt.clone()), + ), + } + } + + fn diagnostic(ctx: &RuleContext, _: &Self::State) -> Option { + let node = ctx.query(); + Some(RuleDiagnostic::new( + rule_category!(), + node.range(), + markup! { + "Unnecessary semicolon." + }, + )) + } + + fn action(ctx: &RuleContext, node_replace: &Self::State) -> Option { + let mut mutation = ctx.root().begin(); + match node_replace { + AnyJsExtraSemicolonOptionType::JsEmptyStatement(stmt) => { + mutation.remove_node(stmt.clone()); + } + AnyJsExtraSemicolonOptionType::JsEmptyClassMember(stmt) => { + mutation.remove_node(stmt.clone()); + } + } + Some(RuleAction { + category: ActionCategory::QuickFix, + applicability: Applicability::MaybeIncorrect, + message: markup! { "Remove unnecessary semicolon." }.to_owned(), + mutation, + }) + } +} + +pub enum AnyJsExtraSemicolonOptionType { + JsEmptyStatement(JsEmptyStatement), + JsEmptyClassMember(JsEmptyClassMember), +} diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js new file mode 100644 index 00000000000..687522e7b46 --- /dev/null +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js @@ -0,0 +1,87 @@ +// invalid + +const x = 10; +if (x > 5) { + x = 5; +}; + +while(true);; + +while(true) {}; + +loop1: +for (let i = 0; i < 5; i++) { + str = str + i;; +}; + +loop1: +for (let i = 0; i < 5; i++) { + if (i === 1) { + continue loop1; + } + str = str + i; +}; + +function baz() { ; } + +function buzz() { + const x = 10;; +} + +for(;true;);; + +for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + +const x = 5;; + +function foo() { + // code +}; + +class C { + field;; + + method() { + // code + } + + static { + // code + } +} + +class C { + field; + + method() { + // code + }; + + static { + // code + } +} + +class C { + field; + + method() { + // code + } + + static { + // code + }; +} + +class C { + field; + + method() { + // code + } + + static { + // code + } +}; diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js.snap new file mode 100644 index 00000000000..f648bc5ca71 --- /dev/null +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js.snap @@ -0,0 +1,399 @@ +--- +source: crates/rome_js_analyze/tests/spec_tests.rs +expression: invalid.js +--- +# Input +```js +// invalid + +const x = 10; +if (x > 5) { + x = 5; +}; + +while(true);; + +while(true) {}; + +loop1: +for (let i = 0; i < 5; i++) { + str = str + i;; +}; + +loop1: +for (let i = 0; i < 5; i++) { + if (i === 1) { + continue loop1; + } + str = str + i; +}; + +function baz() { ; } + +function buzz() { + const x = 10;; +} + +for(;true;);; + +for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + +const x = 5;; + +function foo() { + // code +}; + +class C { + field;; + + method() { + // code + } + + static { + // code + } +} + +class C { + field; + + method() { + // code + }; + + static { + // code + } +} + +class C { + field; + + method() { + // code + } + + static { + // code + }; +} + +class C { + field; + + method() { + // code + } + + static { + // code + } +}; + +``` + +# Diagnostics +``` +invalid.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 4 │ if (x > 5) { + 5 │ x = 5; + > 6 │ }; + │ ^ + 7 │ + 8 │ while(true);; + + i Suggested fix: Remove unnecessary semicolon. + + 6 │ };␍ + │ - + +``` + +``` +invalid.js:8:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 6 │ }; + 7 │ + > 8 │ while(true);; + │ ^ + 9 │ + 10 │ while(true) {}; + + i Suggested fix: Remove unnecessary semicolon. + + 8 │ while(true);;␍ + │ - + +``` + +``` +invalid.js:10:15 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 8 │ while(true);; + 9 │ + > 10 │ while(true) {}; + │ ^ + 11 │ + 12 │ loop1: + + i Suggested fix: Remove unnecessary semicolon. + + 10 │ while(true)·{};␍ + │ - + +``` + +``` +invalid.js:14:17 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 12 │ loop1: + 13 │ for (let i = 0; i < 5; i++) { + > 14 │ str = str + i;; + │ ^ + 15 │ }; + 16 │ + + i Suggested fix: Remove unnecessary semicolon. + + 14 │ ··str·=·str·+·i;;␍ + │ - + +``` + +``` +invalid.js:15:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 13 │ for (let i = 0; i < 5; i++) { + 14 │ str = str + i;; + > 15 │ }; + │ ^ + 16 │ + 17 │ loop1: + + i Suggested fix: Remove unnecessary semicolon. + + 15 │ };␍ + │ - + +``` + +``` +invalid.js:23:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 21 │ } + 22 │ str = str + i; + > 23 │ }; + │ ^ + 24 │ + 25 │ function baz() { ; } + + i Suggested fix: Remove unnecessary semicolon. + + 23 │ };␍ + │ - + +``` + +``` +invalid.js:25:18 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 23 │ }; + 24 │ + > 25 │ function baz() { ; } + │ ^ + 26 │ + 27 │ function buzz() { + + i Suggested fix: Remove unnecessary semicolon. + + 25 │ function·baz()·{·;·}␍ + │ -- + +``` + +``` +invalid.js:28:16 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 27 │ function buzz() { + > 28 │ const x = 10;; + │ ^ + 29 │ } + 30 │ + + i Suggested fix: Remove unnecessary semicolon. + + 28 │ ··const·x·=·10;;␍ + │ - + +``` + +``` +invalid.js:31:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 29 │ } + 30 │ + > 31 │ for(;true;);; + │ ^ + 32 │ + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + + i Suggested fix: Remove unnecessary semicolon. + + 31 │ for(;true;);;␍ + │ - + +``` + +``` +invalid.js:33:61 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 31 │ for(;true;);; + 32 │ + > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ ^ + 34 │ + 35 │ const x = 5;; + + i Suggested fix: Remove unnecessary semicolon. + + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);;␍ + │ - + +``` + +``` +invalid.js:35:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + 34 │ + > 35 │ const x = 5;; + │ ^ + 36 │ + 37 │ function foo() { + + i Suggested fix: Remove unnecessary semicolon. + + 35 │ const·x·=·5;;␍ + │ - + +``` + +``` +invalid.js:39:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 37 │ function foo() { + 38 │ // code + > 39 │ }; + │ ^ + 40 │ + 41 │ class C { + + i Suggested fix: Remove unnecessary semicolon. + + 39 │ };␍ + │ - + +``` + +``` +invalid.js:42:11 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 41 │ class C { + > 42 │ field;; + │ ^ + 43 │ + 44 │ method() { + + i Suggested fix: Remove unnecessary semicolon. + + 42 │ ····field;;␍ + │ - + +``` + +``` +invalid.js:58:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 56 │ method() { + 57 │ // code + > 58 │ }; + │ ^ + 59 │ + 60 │ static { + + i Suggested fix: Remove unnecessary semicolon. + + 58 │ ····};␍ + │ - + +``` + +``` +invalid.js:74:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 72 │ static { + 73 │ // code + > 74 │ }; + │ ^ + 75 │ } + 76 │ + + i Suggested fix: Remove unnecessary semicolon. + + 74 │ ····};␍ + │ - + +``` + +``` +invalid.js:87:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 85 │ // code + 86 │ } + > 87 │ }; + │ ^ + 88 │ + + i Suggested fix: Remove unnecessary semicolon. + + 87 │ };␍ + │ - + +``` + + diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js new file mode 100644 index 00000000000..5c9eb638ae1 --- /dev/null +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js @@ -0,0 +1,51 @@ +// valid + +const x = 10; +if (x > 5) { + x = 5; +}; + +while(true); + +while(true) {} + +loop1: +for (let i = 0; i < 5; i++) { + str = str + i; +} + +loop1: +for (let i = 0; i < 5; i++) { + if (i === 1) { + continue loop1; + } + str = str + i; +} + +function baz() {} + +function buzz() { + const x = 10; +} + +for(;true;); + +for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + +const x = 5; + +const foo = function() { + // code +}; + +class C { + field; + + method() { + // code + } + + static { + // code + } +} diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js.snap new file mode 100644 index 00000000000..ccc2fb0224c --- /dev/null +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js.snap @@ -0,0 +1,81 @@ +--- +source: crates/rome_js_analyze/tests/spec_tests.rs +expression: valid.js +--- +# Input +```js +// valid + +const x = 10; +if (x > 5) { + x = 5; +}; + +while(true); + +while(true) {} + +loop1: +for (let i = 0; i < 5; i++) { + str = str + i; +} + +loop1: +for (let i = 0; i < 5; i++) { + if (i === 1) { + continue loop1; + } + str = str + i; +} + +function baz() {} + +function buzz() { + const x = 10; +} + +for(;true;); + +for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + +const x = 5; + +const foo = function() { + // code +}; + +class C { + field; + + method() { + // code + } + + static { + // code + } +} + +``` + +# Diagnostics +``` +valid.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 4 │ if (x > 5) { + 5 │ x = 5; + > 6 │ }; + │ ^ + 7 │ + 8 │ while(true); + + i Suggested fix: Remove unnecessary semicolon. + + 6 │ };␍ + │ - + +``` + + diff --git a/crates/rome_js_unicode_table/src/tables.rs b/crates/rome_js_unicode_table/src/tables.rs index 7f67057597c..eb783866c93 100644 --- a/crates/rome_js_unicode_table/src/tables.rs +++ b/crates/rome_js_unicode_table/src/tables.rs @@ -787,9 +787,7 @@ pub mod derived_property { ('\u{31350}', '\u{323af}'), ('\u{e0100}', '\u{e01ef}'), ]; - pub fn ID_Continue(c: char) -> bool { - super::bsearch_range_table(c, ID_Continue_table) - } + pub fn ID_Continue(c: char) -> bool { super::bsearch_range_table(c, ID_Continue_table) } pub const ID_Start_table: &[(char, char)] = &[ ('A', 'Z'), ('a', 'z'), @@ -1451,7 +1449,5 @@ pub mod derived_property { ('𰀀', '𱍊'), ('\u{31350}', '\u{323af}'), ]; - pub fn ID_Start(c: char) -> bool { - super::bsearch_range_table(c, ID_Start_table) - } + pub fn ID_Start(c: char) -> bool { super::bsearch_range_table(c, ID_Start_table) } } diff --git a/crates/rome_service/src/configuration/linter/rules.rs b/crates/rome_service/src/configuration/linter/rules.rs index 916e43938b3..361b172dc25 100644 --- a/crates/rome_service/src/configuration/linter/rules.rs +++ b/crates/rome_service/src/configuration/linter/rules.rs @@ -796,7 +796,7 @@ struct NurserySchema { } impl Nursery { const CATEGORY_NAME: &'static str = "nursery"; - pub(crate) const CATEGORY_RULES: [&'static str; 35] = [ + pub(crate) const CATEGORY_RULES: [&'static str; 36] = [ "noAccessKey", "noAssignInExpressions", "noBannedTypes", @@ -821,6 +821,7 @@ impl Nursery { "noVar", "noVoidTypeReturn", "noWith", + "noExtraSemicolons", "useAriaPropTypes", "useAriaPropsForRole", "useCamelCase", @@ -833,7 +834,7 @@ impl Nursery { "useHookAtTopLevel", "useNumericLiterals", ]; - const RECOMMENDED_RULES: [&'static str; 26] = [ + const RECOMMENDED_RULES: [&'static str; 27] = [ "noAssignInExpressions", "noBannedTypes", "noCommaOperator", @@ -853,6 +854,7 @@ impl Nursery { "noVar", "noVoidTypeReturn", "noWith", + "noExtraSemicolons", "useAriaPropsForRole", "useConst", "useDefaultParameterLast", @@ -861,7 +863,7 @@ impl Nursery { "useExhaustiveDependencies", "useNumericLiterals", ]; - const RECOMMENDED_RULES_AS_FILTERS: [RuleFilter<'static>; 26] = [ + const RECOMMENDED_RULES_AS_FILTERS: [RuleFilter<'static>; 27] = [ RuleFilter::Rule("nursery", Self::CATEGORY_RULES[1]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[2]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[3]), @@ -873,6 +875,7 @@ impl Nursery { RuleFilter::Rule("nursery", Self::CATEGORY_RULES[9]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[10]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[11]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[12]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[14]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[17]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[18]), @@ -914,7 +917,7 @@ impl Nursery { pub(crate) fn is_recommended_rule(rule_name: &str) -> bool { Self::RECOMMENDED_RULES.contains(&rule_name) } - pub(crate) fn recommended_rules_as_filters() -> [RuleFilter<'static>; 26] { + pub(crate) fn recommended_rules_as_filters() -> [RuleFilter<'static>; 27] { Self::RECOMMENDED_RULES_AS_FILTERS } } diff --git a/npm/backend-jsonrpc/src/workspace.ts b/npm/backend-jsonrpc/src/workspace.ts index 7375456ebac..4745c7d1029 100644 --- a/npm/backend-jsonrpc/src/workspace.ts +++ b/npm/backend-jsonrpc/src/workspace.ts @@ -381,6 +381,10 @@ export interface Nursery { * Disallow with statements in non-strict contexts. */ noWith?: RuleConfiguration; + /** + * Disallow unnecessary semicolons. + */ + noExtraSemicolons?: RuleConfiguration; /** * It enables the recommended rules for this group */ @@ -701,6 +705,7 @@ export type Category = | "lint/nursery/noAccessKey" | "lint/nursery/noAssignInExpressions" | "lint/nursery/noWith" + | "lint/nursery/noExtraSemicolons" | "lint/nursery/noBannedTypes" | "lint/nursery/noConstEnum" | "lint/nursery/noConstructorReturn" diff --git a/npm/rome/configuration_schema.json b/npm/rome/configuration_schema.json index ee247f404e2..432c3c51fb5 100644 --- a/npm/rome/configuration_schema.json +++ b/npm/rome/configuration_schema.json @@ -841,6 +841,17 @@ } ] }, + "noExtraSemicolons": { + "description": "Disallow unnecessary semicolons.", + "anyOf": [ + { + "$ref": "#/definitions/RuleConfiguration" + }, + { + "type": "null" + } + ] + }, "recommended": { "description": "It enables the recommended rules for this group", "type": [ From a5379074380520d9fef6eb8474f19e9fe791c14e Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 02:01:24 -0300 Subject: [PATCH 02/14] feat(rome_js_analyzer): generated additional content --- .../analyzers/nursery/no_extra_semicolons.rs | 6 +- crates/rome_js_unicode_table/src/tables.rs | 8 +- .../src/configuration/linter/rules.rs | 16 +- editors/vscode/configuration_schema.json | 11 + npm/backend-jsonrpc/src/workspace.ts | 8 +- npm/rome/configuration_schema.json | 22 +- website/src/pages/lint/rules/index.mdx | 7 + .../src/pages/lint/rules/noExtraSemicolons.md | 200 ++++++++++++++++++ 8 files changed, 251 insertions(+), 27 deletions(-) create mode 100644 website/src/pages/lint/rules/noExtraSemicolons.md diff --git a/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs b/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs index d747b1a9f6c..cf58380f77e 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs @@ -21,19 +21,19 @@ declare_rule! { ///```js,expect_diagnostic /// const x = 5;; ///``` - /// + /// ///```js,expect_diagnostic /// function buzz() { /// const x = 10;; /// } ///``` - /// + /// ///```js,expect_diagnostic /// function foo() { /// // code /// }; ///``` - /// + /// ///```js,expect_diagnostic /// class C { /// field;; diff --git a/crates/rome_js_unicode_table/src/tables.rs b/crates/rome_js_unicode_table/src/tables.rs index eb783866c93..7f67057597c 100644 --- a/crates/rome_js_unicode_table/src/tables.rs +++ b/crates/rome_js_unicode_table/src/tables.rs @@ -787,7 +787,9 @@ pub mod derived_property { ('\u{31350}', '\u{323af}'), ('\u{e0100}', '\u{e01ef}'), ]; - pub fn ID_Continue(c: char) -> bool { super::bsearch_range_table(c, ID_Continue_table) } + pub fn ID_Continue(c: char) -> bool { + super::bsearch_range_table(c, ID_Continue_table) + } pub const ID_Start_table: &[(char, char)] = &[ ('A', 'Z'), ('a', 'z'), @@ -1449,5 +1451,7 @@ pub mod derived_property { ('𰀀', '𱍊'), ('\u{31350}', '\u{323af}'), ]; - pub fn ID_Start(c: char) -> bool { super::bsearch_range_table(c, ID_Start_table) } + pub fn ID_Start(c: char) -> bool { + super::bsearch_range_table(c, ID_Start_table) + } } diff --git a/crates/rome_service/src/configuration/linter/rules.rs b/crates/rome_service/src/configuration/linter/rules.rs index 361b172dc25..08e6266a5dc 100644 --- a/crates/rome_service/src/configuration/linter/rules.rs +++ b/crates/rome_service/src/configuration/linter/rules.rs @@ -743,6 +743,8 @@ struct NurserySchema { no_empty_interface: Option, #[doc = "Prevents the wrong usage of the non-null assertion operator (!) in TypeScript files."] no_extra_non_null_assertion: Option, + #[doc = "Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. While not technically an error, extra semicolons can cause confusion when reading code."] + no_extra_semicolons: Option, #[doc = "Check that the scope attribute is only used on th elements."] no_header_scope: Option, #[doc = "Prevents the incorrect use of super() inside classes. It also checks whether a call super() is missing from classes that extends other constructors."] @@ -807,6 +809,7 @@ impl Nursery { "noDuplicateObjectKeys", "noEmptyInterface", "noExtraNonNullAssertion", + "noExtraSemicolons", "noHeaderScope", "noInvalidConstructorSuper", "noNonNullAssertion", @@ -821,7 +824,6 @@ impl Nursery { "noVar", "noVoidTypeReturn", "noWith", - "noExtraSemicolons", "useAriaPropTypes", "useAriaPropsForRole", "useCamelCase", @@ -844,6 +846,7 @@ impl Nursery { "noDuplicateObjectKeys", "noEmptyInterface", "noExtraNonNullAssertion", + "noExtraSemicolons", "noHeaderScope", "noInvalidConstructorSuper", "noRedundantAlt", @@ -854,7 +857,6 @@ impl Nursery { "noVar", "noVoidTypeReturn", "noWith", - "noExtraSemicolons", "useAriaPropsForRole", "useConst", "useDefaultParameterLast", @@ -876,21 +878,21 @@ impl Nursery { RuleFilter::Rule("nursery", Self::CATEGORY_RULES[10]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[11]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[12]), - RuleFilter::Rule("nursery", Self::CATEGORY_RULES[14]), - RuleFilter::Rule("nursery", Self::CATEGORY_RULES[17]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[15]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[18]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[19]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[20]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[21]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[22]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[23]), - RuleFilter::Rule("nursery", Self::CATEGORY_RULES[25]), - RuleFilter::Rule("nursery", Self::CATEGORY_RULES[27]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[24]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[26]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[28]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[29]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[30]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[31]), - RuleFilter::Rule("nursery", Self::CATEGORY_RULES[34]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[32]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[35]), ]; pub(crate) fn is_recommended(&self) -> bool { !matches!(self.recommended, Some(false)) } pub(crate) fn get_enabled_rules(&self) -> IndexSet { diff --git a/editors/vscode/configuration_schema.json b/editors/vscode/configuration_schema.json index ee247f404e2..4f683f156b2 100644 --- a/editors/vscode/configuration_schema.json +++ b/editors/vscode/configuration_schema.json @@ -687,6 +687,17 @@ } ] }, + "noExtraSemicolons": { + "description": "Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. While not technically an error, extra semicolons can cause confusion when reading code.", + "anyOf": [ + { + "$ref": "#/definitions/RuleConfiguration" + }, + { + "type": "null" + } + ] + }, "noHeaderScope": { "description": "Check that the scope attribute is only used on th elements.", "anyOf": [ diff --git a/npm/backend-jsonrpc/src/workspace.ts b/npm/backend-jsonrpc/src/workspace.ts index 4745c7d1029..5031c67706d 100644 --- a/npm/backend-jsonrpc/src/workspace.ts +++ b/npm/backend-jsonrpc/src/workspace.ts @@ -325,6 +325,10 @@ export interface Nursery { * Prevents the wrong usage of the non-null assertion operator (!) in TypeScript files. */ noExtraNonNullAssertion?: RuleConfiguration; + /** + * Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. While not technically an error, extra semicolons can cause confusion when reading code. + */ + noExtraSemicolons?: RuleConfiguration; /** * Check that the scope attribute is only used on th elements. */ @@ -381,10 +385,6 @@ export interface Nursery { * Disallow with statements in non-strict contexts. */ noWith?: RuleConfiguration; - /** - * Disallow unnecessary semicolons. - */ - noExtraSemicolons?: RuleConfiguration; /** * It enables the recommended rules for this group */ diff --git a/npm/rome/configuration_schema.json b/npm/rome/configuration_schema.json index 432c3c51fb5..4f683f156b2 100644 --- a/npm/rome/configuration_schema.json +++ b/npm/rome/configuration_schema.json @@ -687,6 +687,17 @@ } ] }, + "noExtraSemicolons": { + "description": "Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. While not technically an error, extra semicolons can cause confusion when reading code.", + "anyOf": [ + { + "$ref": "#/definitions/RuleConfiguration" + }, + { + "type": "null" + } + ] + }, "noHeaderScope": { "description": "Check that the scope attribute is only used on th elements.", "anyOf": [ @@ -841,17 +852,6 @@ } ] }, - "noExtraSemicolons": { - "description": "Disallow unnecessary semicolons.", - "anyOf": [ - { - "$ref": "#/definitions/RuleConfiguration" - }, - { - "type": "null" - } - ] - }, "recommended": { "description": "It enables the recommended rules for this group", "type": [ diff --git a/website/src/pages/lint/rules/index.mdx b/website/src/pages/lint/rules/index.mdx index fe63d04c5e6..6a5903d0cb8 100644 --- a/website/src/pages/lint/rules/index.mdx +++ b/website/src/pages/lint/rules/index.mdx @@ -535,6 +535,13 @@ Disallow the declaration of empty interfaces. Prevents the wrong usage of the non-null assertion operator (!) in TypeScript files.
+

+ noExtraSemicolons +

+Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. +While not technically an error, extra semicolons can cause confusion when reading code. +
+

noHeaderScope

diff --git a/website/src/pages/lint/rules/noExtraSemicolons.md b/website/src/pages/lint/rules/noExtraSemicolons.md new file mode 100644 index 00000000000..a4f52111d3c --- /dev/null +++ b/website/src/pages/lint/rules/noExtraSemicolons.md @@ -0,0 +1,200 @@ +--- +title: Lint Rule noExtraSemicolons +parent: lint/rules/index +--- + +# noExtraSemicolons (since v12.0.0) + +Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. +While not technically an error, extra semicolons can cause confusion when reading code. + +This rule disallows unnecessary semicolons. + +## Examples + +### Invalid + +```jsx + const x = 5;; +``` + +
nursery/noExtraSemicolons.js:1:15 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+  > 1 │   const x = 5;;
+                 ^
+    2 │ 
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    1 │ ··const·x·=·5;;
+                -
+
+ +```jsx + function buzz() { + const x = 10;; + } +``` + +
nursery/noExtraSemicolons.js:2:19 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+    1 │  function buzz() {
+  > 2 │      const x = 10;;
+                     ^
+    3 │  }
+    4 │ 
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    2 │ ·····const·x·=·10;;
+                    -
+
+ +```jsx + function foo() { + // code + }; +``` + +
nursery/noExtraSemicolons.js:3:4 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+    1 │   function foo() {
+    2 │     // code
+  > 3 │   };
+      ^
+    4 │ 
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    3 │ ··};
+     -
+
+ +```jsx + class C { + field;; + + method() { + // code + } + + static { + // code + } + } +``` + +
nursery/noExtraSemicolons.js:2:13 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+    1 │     class C {
+  > 2 │       field;;
+               ^
+    3 │ 
+    4 │       method() {
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    2 │ ······field;;
+              -
+
+ +```jsx + class C { + field; + + method() { + // code + }; + + static { + // code + } + } +``` + +
nursery/noExtraSemicolons.js:6:7 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+    4 │      method() {
+    5 │          // code
+  > 6 │      };
+         ^
+    7 │ 
+    8 │      static {
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    6 │ ·····};
+        -
+
+ +```jsx + class C { + field; + + method() { + // code + } + + static { + // code + }; + } +``` + +
nursery/noExtraSemicolons.js:10:7 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+     8 │      static {
+     9 │          // code
+  > 10 │      };
+          ^
+    11 │    }
+    12 │ 
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    10 │ ·····};
+        -
+
+ +```jsx + class C { + field; + + method() { + // code + } + + static { + // code + } + }; +``` + +
nursery/noExtraSemicolons.js:11:5 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+     9 │          // code
+    10 │      }
+  > 11 │    };
+        ^
+    12 │ 
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    11 │ ···};
+      -
+
+ From b1817a7ee39bae4e80875edaeacdae4ad8f28fc4 Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 02:39:53 -0300 Subject: [PATCH 03/14] fix(rome_js_analyzer): changed the name of cases --- .../analyzers/nursery/no_extra_semicolons.rs | 4 +- ...invalid.js => noExtraSemicolonsInvalid.js} | 0 .../noExtraSemicolonsInvalid.js.snap | 399 ++++++++++++++++++ .../{valid.js => noExtraSemicolonsValid.js} | 0 .../noExtraSemicolonsValid.js.snap | 81 ++++ crates/rome_js_unicode_table/src/tables.rs | 8 +- 6 files changed, 484 insertions(+), 8 deletions(-) rename crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/{invalid.js => noExtraSemicolonsInvalid.js} (100%) create mode 100644 crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsInvalid.js.snap rename crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/{valid.js => noExtraSemicolonsValid.js} (100%) create mode 100644 crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js.snap diff --git a/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs b/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs index cf58380f77e..5db45d1d990 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs @@ -1,5 +1,5 @@ use rome_analyze::context::RuleContext; -use rome_analyze::{declare_rule, ActionCategory, Ast, Rule, RuleAction, RuleDiagnostic}; +use rome_analyze::{declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_syntax::{JsEmptyClassMember, JsEmptyStatement, JsSyntaxKind}; @@ -158,7 +158,7 @@ impl Rule for NoExtraSemicolons { mutation.remove_node(stmt.clone()); } } - Some(RuleAction { + Some(JsRuleAction { category: ActionCategory::QuickFix, applicability: Applicability::MaybeIncorrect, message: markup! { "Remove unnecessary semicolon." }.to_owned(), diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsInvalid.js similarity index 100% rename from crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js rename to crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsInvalid.js diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsInvalid.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsInvalid.js.snap new file mode 100644 index 00000000000..acdf07bf735 --- /dev/null +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsInvalid.js.snap @@ -0,0 +1,399 @@ +--- +source: crates/rome_js_analyze/tests/spec_tests.rs +expression: noExtraSemicolonsInvalid.js +--- +# Input +```js +// invalid + +const x = 10; +if (x > 5) { + x = 5; +}; + +while(true);; + +while(true) {}; + +loop1: +for (let i = 0; i < 5; i++) { + str = str + i;; +}; + +loop1: +for (let i = 0; i < 5; i++) { + if (i === 1) { + continue loop1; + } + str = str + i; +}; + +function baz() { ; } + +function buzz() { + const x = 10;; +} + +for(;true;);; + +for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + +const x = 5;; + +function foo() { + // code +}; + +class C { + field;; + + method() { + // code + } + + static { + // code + } +} + +class C { + field; + + method() { + // code + }; + + static { + // code + } +} + +class C { + field; + + method() { + // code + } + + static { + // code + }; +} + +class C { + field; + + method() { + // code + } + + static { + // code + } +}; + +``` + +# Diagnostics +``` +noExtraSemicolonsInvalid.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 4 │ if (x > 5) { + 5 │ x = 5; + > 6 │ }; + │ ^ + 7 │ + 8 │ while(true);; + + i Suggested fix: Remove unnecessary semicolon. + + 6 │ };␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:8:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 6 │ }; + 7 │ + > 8 │ while(true);; + │ ^ + 9 │ + 10 │ while(true) {}; + + i Suggested fix: Remove unnecessary semicolon. + + 8 │ while(true);;␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:10:15 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 8 │ while(true);; + 9 │ + > 10 │ while(true) {}; + │ ^ + 11 │ + 12 │ loop1: + + i Suggested fix: Remove unnecessary semicolon. + + 10 │ while(true)·{};␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:14:17 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 12 │ loop1: + 13 │ for (let i = 0; i < 5; i++) { + > 14 │ str = str + i;; + │ ^ + 15 │ }; + 16 │ + + i Suggested fix: Remove unnecessary semicolon. + + 14 │ ··str·=·str·+·i;;␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:15:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 13 │ for (let i = 0; i < 5; i++) { + 14 │ str = str + i;; + > 15 │ }; + │ ^ + 16 │ + 17 │ loop1: + + i Suggested fix: Remove unnecessary semicolon. + + 15 │ };␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:23:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 21 │ } + 22 │ str = str + i; + > 23 │ }; + │ ^ + 24 │ + 25 │ function baz() { ; } + + i Suggested fix: Remove unnecessary semicolon. + + 23 │ };␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:25:18 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 23 │ }; + 24 │ + > 25 │ function baz() { ; } + │ ^ + 26 │ + 27 │ function buzz() { + + i Suggested fix: Remove unnecessary semicolon. + + 25 │ function·baz()·{·;·}␍ + │ -- + +``` + +``` +noExtraSemicolonsInvalid.js:28:16 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 27 │ function buzz() { + > 28 │ const x = 10;; + │ ^ + 29 │ } + 30 │ + + i Suggested fix: Remove unnecessary semicolon. + + 28 │ ··const·x·=·10;;␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:31:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 29 │ } + 30 │ + > 31 │ for(;true;);; + │ ^ + 32 │ + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + + i Suggested fix: Remove unnecessary semicolon. + + 31 │ for(;true;);;␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:33:61 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 31 │ for(;true;);; + 32 │ + > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ ^ + 34 │ + 35 │ const x = 5;; + + i Suggested fix: Remove unnecessary semicolon. + + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);;␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:35:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + 34 │ + > 35 │ const x = 5;; + │ ^ + 36 │ + 37 │ function foo() { + + i Suggested fix: Remove unnecessary semicolon. + + 35 │ const·x·=·5;;␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:39:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 37 │ function foo() { + 38 │ // code + > 39 │ }; + │ ^ + 40 │ + 41 │ class C { + + i Suggested fix: Remove unnecessary semicolon. + + 39 │ };␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:42:11 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 41 │ class C { + > 42 │ field;; + │ ^ + 43 │ + 44 │ method() { + + i Suggested fix: Remove unnecessary semicolon. + + 42 │ ····field;;␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:58:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 56 │ method() { + 57 │ // code + > 58 │ }; + │ ^ + 59 │ + 60 │ static { + + i Suggested fix: Remove unnecessary semicolon. + + 58 │ ····};␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:74:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 72 │ static { + 73 │ // code + > 74 │ }; + │ ^ + 75 │ } + 76 │ + + i Suggested fix: Remove unnecessary semicolon. + + 74 │ ····};␍ + │ - + +``` + +``` +noExtraSemicolonsInvalid.js:87:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 85 │ // code + 86 │ } + > 87 │ }; + │ ^ + 88 │ + + i Suggested fix: Remove unnecessary semicolon. + + 87 │ };␍ + │ - + +``` + + diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js similarity index 100% rename from crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js rename to crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js.snap new file mode 100644 index 00000000000..cda740bd220 --- /dev/null +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js.snap @@ -0,0 +1,81 @@ +--- +source: crates/rome_js_analyze/tests/spec_tests.rs +expression: noExtraSemicolonsValid.js +--- +# Input +```js +// valid + +const x = 10; +if (x > 5) { + x = 5; +}; + +while(true); + +while(true) {} + +loop1: +for (let i = 0; i < 5; i++) { + str = str + i; +} + +loop1: +for (let i = 0; i < 5; i++) { + if (i === 1) { + continue loop1; + } + str = str + i; +} + +function baz() {} + +function buzz() { + const x = 10; +} + +for(;true;); + +for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + +const x = 5; + +const foo = function() { + // code +}; + +class C { + field; + + method() { + // code + } + + static { + // code + } +} + +``` + +# Diagnostics +``` +noExtraSemicolonsValid.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 4 │ if (x > 5) { + 5 │ x = 5; + > 6 │ }; + │ ^ + 7 │ + 8 │ while(true); + + i Suggested fix: Remove unnecessary semicolon. + + 6 │ };␍ + │ - + +``` + + diff --git a/crates/rome_js_unicode_table/src/tables.rs b/crates/rome_js_unicode_table/src/tables.rs index 7f67057597c..eb783866c93 100644 --- a/crates/rome_js_unicode_table/src/tables.rs +++ b/crates/rome_js_unicode_table/src/tables.rs @@ -787,9 +787,7 @@ pub mod derived_property { ('\u{31350}', '\u{323af}'), ('\u{e0100}', '\u{e01ef}'), ]; - pub fn ID_Continue(c: char) -> bool { - super::bsearch_range_table(c, ID_Continue_table) - } + pub fn ID_Continue(c: char) -> bool { super::bsearch_range_table(c, ID_Continue_table) } pub const ID_Start_table: &[(char, char)] = &[ ('A', 'Z'), ('a', 'z'), @@ -1451,7 +1449,5 @@ pub mod derived_property { ('𰀀', '𱍊'), ('\u{31350}', '\u{323af}'), ]; - pub fn ID_Start(c: char) -> bool { - super::bsearch_range_table(c, ID_Start_table) - } + pub fn ID_Start(c: char) -> bool { super::bsearch_range_table(c, ID_Start_table) } } From 4e332377797dc473e2893c585f59a17691ed17ea Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 02:45:28 -0300 Subject: [PATCH 04/14] feat(rome_js_analayzer): additional resource to rule --- crates/rome_js_unicode_table/src/tables.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/rome_js_unicode_table/src/tables.rs b/crates/rome_js_unicode_table/src/tables.rs index eb783866c93..7f67057597c 100644 --- a/crates/rome_js_unicode_table/src/tables.rs +++ b/crates/rome_js_unicode_table/src/tables.rs @@ -787,7 +787,9 @@ pub mod derived_property { ('\u{31350}', '\u{323af}'), ('\u{e0100}', '\u{e01ef}'), ]; - pub fn ID_Continue(c: char) -> bool { super::bsearch_range_table(c, ID_Continue_table) } + pub fn ID_Continue(c: char) -> bool { + super::bsearch_range_table(c, ID_Continue_table) + } pub const ID_Start_table: &[(char, char)] = &[ ('A', 'Z'), ('a', 'z'), @@ -1449,5 +1451,7 @@ pub mod derived_property { ('𰀀', '𱍊'), ('\u{31350}', '\u{323af}'), ]; - pub fn ID_Start(c: char) -> bool { super::bsearch_range_table(c, ID_Start_table) } + pub fn ID_Start(c: char) -> bool { + super::bsearch_range_table(c, ID_Start_table) + } } From f32b57a052e27a9358e69f387d5ae6d11cb1f957 Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 03:48:36 -0300 Subject: [PATCH 05/14] feat(rome_js_analyzer): removed old snapshots --- .../nursery/noExtraSemicolons/invalid.js.snap | 399 ------------------ .../nursery/noExtraSemicolons/valid.js.snap | 81 ---- crates/rome_js_unicode_table/src/tables.rs | 8 +- 3 files changed, 2 insertions(+), 486 deletions(-) delete mode 100644 crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js.snap delete mode 100644 crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js.snap diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js.snap deleted file mode 100644 index f648bc5ca71..00000000000 --- a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/invalid.js.snap +++ /dev/null @@ -1,399 +0,0 @@ ---- -source: crates/rome_js_analyze/tests/spec_tests.rs -expression: invalid.js ---- -# Input -```js -// invalid - -const x = 10; -if (x > 5) { - x = 5; -}; - -while(true);; - -while(true) {}; - -loop1: -for (let i = 0; i < 5; i++) { - str = str + i;; -}; - -loop1: -for (let i = 0; i < 5; i++) { - if (i === 1) { - continue loop1; - } - str = str + i; -}; - -function baz() { ; } - -function buzz() { - const x = 10;; -} - -for(;true;);; - -for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - -const x = 5;; - -function foo() { - // code -}; - -class C { - field;; - - method() { - // code - } - - static { - // code - } -} - -class C { - field; - - method() { - // code - }; - - static { - // code - } -} - -class C { - field; - - method() { - // code - } - - static { - // code - }; -} - -class C { - field; - - method() { - // code - } - - static { - // code - } -}; - -``` - -# Diagnostics -``` -invalid.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 4 │ if (x > 5) { - 5 │ x = 5; - > 6 │ }; - │ ^ - 7 │ - 8 │ while(true);; - - i Suggested fix: Remove unnecessary semicolon. - - 6 │ };␍ - │ - - -``` - -``` -invalid.js:8:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 6 │ }; - 7 │ - > 8 │ while(true);; - │ ^ - 9 │ - 10 │ while(true) {}; - - i Suggested fix: Remove unnecessary semicolon. - - 8 │ while(true);;␍ - │ - - -``` - -``` -invalid.js:10:15 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 8 │ while(true);; - 9 │ - > 10 │ while(true) {}; - │ ^ - 11 │ - 12 │ loop1: - - i Suggested fix: Remove unnecessary semicolon. - - 10 │ while(true)·{};␍ - │ - - -``` - -``` -invalid.js:14:17 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 12 │ loop1: - 13 │ for (let i = 0; i < 5; i++) { - > 14 │ str = str + i;; - │ ^ - 15 │ }; - 16 │ - - i Suggested fix: Remove unnecessary semicolon. - - 14 │ ··str·=·str·+·i;;␍ - │ - - -``` - -``` -invalid.js:15:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 13 │ for (let i = 0; i < 5; i++) { - 14 │ str = str + i;; - > 15 │ }; - │ ^ - 16 │ - 17 │ loop1: - - i Suggested fix: Remove unnecessary semicolon. - - 15 │ };␍ - │ - - -``` - -``` -invalid.js:23:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 21 │ } - 22 │ str = str + i; - > 23 │ }; - │ ^ - 24 │ - 25 │ function baz() { ; } - - i Suggested fix: Remove unnecessary semicolon. - - 23 │ };␍ - │ - - -``` - -``` -invalid.js:25:18 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 23 │ }; - 24 │ - > 25 │ function baz() { ; } - │ ^ - 26 │ - 27 │ function buzz() { - - i Suggested fix: Remove unnecessary semicolon. - - 25 │ function·baz()·{·;·}␍ - │ -- - -``` - -``` -invalid.js:28:16 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 27 │ function buzz() { - > 28 │ const x = 10;; - │ ^ - 29 │ } - 30 │ - - i Suggested fix: Remove unnecessary semicolon. - - 28 │ ··const·x·=·10;;␍ - │ - - -``` - -``` -invalid.js:31:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 29 │ } - 30 │ - > 31 │ for(;true;);; - │ ^ - 32 │ - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - - i Suggested fix: Remove unnecessary semicolon. - - 31 │ for(;true;);;␍ - │ - - -``` - -``` -invalid.js:33:61 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 31 │ for(;true;);; - 32 │ - > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ ^ - 34 │ - 35 │ const x = 5;; - - i Suggested fix: Remove unnecessary semicolon. - - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);;␍ - │ - - -``` - -``` -invalid.js:35:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - 34 │ - > 35 │ const x = 5;; - │ ^ - 36 │ - 37 │ function foo() { - - i Suggested fix: Remove unnecessary semicolon. - - 35 │ const·x·=·5;;␍ - │ - - -``` - -``` -invalid.js:39:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 37 │ function foo() { - 38 │ // code - > 39 │ }; - │ ^ - 40 │ - 41 │ class C { - - i Suggested fix: Remove unnecessary semicolon. - - 39 │ };␍ - │ - - -``` - -``` -invalid.js:42:11 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 41 │ class C { - > 42 │ field;; - │ ^ - 43 │ - 44 │ method() { - - i Suggested fix: Remove unnecessary semicolon. - - 42 │ ····field;;␍ - │ - - -``` - -``` -invalid.js:58:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 56 │ method() { - 57 │ // code - > 58 │ }; - │ ^ - 59 │ - 60 │ static { - - i Suggested fix: Remove unnecessary semicolon. - - 58 │ ····};␍ - │ - - -``` - -``` -invalid.js:74:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 72 │ static { - 73 │ // code - > 74 │ }; - │ ^ - 75 │ } - 76 │ - - i Suggested fix: Remove unnecessary semicolon. - - 74 │ ····};␍ - │ - - -``` - -``` -invalid.js:87:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 85 │ // code - 86 │ } - > 87 │ }; - │ ^ - 88 │ - - i Suggested fix: Remove unnecessary semicolon. - - 87 │ };␍ - │ - - -``` - - diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js.snap deleted file mode 100644 index ccc2fb0224c..00000000000 --- a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/valid.js.snap +++ /dev/null @@ -1,81 +0,0 @@ ---- -source: crates/rome_js_analyze/tests/spec_tests.rs -expression: valid.js ---- -# Input -```js -// valid - -const x = 10; -if (x > 5) { - x = 5; -}; - -while(true); - -while(true) {} - -loop1: -for (let i = 0; i < 5; i++) { - str = str + i; -} - -loop1: -for (let i = 0; i < 5; i++) { - if (i === 1) { - continue loop1; - } - str = str + i; -} - -function baz() {} - -function buzz() { - const x = 10; -} - -for(;true;); - -for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - -const x = 5; - -const foo = function() { - // code -}; - -class C { - field; - - method() { - // code - } - - static { - // code - } -} - -``` - -# Diagnostics -``` -valid.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 4 │ if (x > 5) { - 5 │ x = 5; - > 6 │ }; - │ ^ - 7 │ - 8 │ while(true); - - i Suggested fix: Remove unnecessary semicolon. - - 6 │ };␍ - │ - - -``` - - diff --git a/crates/rome_js_unicode_table/src/tables.rs b/crates/rome_js_unicode_table/src/tables.rs index 7f67057597c..eb783866c93 100644 --- a/crates/rome_js_unicode_table/src/tables.rs +++ b/crates/rome_js_unicode_table/src/tables.rs @@ -787,9 +787,7 @@ pub mod derived_property { ('\u{31350}', '\u{323af}'), ('\u{e0100}', '\u{e01ef}'), ]; - pub fn ID_Continue(c: char) -> bool { - super::bsearch_range_table(c, ID_Continue_table) - } + pub fn ID_Continue(c: char) -> bool { super::bsearch_range_table(c, ID_Continue_table) } pub const ID_Start_table: &[(char, char)] = &[ ('A', 'Z'), ('a', 'z'), @@ -1451,7 +1449,5 @@ pub mod derived_property { ('𰀀', '𱍊'), ('\u{31350}', '\u{323af}'), ]; - pub fn ID_Start(c: char) -> bool { - super::bsearch_range_table(c, ID_Start_table) - } + pub fn ID_Start(c: char) -> bool { super::bsearch_range_table(c, ID_Start_table) } } From 7adcbb985a1ab35d5830c85f9e40be7ee185f3cc Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 03:55:28 -0300 Subject: [PATCH 06/14] feat(rome_js_analayzer): changed to one file --- ...icolonsInvalid.js => noExtraSemicolons.js} | 52 +++++++++ ...alid.js.snap => noExtraSemicolons.js.snap} | 106 +++++++++++++++--- .../noExtraSemicolonsValid.js | 51 --------- .../noExtraSemicolonsValid.js.snap | 81 ------------- 4 files changed, 141 insertions(+), 149 deletions(-) rename crates/rome_js_analyze/tests/specs/nursery/{noExtraSemicolons/noExtraSemicolonsInvalid.js => noExtraSemicolons.js} (61%) rename crates/rome_js_analyze/tests/specs/nursery/{noExtraSemicolons/noExtraSemicolonsInvalid.js.snap => noExtraSemicolons.js.snap} (59%) delete mode 100644 crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js delete mode 100644 crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js.snap diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsInvalid.js b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js similarity index 61% rename from crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsInvalid.js rename to crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js index 687522e7b46..466e9db1e1a 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsInvalid.js +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js @@ -85,3 +85,55 @@ class C { // code } }; + +// valid + +const x = 10; +if (x > 5) { + x = 5; +}; + +while(true); + +while(true) {} + +loop1: +for (let i = 0; i < 5; i++) { + str = str + i; +} + +loop1: +for (let i = 0; i < 5; i++) { + if (i === 1) { + continue loop1; + } + str = str + i; +} + +function baz() {} + +function buzz() { + const x = 10; +} + +for(;true;); + +for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + +const x = 5; + +const foo = function() { + // code +}; + +class C { + field; + + method() { + // code + } + + static { + // code + } +} diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsInvalid.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap similarity index 59% rename from crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsInvalid.js.snap rename to crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap index acdf07bf735..fc67ab06a8e 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsInvalid.js.snap +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap @@ -1,6 +1,6 @@ --- source: crates/rome_js_analyze/tests/spec_tests.rs -expression: noExtraSemicolonsInvalid.js +expression: noExtraSemicolons.js --- # Input ```js @@ -92,11 +92,63 @@ class C { } }; +// valid + +const x = 10; +if (x > 5) { + x = 5; +}; + +while(true); + +while(true) {} + +loop1: +for (let i = 0; i < 5; i++) { + str = str + i; +} + +loop1: +for (let i = 0; i < 5; i++) { + if (i === 1) { + continue loop1; + } + str = str + i; +} + +function baz() {} + +function buzz() { + const x = 10; +} + +for(;true;); + +for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + +const x = 5; + +const foo = function() { + // code +}; + +class C { + field; + + method() { + // code + } + + static { + // code + } +} + ``` # Diagnostics ``` -noExtraSemicolonsInvalid.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -115,7 +167,7 @@ noExtraSemicolonsInvalid.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━ ``` ``` -noExtraSemicolonsInvalid.js:8:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:8:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -134,7 +186,7 @@ noExtraSemicolonsInvalid.js:8:13 lint/nursery/noExtraSemicolons FIXABLE ━━ ``` ``` -noExtraSemicolonsInvalid.js:10:15 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:10:15 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -153,7 +205,7 @@ noExtraSemicolonsInvalid.js:10:15 lint/nursery/noExtraSemicolons FIXABLE ━ ``` ``` -noExtraSemicolonsInvalid.js:14:17 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:14:17 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -172,7 +224,7 @@ noExtraSemicolonsInvalid.js:14:17 lint/nursery/noExtraSemicolons FIXABLE ━ ``` ``` -noExtraSemicolonsInvalid.js:15:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:15:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -191,7 +243,7 @@ noExtraSemicolonsInvalid.js:15:2 lint/nursery/noExtraSemicolons FIXABLE ━━ ``` ``` -noExtraSemicolonsInvalid.js:23:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:23:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -210,7 +262,7 @@ noExtraSemicolonsInvalid.js:23:2 lint/nursery/noExtraSemicolons FIXABLE ━━ ``` ``` -noExtraSemicolonsInvalid.js:25:18 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:25:18 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -229,7 +281,7 @@ noExtraSemicolonsInvalid.js:25:18 lint/nursery/noExtraSemicolons FIXABLE ━ ``` ``` -noExtraSemicolonsInvalid.js:28:16 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:28:16 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -247,7 +299,7 @@ noExtraSemicolonsInvalid.js:28:16 lint/nursery/noExtraSemicolons FIXABLE ━ ``` ``` -noExtraSemicolonsInvalid.js:31:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:31:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -266,7 +318,7 @@ noExtraSemicolonsInvalid.js:31:13 lint/nursery/noExtraSemicolons FIXABLE ━ ``` ``` -noExtraSemicolonsInvalid.js:33:61 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:33:61 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -285,7 +337,7 @@ noExtraSemicolonsInvalid.js:33:61 lint/nursery/noExtraSemicolons FIXABLE ━ ``` ``` -noExtraSemicolonsInvalid.js:35:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:35:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -304,7 +356,7 @@ noExtraSemicolonsInvalid.js:35:13 lint/nursery/noExtraSemicolons FIXABLE ━ ``` ``` -noExtraSemicolonsInvalid.js:39:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:39:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -323,7 +375,7 @@ noExtraSemicolonsInvalid.js:39:2 lint/nursery/noExtraSemicolons FIXABLE ━━ ``` ``` -noExtraSemicolonsInvalid.js:42:11 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:42:11 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -341,7 +393,7 @@ noExtraSemicolonsInvalid.js:42:11 lint/nursery/noExtraSemicolons FIXABLE ━ ``` ``` -noExtraSemicolonsInvalid.js:58:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:58:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -360,7 +412,7 @@ noExtraSemicolonsInvalid.js:58:6 lint/nursery/noExtraSemicolons FIXABLE ━━ ``` ``` -noExtraSemicolonsInvalid.js:74:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:74:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -379,7 +431,7 @@ noExtraSemicolonsInvalid.js:74:6 lint/nursery/noExtraSemicolons FIXABLE ━━ ``` ``` -noExtraSemicolonsInvalid.js:87:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:87:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. @@ -388,6 +440,7 @@ noExtraSemicolonsInvalid.js:87:2 lint/nursery/noExtraSemicolons FIXABLE ━━ > 87 │ }; │ ^ 88 │ + 89 │ // valid i Suggested fix: Remove unnecessary semicolon. @@ -396,4 +449,23 @@ noExtraSemicolonsInvalid.js:87:2 lint/nursery/noExtraSemicolons FIXABLE ━━ ``` +``` +noExtraSemicolons.js:94:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Unnecessary semicolon. + + 92 │ if (x > 5) { + 93 │ x = 5; + > 94 │ }; + │ ^ + 95 │ + 96 │ while(true); + + i Suggested fix: Remove unnecessary semicolon. + + 94 │ };␍ + │ - + +``` + diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js deleted file mode 100644 index 5c9eb638ae1..00000000000 --- a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js +++ /dev/null @@ -1,51 +0,0 @@ -// valid - -const x = 10; -if (x > 5) { - x = 5; -}; - -while(true); - -while(true) {} - -loop1: -for (let i = 0; i < 5; i++) { - str = str + i; -} - -loop1: -for (let i = 0; i < 5; i++) { - if (i === 1) { - continue loop1; - } - str = str + i; -} - -function baz() {} - -function buzz() { - const x = 10; -} - -for(;true;); - -for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - -const x = 5; - -const foo = function() { - // code -}; - -class C { - field; - - method() { - // code - } - - static { - // code - } -} diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js.snap deleted file mode 100644 index cda740bd220..00000000000 --- a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons/noExtraSemicolonsValid.js.snap +++ /dev/null @@ -1,81 +0,0 @@ ---- -source: crates/rome_js_analyze/tests/spec_tests.rs -expression: noExtraSemicolonsValid.js ---- -# Input -```js -// valid - -const x = 10; -if (x > 5) { - x = 5; -}; - -while(true); - -while(true) {} - -loop1: -for (let i = 0; i < 5; i++) { - str = str + i; -} - -loop1: -for (let i = 0; i < 5; i++) { - if (i === 1) { - continue loop1; - } - str = str + i; -} - -function baz() {} - -function buzz() { - const x = 10; -} - -for(;true;); - -for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - -const x = 5; - -const foo = function() { - // code -}; - -class C { - field; - - method() { - // code - } - - static { - // code - } -} - -``` - -# Diagnostics -``` -noExtraSemicolonsValid.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! Unnecessary semicolon. - - 4 │ if (x > 5) { - 5 │ x = 5; - > 6 │ }; - │ ^ - 7 │ - 8 │ while(true); - - i Suggested fix: Remove unnecessary semicolon. - - 6 │ };␍ - │ - - -``` - - From e69d180e634aaf3af9994ac616ee426ea3fb2d6b Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 03:59:50 -0300 Subject: [PATCH 07/14] feat(rome_js_analyzer): additional resources for the rule --- crates/rome_js_unicode_table/src/tables.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/rome_js_unicode_table/src/tables.rs b/crates/rome_js_unicode_table/src/tables.rs index eb783866c93..7f67057597c 100644 --- a/crates/rome_js_unicode_table/src/tables.rs +++ b/crates/rome_js_unicode_table/src/tables.rs @@ -787,7 +787,9 @@ pub mod derived_property { ('\u{31350}', '\u{323af}'), ('\u{e0100}', '\u{e01ef}'), ]; - pub fn ID_Continue(c: char) -> bool { super::bsearch_range_table(c, ID_Continue_table) } + pub fn ID_Continue(c: char) -> bool { + super::bsearch_range_table(c, ID_Continue_table) + } pub const ID_Start_table: &[(char, char)] = &[ ('A', 'Z'), ('a', 'z'), @@ -1449,5 +1451,7 @@ pub mod derived_property { ('𰀀', '𱍊'), ('\u{31350}', '\u{323af}'), ]; - pub fn ID_Start(c: char) -> bool { super::bsearch_range_table(c, ID_Start_table) } + pub fn ID_Start(c: char) -> bool { + super::bsearch_range_table(c, ID_Start_table) + } } From 6f35bd5cb96b3d318e31ecf9c43750431edca120 Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 08:35:22 -0300 Subject: [PATCH 08/14] fix(rome_js_analyze): changed EOL kind --- .../tests/specs/nursery/noExtraSemicolons.js | 2 +- .../specs/nursery/noExtraSemicolons.js.snap | 35 +++++++++---------- crates/rome_js_unicode_table/src/tables.rs | 8 ++--- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js index 466e9db1e1a..939d661c1a8 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js @@ -136,4 +136,4 @@ class C { static { // code } -} +} \ No newline at end of file diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap index fc67ab06a8e..fa71231d917 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap @@ -143,7 +143,6 @@ class C { // code } } - ``` # Diagnostics @@ -161,7 +160,7 @@ noExtraSemicolons.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 6 │ };␍ + 6 │ }; │ - ``` @@ -180,7 +179,7 @@ noExtraSemicolons.js:8:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 8 │ while(true);;␍ + 8 │ while(true);; │ - ``` @@ -199,7 +198,7 @@ noExtraSemicolons.js:10:15 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 10 │ while(true)·{};␍ + 10 │ while(true)·{}; │ - ``` @@ -218,7 +217,7 @@ noExtraSemicolons.js:14:17 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 14 │ ··str·=·str·+·i;;␍ + 14 │ ··str·=·str·+·i;; │ - ``` @@ -237,7 +236,7 @@ noExtraSemicolons.js:15:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 15 │ };␍ + 15 │ }; │ - ``` @@ -256,7 +255,7 @@ noExtraSemicolons.js:23:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 23 │ };␍ + 23 │ }; │ - ``` @@ -275,7 +274,7 @@ noExtraSemicolons.js:25:18 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 25 │ function·baz()·{·;·}␍ + 25 │ function·baz()·{·;·} │ -- ``` @@ -293,7 +292,7 @@ noExtraSemicolons.js:28:16 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 28 │ ··const·x·=·10;;␍ + 28 │ ··const·x·=·10;; │ - ``` @@ -312,7 +311,7 @@ noExtraSemicolons.js:31:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 31 │ for(;true;);;␍ + 31 │ for(;true;);; │ - ``` @@ -331,7 +330,7 @@ noExtraSemicolons.js:33:61 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);;␍ + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; │ - ``` @@ -350,7 +349,7 @@ noExtraSemicolons.js:35:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 35 │ const·x·=·5;;␍ + 35 │ const·x·=·5;; │ - ``` @@ -369,7 +368,7 @@ noExtraSemicolons.js:39:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 39 │ };␍ + 39 │ }; │ - ``` @@ -387,7 +386,7 @@ noExtraSemicolons.js:42:11 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 42 │ ····field;;␍ + 42 │ ····field;; │ - ``` @@ -406,7 +405,7 @@ noExtraSemicolons.js:58:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 58 │ ····};␍ + 58 │ ····}; │ - ``` @@ -425,7 +424,7 @@ noExtraSemicolons.js:74:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 74 │ ····};␍ + 74 │ ····}; │ - ``` @@ -444,7 +443,7 @@ noExtraSemicolons.js:87:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 87 │ };␍ + 87 │ }; │ - ``` @@ -463,7 +462,7 @@ noExtraSemicolons.js:94:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━ i Suggested fix: Remove unnecessary semicolon. - 94 │ };␍ + 94 │ }; │ - ``` diff --git a/crates/rome_js_unicode_table/src/tables.rs b/crates/rome_js_unicode_table/src/tables.rs index 7f67057597c..eb783866c93 100644 --- a/crates/rome_js_unicode_table/src/tables.rs +++ b/crates/rome_js_unicode_table/src/tables.rs @@ -787,9 +787,7 @@ pub mod derived_property { ('\u{31350}', '\u{323af}'), ('\u{e0100}', '\u{e01ef}'), ]; - pub fn ID_Continue(c: char) -> bool { - super::bsearch_range_table(c, ID_Continue_table) - } + pub fn ID_Continue(c: char) -> bool { super::bsearch_range_table(c, ID_Continue_table) } pub const ID_Start_table: &[(char, char)] = &[ ('A', 'Z'), ('a', 'z'), @@ -1451,7 +1449,5 @@ pub mod derived_property { ('𰀀', '𱍊'), ('\u{31350}', '\u{323af}'), ]; - pub fn ID_Start(c: char) -> bool { - super::bsearch_range_table(c, ID_Start_table) - } + pub fn ID_Start(c: char) -> bool { super::bsearch_range_table(c, ID_Start_table) } } From 9473ce87b206f482347ad579e8fc9fb97b30ad54 Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 08:39:45 -0300 Subject: [PATCH 09/14] feat(rome_js_analyzer): generated additional resource --- crates/rome_js_unicode_table/src/tables.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/rome_js_unicode_table/src/tables.rs b/crates/rome_js_unicode_table/src/tables.rs index eb783866c93..7f67057597c 100644 --- a/crates/rome_js_unicode_table/src/tables.rs +++ b/crates/rome_js_unicode_table/src/tables.rs @@ -787,7 +787,9 @@ pub mod derived_property { ('\u{31350}', '\u{323af}'), ('\u{e0100}', '\u{e01ef}'), ]; - pub fn ID_Continue(c: char) -> bool { super::bsearch_range_table(c, ID_Continue_table) } + pub fn ID_Continue(c: char) -> bool { + super::bsearch_range_table(c, ID_Continue_table) + } pub const ID_Start_table: &[(char, char)] = &[ ('A', 'Z'), ('a', 'z'), @@ -1449,5 +1451,7 @@ pub mod derived_property { ('𰀀', '𱍊'), ('\u{31350}', '\u{323af}'), ]; - pub fn ID_Start(c: char) -> bool { super::bsearch_range_table(c, ID_Start_table) } + pub fn ID_Start(c: char) -> bool { + super::bsearch_range_table(c, ID_Start_table) + } } From d7492a59d243e26a12322fc5615a8a861a365e51 Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 12:44:15 -0300 Subject: [PATCH 10/14] refactor(rome_js_analyzer): added review suggestions added one check of list removed duplicated enums added code block for invalid and valid cases --- .../analyzers/nursery/no_extra_semicolons.rs | 30 +- .../tests/specs/nursery/noExtraSemicolons.js | 8 +- .../specs/nursery/noExtraSemicolons.js.snap | 311 +++++++++--------- 3 files changed, 171 insertions(+), 178 deletions(-) diff --git a/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs b/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs index 5db45d1d990..f188c44ce22 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs @@ -2,7 +2,7 @@ use rome_analyze::context::RuleContext; use rome_analyze::{declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use rome_console::markup; use rome_diagnostics::Applicability; -use rome_js_syntax::{JsEmptyClassMember, JsEmptyStatement, JsSyntaxKind}; +use rome_js_syntax::{JsEmptyClassMember, JsEmptyStatement}; use rome_rowan::{declare_node_union, AstNode, BatchMutationExt}; @@ -102,7 +102,7 @@ declare_node_union! { impl Rule for NoExtraSemicolons { type Query = Ast; - type State = AnyJsExtraSemicolonOptionType; + type State = AnyJsExtraSemicolon; type Signals = Option; type Options = (); @@ -112,19 +112,8 @@ impl Rule for NoExtraSemicolons { match node { AnyJsExtraSemicolon::JsEmptyStatement(stmt) => { let parent = stmt.syntax().parent()?; - let allowed_parent_kinds = vec![ - JsSyntaxKind::JS_FOR_STATEMENT, - JsSyntaxKind::JS_FOR_IN_STATEMENT, - JsSyntaxKind::JS_FOR_OF_STATEMENT, - JsSyntaxKind::JS_WHILE_STATEMENT, - JsSyntaxKind::JS_DO_WHILE_STATEMENT, - JsSyntaxKind::JS_IF_STATEMENT, - JsSyntaxKind::JS_LABELED_STATEMENT, - JsSyntaxKind::JS_WITH_STATEMENT, - ]; - let has_allowed_parent = allowed_parent_kinds.contains(&parent.kind()); - if !has_allowed_parent { - Some(AnyJsExtraSemicolonOptionType::JsEmptyStatement( + if !parent.kind().is_list() { + Some(AnyJsExtraSemicolon::JsEmptyStatement( stmt.clone(), )) } else { @@ -132,7 +121,7 @@ impl Rule for NoExtraSemicolons { } } AnyJsExtraSemicolon::JsEmptyClassMember(stmt) => Some( - AnyJsExtraSemicolonOptionType::JsEmptyClassMember(stmt.clone()), + AnyJsExtraSemicolon::JsEmptyClassMember(stmt.clone()), ), } } @@ -151,10 +140,10 @@ impl Rule for NoExtraSemicolons { fn action(ctx: &RuleContext, node_replace: &Self::State) -> Option { let mut mutation = ctx.root().begin(); match node_replace { - AnyJsExtraSemicolonOptionType::JsEmptyStatement(stmt) => { + AnyJsExtraSemicolon::JsEmptyStatement(stmt) => { mutation.remove_node(stmt.clone()); } - AnyJsExtraSemicolonOptionType::JsEmptyClassMember(stmt) => { + AnyJsExtraSemicolon::JsEmptyClassMember(stmt) => { mutation.remove_node(stmt.clone()); } } @@ -166,8 +155,3 @@ impl Rule for NoExtraSemicolons { }) } } - -pub enum AnyJsExtraSemicolonOptionType { - JsEmptyStatement(JsEmptyStatement), - JsEmptyClassMember(JsEmptyClassMember), -} diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js index 939d661c1a8..a58943476d7 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js @@ -32,7 +32,9 @@ for(;true;);; for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; -const x = 5;; +{ + const x = 5;; +} function foo() { // code @@ -120,7 +122,9 @@ for(;true;); for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); -const x = 5; +{ + const x = 5; +} const foo = function() { // code diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap index fa71231d917..57f1d8b1f90 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap @@ -38,7 +38,9 @@ for(;true;);; for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; -const x = 5;; +{ + const x = 5;; +} function foo() { // code @@ -126,7 +128,9 @@ for(;true;); for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); -const x = 5; +{ + const x = 5; +} const foo = function() { // code @@ -147,323 +151,324 @@ class C { # Diagnostics ``` -noExtraSemicolons.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:8:12 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 4 │ if (x > 5) { - 5 │ x = 5; - > 6 │ }; - │ ^ - 7 │ - 8 │ while(true);; + 6 │ }; + 7 │ + > 8 │ while(true);; + │ ^ + 9 │ + 10 │ while(true) {}; i Suggested fix: Remove unnecessary semicolon. - 6 │ }; - │ - + 8 │ while(true);; + │ - ``` ``` -noExtraSemicolons.js:8:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:31:12 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 6 │ }; - 7 │ - > 8 │ while(true);; - │ ^ - 9 │ - 10 │ while(true) {}; + 29 │ } + 30 │ + > 31 │ for(;true;);; + │ ^ + 32 │ + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; i Suggested fix: Remove unnecessary semicolon. - 8 │ while(true);; - │ - + 31 │ for(;true;);; + │ - ``` ``` -noExtraSemicolons.js:10:15 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:33:12 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 8 │ while(true);; - 9 │ - > 10 │ while(true) {}; - │ ^ - 11 │ - 12 │ loop1: + 31 │ for(;true;);; + 32 │ + > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ ^ + 34 │ + 35 │ { i Suggested fix: Remove unnecessary semicolon. - 10 │ while(true)·{}; - │ - + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ - ``` ``` -noExtraSemicolons.js:14:17 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:33:24 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 12 │ loop1: - 13 │ for (let i = 0; i < 5; i++) { - > 14 │ str = str + i;; - │ ^ - 15 │ }; - 16 │ + 31 │ for(;true;);; + 32 │ + > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ ^ + 34 │ + 35 │ { i Suggested fix: Remove unnecessary semicolon. - 14 │ ··str·=·str·+·i;; - │ - + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ - ``` ``` -noExtraSemicolons.js:15:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:33:36 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 13 │ for (let i = 0; i < 5; i++) { - 14 │ str = str + i;; - > 15 │ }; - │ ^ - 16 │ - 17 │ loop1: + 31 │ for(;true;);; + 32 │ + > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ ^ + 34 │ + 35 │ { i Suggested fix: Remove unnecessary semicolon. - 15 │ }; - │ - + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ - ``` ``` -noExtraSemicolons.js:23:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:33:48 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 21 │ } - 22 │ str = str + i; - > 23 │ }; - │ ^ - 24 │ - 25 │ function baz() { ; } + 31 │ for(;true;);; + 32 │ + > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ ^ + 34 │ + 35 │ { i Suggested fix: Remove unnecessary semicolon. - 23 │ }; - │ - + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ - ``` ``` -noExtraSemicolons.js:25:18 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:33:60 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 23 │ }; - 24 │ - > 25 │ function baz() { ; } - │ ^ - 26 │ - 27 │ function buzz() { + 31 │ for(;true;);; + 32 │ + > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ ^ + 34 │ + 35 │ { i Suggested fix: Remove unnecessary semicolon. - 25 │ function·baz()·{·;·} - │ -- + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ - ``` ``` -noExtraSemicolons.js:28:16 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:44:11 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 27 │ function buzz() { - > 28 │ const x = 10;; - │ ^ - 29 │ } - 30 │ + 43 │ class C { + > 44 │ field;; + │ ^ + 45 │ + 46 │ method() { i Suggested fix: Remove unnecessary semicolon. - 28 │ ··const·x·=·10;; - │ - + 44 │ ····field;; + │ - ``` ``` -noExtraSemicolons.js:31:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:60:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 29 │ } - 30 │ - > 31 │ for(;true;);; - │ ^ - 32 │ - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + 58 │ method() { + 59 │ // code + > 60 │ }; + │ ^ + 61 │ + 62 │ static { i Suggested fix: Remove unnecessary semicolon. - 31 │ for(;true;);; - │ - + 60 │ ····}; + │ - ``` ``` -noExtraSemicolons.js:33:61 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:76:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 31 │ for(;true;);; - 32 │ - > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ ^ - 34 │ - 35 │ const x = 5;; + 74 │ static { + 75 │ // code + > 76 │ }; + │ ^ + 77 │ } + 78 │ i Suggested fix: Remove unnecessary semicolon. - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ - + 76 │ ····}; + │ - ``` ``` -noExtraSemicolons.js:35:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:98:12 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - 34 │ - > 35 │ const x = 5;; - │ ^ - 36 │ - 37 │ function foo() { + 96 │ }; + 97 │ + > 98 │ while(true); + │ ^ + 99 │ + 100 │ while(true) {} i Suggested fix: Remove unnecessary semicolon. - 35 │ const·x·=·5;; - │ - + 98 │ while(true); + │ - ``` ``` -noExtraSemicolons.js:39:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:121:12 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 37 │ function foo() { - 38 │ // code - > 39 │ }; - │ ^ - 40 │ - 41 │ class C { + 119 │ } + 120 │ + > 121 │ for(;true;); + │ ^ + 122 │ + 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); i Suggested fix: Remove unnecessary semicolon. - 39 │ }; - │ - + 121 │ for(;true;); + │ - ``` ``` -noExtraSemicolons.js:42:11 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:123:12 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 41 │ class C { - > 42 │ field;; - │ ^ - 43 │ - 44 │ method() { + 121 │ for(;true;); + 122 │ + > 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + │ ^ + 124 │ + 125 │ { i Suggested fix: Remove unnecessary semicolon. - 42 │ ····field;; - │ - + 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + │ - ``` ``` -noExtraSemicolons.js:58:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:123:24 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 56 │ method() { - 57 │ // code - > 58 │ }; - │ ^ - 59 │ - 60 │ static { + 121 │ for(;true;); + 122 │ + > 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + │ ^ + 124 │ + 125 │ { i Suggested fix: Remove unnecessary semicolon. - 58 │ ····}; - │ - + 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + │ - ``` ``` -noExtraSemicolons.js:74:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:123:36 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 72 │ static { - 73 │ // code - > 74 │ }; - │ ^ - 75 │ } - 76 │ + 121 │ for(;true;); + 122 │ + > 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + │ ^ + 124 │ + 125 │ { i Suggested fix: Remove unnecessary semicolon. - 74 │ ····}; - │ - + 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + │ - ``` ``` -noExtraSemicolons.js:87:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:123:48 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 85 │ // code - 86 │ } - > 87 │ }; - │ ^ - 88 │ - 89 │ // valid + 121 │ for(;true;); + 122 │ + > 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + │ ^ + 124 │ + 125 │ { i Suggested fix: Remove unnecessary semicolon. - 87 │ }; - │ - + 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + │ - ``` ``` -noExtraSemicolons.js:94:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:123:60 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 92 │ if (x > 5) { - 93 │ x = 5; - > 94 │ }; - │ ^ - 95 │ - 96 │ while(true); + 121 │ for(;true;); + 122 │ + > 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + │ ^ + 124 │ + 125 │ { i Suggested fix: Remove unnecessary semicolon. - 94 │ }; - │ - + 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + │ - ``` From 87db5819c5079d9301b657e80a346dfa9b6c88a4 Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 12:50:33 -0300 Subject: [PATCH 11/14] fix(rome_js_analyzer): remove unecessary condition --- .../analyzers/nursery/no_extra_semicolons.rs | 2 +- .../specs/nursery/noExtraSemicolons.js.snap | 302 ++++---- crates/rome_js_unicode_table/src/tables.rs | 8 +- website/src/pages/lint/rules/index.mdx | 703 ------------------ .../src/pages/lint/rules/noExtraSemicolons.md | 200 ----- 5 files changed, 153 insertions(+), 1062 deletions(-) delete mode 100644 website/src/pages/lint/rules/index.mdx delete mode 100644 website/src/pages/lint/rules/noExtraSemicolons.md diff --git a/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs b/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs index f188c44ce22..810f1cc70a4 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs @@ -112,7 +112,7 @@ impl Rule for NoExtraSemicolons { match node { AnyJsExtraSemicolon::JsEmptyStatement(stmt) => { let parent = stmt.syntax().parent()?; - if !parent.kind().is_list() { + if parent.kind().is_list() { Some(AnyJsExtraSemicolon::JsEmptyStatement( stmt.clone(), )) diff --git a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap index 57f1d8b1f90..15eee7362d8 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap +++ b/crates/rome_js_analyze/tests/specs/nursery/noExtraSemicolons.js.snap @@ -151,324 +151,322 @@ class C { # Diagnostics ``` -noExtraSemicolons.js:8:12 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:6:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 6 │ }; - 7 │ - > 8 │ while(true);; - │ ^ - 9 │ - 10 │ while(true) {}; + 4 │ if (x > 5) { + 5 │ x = 5; + > 6 │ }; + │ ^ + 7 │ + 8 │ while(true);; i Suggested fix: Remove unnecessary semicolon. - 8 │ while(true);; - │ - + 6 │ }; + │ - ``` ``` -noExtraSemicolons.js:31:12 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:8:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 29 │ } - 30 │ - > 31 │ for(;true;);; - │ ^ - 32 │ - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + 6 │ }; + 7 │ + > 8 │ while(true);; + │ ^ + 9 │ + 10 │ while(true) {}; i Suggested fix: Remove unnecessary semicolon. - 31 │ for(;true;);; - │ - + 8 │ while(true);; + │ - ``` ``` -noExtraSemicolons.js:33:12 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:10:15 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 31 │ for(;true;);; - 32 │ - > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ ^ - 34 │ - 35 │ { + 8 │ while(true);; + 9 │ + > 10 │ while(true) {}; + │ ^ + 11 │ + 12 │ loop1: i Suggested fix: Remove unnecessary semicolon. - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ - + 10 │ while(true)·{}; + │ - ``` ``` -noExtraSemicolons.js:33:24 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:14:17 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 31 │ for(;true;);; - 32 │ - > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ ^ - 34 │ - 35 │ { + 12 │ loop1: + 13 │ for (let i = 0; i < 5; i++) { + > 14 │ str = str + i;; + │ ^ + 15 │ }; + 16 │ i Suggested fix: Remove unnecessary semicolon. - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ - + 14 │ ··str·=·str·+·i;; + │ - ``` ``` -noExtraSemicolons.js:33:36 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:15:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 31 │ for(;true;);; - 32 │ - > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ ^ - 34 │ - 35 │ { + 13 │ for (let i = 0; i < 5; i++) { + 14 │ str = str + i;; + > 15 │ }; + │ ^ + 16 │ + 17 │ loop1: i Suggested fix: Remove unnecessary semicolon. - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ - + 15 │ }; + │ - ``` ``` -noExtraSemicolons.js:33:48 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:23:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 31 │ for(;true;);; - 32 │ - > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ ^ - 34 │ - 35 │ { + 21 │ } + 22 │ str = str + i; + > 23 │ }; + │ ^ + 24 │ + 25 │ function baz() { ; } i Suggested fix: Remove unnecessary semicolon. - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ - + 23 │ }; + │ - ``` ``` -noExtraSemicolons.js:33:60 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:25:18 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 31 │ for(;true;);; - 32 │ - > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ ^ - 34 │ - 35 │ { + 23 │ }; + 24 │ + > 25 │ function baz() { ; } + │ ^ + 26 │ + 27 │ function buzz() { i Suggested fix: Remove unnecessary semicolon. - 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; - │ - + 25 │ function·baz()·{·;·} + │ -- ``` ``` -noExtraSemicolons.js:44:11 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:28:16 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 43 │ class C { - > 44 │ field;; - │ ^ - 45 │ - 46 │ method() { + 27 │ function buzz() { + > 28 │ const x = 10;; + │ ^ + 29 │ } + 30 │ i Suggested fix: Remove unnecessary semicolon. - 44 │ ····field;; - │ - + 28 │ ··const·x·=·10;; + │ - ``` ``` -noExtraSemicolons.js:60:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:31:13 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 58 │ method() { - 59 │ // code - > 60 │ }; - │ ^ - 61 │ - 62 │ static { + 29 │ } + 30 │ + > 31 │ for(;true;);; + │ ^ + 32 │ + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; i Suggested fix: Remove unnecessary semicolon. - 60 │ ····}; - │ - + 31 │ for(;true;);; + │ - ``` ``` -noExtraSemicolons.js:76:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:33:61 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 74 │ static { - 75 │ // code - > 76 │ }; - │ ^ - 77 │ } - 78 │ + 31 │ for(;true;);; + 32 │ + > 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ ^ + 34 │ + 35 │ { i Suggested fix: Remove unnecessary semicolon. - 76 │ ····}; - │ - + 33 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);; + │ - ``` ``` -noExtraSemicolons.js:98:12 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:36:15 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 96 │ }; - 97 │ - > 98 │ while(true); - │ ^ - 99 │ - 100 │ while(true) {} + 35 │ { + > 36 │ const x = 5;; + │ ^ + 37 │ } + 38 │ i Suggested fix: Remove unnecessary semicolon. - 98 │ while(true); - │ - + 36 │ ··const·x·=·5;; + │ - ``` ``` -noExtraSemicolons.js:121:12 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:41:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 119 │ } - 120 │ - > 121 │ for(;true;); - │ ^ - 122 │ - 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); + 39 │ function foo() { + 40 │ // code + > 41 │ }; + │ ^ + 42 │ + 43 │ class C { i Suggested fix: Remove unnecessary semicolon. - 121 │ for(;true;); - │ - + 41 │ }; + │ - ``` ``` -noExtraSemicolons.js:123:12 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:44:11 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 121 │ for(;true;); - 122 │ - > 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - │ ^ - 124 │ - 125 │ { + 43 │ class C { + > 44 │ field;; + │ ^ + 45 │ + 46 │ method() { i Suggested fix: Remove unnecessary semicolon. - 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - │ - + 44 │ ····field;; + │ - ``` ``` -noExtraSemicolons.js:123:24 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:60:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 121 │ for(;true;); - 122 │ - > 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - │ ^ - 124 │ - 125 │ { + 58 │ method() { + 59 │ // code + > 60 │ }; + │ ^ + 61 │ + 62 │ static { i Suggested fix: Remove unnecessary semicolon. - 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - │ - + 60 │ ····}; + │ - ``` ``` -noExtraSemicolons.js:123:36 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:76:6 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 121 │ for(;true;); - 122 │ - > 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - │ ^ - 124 │ - 125 │ { + 74 │ static { + 75 │ // code + > 76 │ }; + │ ^ + 77 │ } + 78 │ i Suggested fix: Remove unnecessary semicolon. - 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - │ - + 76 │ ····}; + │ - ``` ``` -noExtraSemicolons.js:123:48 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:89:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 121 │ for(;true;); - 122 │ - > 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - │ ^ - 124 │ - 125 │ { + 87 │ // code + 88 │ } + > 89 │ }; + │ ^ + 90 │ + 91 │ // valid i Suggested fix: Remove unnecessary semicolon. - 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - │ - + 89 │ }; + │ - ``` ``` -noExtraSemicolons.js:123:60 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +noExtraSemicolons.js:96:2 lint/nursery/noExtraSemicolons FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary semicolon. - 121 │ for(;true;); - 122 │ - > 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - │ ^ - 124 │ - 125 │ { + 94 │ if (x > 5) { + 95 │ x = 5; + > 96 │ }; + │ ^ + 97 │ + 98 │ while(true); i Suggested fix: Remove unnecessary semicolon. - 123 │ for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); - │ - + 96 │ }; + │ - ``` diff --git a/crates/rome_js_unicode_table/src/tables.rs b/crates/rome_js_unicode_table/src/tables.rs index 7f67057597c..eb783866c93 100644 --- a/crates/rome_js_unicode_table/src/tables.rs +++ b/crates/rome_js_unicode_table/src/tables.rs @@ -787,9 +787,7 @@ pub mod derived_property { ('\u{31350}', '\u{323af}'), ('\u{e0100}', '\u{e01ef}'), ]; - pub fn ID_Continue(c: char) -> bool { - super::bsearch_range_table(c, ID_Continue_table) - } + pub fn ID_Continue(c: char) -> bool { super::bsearch_range_table(c, ID_Continue_table) } pub const ID_Start_table: &[(char, char)] = &[ ('A', 'Z'), ('a', 'z'), @@ -1451,7 +1449,5 @@ pub mod derived_property { ('𰀀', '𱍊'), ('\u{31350}', '\u{323af}'), ]; - pub fn ID_Start(c: char) -> bool { - super::bsearch_range_table(c, ID_Start_table) - } + pub fn ID_Start(c: char) -> bool { super::bsearch_range_table(c, ID_Start_table) } } diff --git a/website/src/pages/lint/rules/index.mdx b/website/src/pages/lint/rules/index.mdx deleted file mode 100644 index 03f3772063b..00000000000 --- a/website/src/pages/lint/rules/index.mdx +++ /dev/null @@ -1,703 +0,0 @@ ---- -title: Lint Rules -parent: linter/index -emoji: 📏 -description: List of available lint rules. -category: reference -mainClass: rules ---- - -# Rules - - -## Accessibility - -Rules focused on preventing accessibility problems. -
-
-

- noAutofocus - recommended -

-Avoid the autoFocus attribute -
-
-

- noBlankTarget - recommended -

-Disallow target="_blank" attribute without rel="noreferrer" -
-
-

- noPositiveTabindex - recommended -

-Prevent the usage of positive integers on tabIndex property -
-
-

- useAltText - recommended -

-It asserts that alternative text to images or areas, help to rely on to screen readers to understand the purpose and the context of the image. -
-
-

- useAnchorContent - recommended -

-Enforce that anchor elements have content and that the content is accessible to screen readers. -
-
-

- useButtonType - recommended -

-Enforces the usage of the attribute type for the element button -
-
-

- useKeyWithClickEvents - recommended -

-Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. -
-
-

- useKeyWithMouseEvents - recommended -

-Enforce that onMouseOver/onMouseOut are accompanied by onFocus/onBlur for keyboard-only users. -It is important to take into account users with physical disabilities who cannot use a mouse, -who use assistive technology or screenreader. -
-
-

- useValidAnchor - recommended -

-Enforce that all anchors are valid, and they are navigable elements. -
- -
- -## Complexity - -Rules that focus on inspecting complex code that could be simplified. -
-
-

- noExtraBooleanCast - recommended -

-Disallow unnecessary boolean casts -
-
-

- noMultipleSpacesInRegularExpressionLiterals - recommended -

-Disallow unclear usage of multiple space characters in regular expression literals -
-
-

- noUselessFragments -

-Disallow unnecessary fragments -
-
-

- useFlatMap - recommended -

-Promotes the use of .flatMap() when map().flat() are used together. -
-
-

- useOptionalChain - recommended -

-Enforce using concise optional chain instead of chained logical expressions. -
-
-

- useSimplifiedLogicExpression - recommended -

-Discard redundant terms from logical expressions. -
- -
- -## Correctness - -Rules that detect code that is guaranteed to be incorrect or useless. -
-
-

- noChildrenProp - recommended -

-Prevent passing of children as props. -
-
-

- noConstAssign - recommended -

-Prevents from having const variables being re-assigned. -
-
-

- noEmptyPattern - recommended -

-Disallows empty destructuring patterns. -
-
-

- noNewSymbol - recommended -

-Disallow new operators with the Symbol object -
-
-

- noRenderReturnValue - recommended -

-Prevent the usage of the return value of React.render. -
-
-

- noUndeclaredVariables -

-Prevents the usage of variables that haven't been declared inside the document -
-
-

- noUnnecessaryContinue - recommended -

-Avoid using unnecessary continue. -
-
-

- noUnreachable - recommended -

-Disallow unreachable code -
-
-

- noUnusedVariables -

-Disallow unused variables. -
-
-

- noVoidElementsWithChildren - recommended -

-This rules prevents void elements (AKA self-closing elements) from having children. -
-
-

- useValidForDirection - recommended -

-Enforce "for" loop update clause moving the counter in the right direction. -
- -
- -## Performance - -Rules catching ways your code could be written to run faster, or generally be more efficient. -
-
-

- noDelete - recommended -

-Disallow the use of the delete operator -
- -
- -## Security - -Rules that detect potential security flaws. -
-
-

- noDangerouslySetInnerHtml - recommended -

-Prevent the usage of dangerous JSX props -
-
-

- noDangerouslySetInnerHtmlWithChildren - recommended -

-Report when a DOM element or a component uses both children and dangerouslySetInnerHTML prop. -
- -
- -## Style - -Rules enforcing a consistent and idiomatic way of writing your code. -
-
-

- noArguments - recommended -

-Disallow the use of arguments -
-
-

- noImplicitBoolean -

-Disallow implicit true values on JSX boolean attributes -
-
-

- noNegationElse -

-Disallow negation in the condition of an if statement if it has an else clause -
-
-

- noShoutyConstants -

-Disallow the use of constants which its value is the upper-case version of its name. -
-
-

- noUnusedTemplateLiteral - recommended -

-Disallow template literals if interpolation and special-character handling are not needed -
-
-

- useBlockStatements -

-Requires following curly brace conventions. -JavaScript allows the omission of curly braces when a block contains only one statement. However, it is considered by many to be best practice to never omit curly braces around blocks, even when they are optional, because it can lead to bugs and reduces code clarity. -
-
-

- useFragmentSyntax -

-This rule enforces the use of <>...</> over <Fragment>...</Fragment>. -
-
-

- useSelfClosingElements - recommended -

-Prevent extra closing tags for components without children -
-
-

- useShorthandArrayType -

-When expressing array types, this rule promotes the usage of T[] shorthand instead of Array<T>. -
-
-

- useSingleCaseStatement -

-Enforces case clauses have a single statement, emits a quick fix wrapping -the statements in a block -
-
-

- useSingleVarDeclarator - recommended -

-Disallow multiple variable declarations in the same variable statement -
-
-

- useTemplate - recommended -

-Template literals are preferred over string concatenation. -
-
-

- useWhile - recommended -

-Enforce the use of while loops instead of for loops when the -initializer and update expressions are not needed -
- -
- -## Suspicious - -Rules that detect code that is likely to be incorrect or useless. -
-
-

- noArrayIndexKey - recommended -

-Discourage the usage of Array index in keys. -
-
-

- noAsyncPromiseExecutor - recommended -

-Disallows using an async function as a Promise executor. -
-
-

- noCatchAssign - recommended -

-Disallow reassigning exceptions in catch clauses -
-
-

- noCommentText - recommended -

-Prevent comments from being inserted as text nodes -
-
-

- noCompareNegZero - recommended -

-Disallow comparing against -0 -
-
-

- noDebugger - recommended -

-Disallow the use of debugger -
-
-

- noDoubleEquals - recommended -

-Require the use of === and !== -
-
-

- noDuplicateParameters - recommended -

-Disallow duplicate function arguments name. -
-
-

- noExplicitAny - recommended -

-Disallow the any type usage -
-
-

- noFunctionAssign - recommended -

-Disallow reassigning function declarations. -
-
-

- noImportAssign - recommended -

-Disallow assigning to imported bindings -
-
-

- noLabelVar - recommended -

-Disallow labels that share a name with a variable -
-
-

- noShadowRestrictedNames - recommended -

-Disallow identifiers from shadowing restricted names. -
-
-

- noSparseArray - recommended -

-Disallow sparse arrays -
-
-

- noUnsafeNegation - recommended -

-Disallow using unsafe negation. -
-
-

- useValidTypeof - recommended -

-This rule verifies the result of typeof $expr unary expressions is being -compared to valid values, either string literals containing valid type -names or other typeof expressions -
- -
- -## Nursery - -New rules that are still under development. - -Nursery rules require explicit opt-in via configuration on stable versions because they may still have bugs or performance problems. -They are enabled by default on nightly builds, but as they are unstable their diagnostic severity may be set to either error or -warning, depending on whether we intend for the rule to be recommended or not when it eventually gets stabilized. -Nursery rules get promoted to other groups once they become stable or may be removed. - -Rules that belong to this group are not subject to semantic version. -
-
-

- noAccessKey -

-Enforce that the accessKey attribute is not used on any HTML element. -
-
-

- noAssignInExpressions -

-Disallow assignments in expressions. -
-
-

- noBannedTypes -

-Disallow certain types. -
-
-

- noCommaOperator -

-Disallow comma operator. -
-
-

- noConstEnum -

-Disallow TypeScript const enum -
-
-

- noConstructorReturn -

-Disallow returning a value from a constructor. -
-
-

- noDistractingElements -

-Enforces that no distracting elements are used. -
-
-

- noDuplicateObjectKeys -

-Prevents object literals having more than one property declaration for the same name. -If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored, which is likely a mistake. -
-
-

- noEmptyInterface -

-Disallow the declaration of empty interfaces. -
-
-

- noExtraNonNullAssertion -

-Prevents the wrong usage of the non-null assertion operator (!) in TypeScript files. -
-
-

- noExtraSemicolons -

-Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. -While not technically an error, extra semicolons can cause confusion when reading code. -
-
-

- noHeaderScope -

-Check that the scope attribute is only used on th elements. -
-
-

- noInvalidConstructorSuper -

-Prevents the incorrect use of super() inside classes. -It also checks whether a call super() is missing from classes that extends other constructors. -
-
-

- noNonNullAssertion -

-Disallow non-null assertions using the ! postfix operator. -
-
-

- noPrecisionLoss -

-Disallow literal numbers that lose precision -
-
-

- noRedundantAlt -

-Enforce img alt prop does not contain the word "image", "picture", or "photo". -
-
-

- noRedundantUseStrict -

-Prevents from having redundant "use strict". -
-
-

- noRestrictedGlobals -

-This rule allows you to specify global variable names that you don’t want to use in your application. -
-
-

- noSelfCompare -

-Disallow comparisons where both sides are exactly the same. -
-
-

- noSetterReturn -

-Disallow returning a value from a setter -
-
-

- noStringCaseMismatch -

-Disallow comparison of expressions modifying the string case with non-compliant value. -
-
-

- noUnsafeFinally -

-Disallow control flow statements in finally blocks. -
-
-

- noUselessSwitchCase -

-Disallow useless case in switch statements. -
-
-

- noVar -

-Disallow the use of var -
-
-

- noVoidTypeReturn -

-Disallow returning a value from a function with the return type 'void' -
-
-

- noWith -

-Disallow with statements in non-strict contexts. -
-
-

- useAriaPropTypes -

-Enforce that ARIA state and property values are valid. -
-
-

- useAriaPropsForRole -

-Enforce that elements with ARIA roles must have all required ARIA attributes for that role. -
-
-

- useCamelCase -

-Enforce camel case naming convention. -
-
-

- useConst -

-Require const declarations for variables that are never reassigned after declared. -
-
-

- useDefaultParameterLast -

-Enforce default function parameters and optional parameters to be last. -
-
-

- useDefaultSwitchClauseLast -

-Enforce default clauses in switch statements to be last -
-
-

- useEnumInitializers -

-Require that each enum member value be explicitly initialized. -
-
-

- useExhaustiveDependencies -

-Enforce all dependencies are correctly specified. -
-
-

- useExponentiationOperator -

-Disallow the use of Math.pow in favor of the ** operator. -
-
-

- useHookAtTopLevel -

-Enforce that all React hooks are being called from the Top Level -component functions. -
-
-

- useNumericLiterals -

-Disallow parseInt() and Number.parseInt() in favor of binary, octal, and hexadecimal literals -
- -
diff --git a/website/src/pages/lint/rules/noExtraSemicolons.md b/website/src/pages/lint/rules/noExtraSemicolons.md deleted file mode 100644 index a4f52111d3c..00000000000 --- a/website/src/pages/lint/rules/noExtraSemicolons.md +++ /dev/null @@ -1,200 +0,0 @@ ---- -title: Lint Rule noExtraSemicolons -parent: lint/rules/index ---- - -# noExtraSemicolons (since v12.0.0) - -Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. -While not technically an error, extra semicolons can cause confusion when reading code. - -This rule disallows unnecessary semicolons. - -## Examples - -### Invalid - -```jsx - const x = 5;; -``` - -
nursery/noExtraSemicolons.js:1:15 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
-
-   Unnecessary semicolon.
-  
-  > 1 │   const x = 5;;
-                 ^
-    2 │ 
-  
-   Suggested fix: Remove unnecessary semicolon.
-  
-    1 │ ··const·x·=·5;;
-                -
-
- -```jsx - function buzz() { - const x = 10;; - } -``` - -
nursery/noExtraSemicolons.js:2:19 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
-
-   Unnecessary semicolon.
-  
-    1 │  function buzz() {
-  > 2 │      const x = 10;;
-                     ^
-    3 │  }
-    4 │ 
-  
-   Suggested fix: Remove unnecessary semicolon.
-  
-    2 │ ·····const·x·=·10;;
-                    -
-
- -```jsx - function foo() { - // code - }; -``` - -
nursery/noExtraSemicolons.js:3:4 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━
-
-   Unnecessary semicolon.
-  
-    1 │   function foo() {
-    2 │     // code
-  > 3 │   };
-      ^
-    4 │ 
-  
-   Suggested fix: Remove unnecessary semicolon.
-  
-    3 │ ··};
-     -
-
- -```jsx - class C { - field;; - - method() { - // code - } - - static { - // code - } - } -``` - -
nursery/noExtraSemicolons.js:2:13 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
-
-   Unnecessary semicolon.
-  
-    1 │     class C {
-  > 2 │       field;;
-               ^
-    3 │ 
-    4 │       method() {
-  
-   Suggested fix: Remove unnecessary semicolon.
-  
-    2 │ ······field;;
-              -
-
- -```jsx - class C { - field; - - method() { - // code - }; - - static { - // code - } - } -``` - -
nursery/noExtraSemicolons.js:6:7 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━
-
-   Unnecessary semicolon.
-  
-    4 │      method() {
-    5 │          // code
-  > 6 │      };
-         ^
-    7 │ 
-    8 │      static {
-  
-   Suggested fix: Remove unnecessary semicolon.
-  
-    6 │ ·····};
-        -
-
- -```jsx - class C { - field; - - method() { - // code - } - - static { - // code - }; - } -``` - -
nursery/noExtraSemicolons.js:10:7 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
-
-   Unnecessary semicolon.
-  
-     8 │      static {
-     9 │          // code
-  > 10 │      };
-          ^
-    11 │    }
-    12 │ 
-  
-   Suggested fix: Remove unnecessary semicolon.
-  
-    10 │ ·····};
-        -
-
- -```jsx - class C { - field; - - method() { - // code - } - - static { - // code - } - }; -``` - -
nursery/noExtraSemicolons.js:11:5 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
-
-   Unnecessary semicolon.
-  
-     9 │          // code
-    10 │      }
-  > 11 │    };
-        ^
-    12 │ 
-  
-   Suggested fix: Remove unnecessary semicolon.
-  
-    11 │ ···};
-      -
-
- From 5d2fc107be38298988288f3b3d2ffd89ce3943fd Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 12:55:34 -0300 Subject: [PATCH 12/14] feat(rome_js_analyzer): generated resources --- .../analyzers/nursery/no_extra_semicolons.rs | 10 +- crates/rome_js_unicode_table/src/tables.rs | 8 +- website/src/pages/lint/rules/index.mdx | 703 ++++++++++++++++++ .../src/pages/lint/rules/noExtraSemicolons.md | 200 +++++ 4 files changed, 913 insertions(+), 8 deletions(-) create mode 100644 website/src/pages/lint/rules/index.mdx create mode 100644 website/src/pages/lint/rules/noExtraSemicolons.md diff --git a/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs b/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs index 810f1cc70a4..8f5d2380bbe 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery/no_extra_semicolons.rs @@ -113,16 +113,14 @@ impl Rule for NoExtraSemicolons { AnyJsExtraSemicolon::JsEmptyStatement(stmt) => { let parent = stmt.syntax().parent()?; if parent.kind().is_list() { - Some(AnyJsExtraSemicolon::JsEmptyStatement( - stmt.clone(), - )) + Some(AnyJsExtraSemicolon::JsEmptyStatement(stmt.clone())) } else { None } } - AnyJsExtraSemicolon::JsEmptyClassMember(stmt) => Some( - AnyJsExtraSemicolon::JsEmptyClassMember(stmt.clone()), - ), + AnyJsExtraSemicolon::JsEmptyClassMember(stmt) => { + Some(AnyJsExtraSemicolon::JsEmptyClassMember(stmt.clone())) + } } } diff --git a/crates/rome_js_unicode_table/src/tables.rs b/crates/rome_js_unicode_table/src/tables.rs index eb783866c93..7f67057597c 100644 --- a/crates/rome_js_unicode_table/src/tables.rs +++ b/crates/rome_js_unicode_table/src/tables.rs @@ -787,7 +787,9 @@ pub mod derived_property { ('\u{31350}', '\u{323af}'), ('\u{e0100}', '\u{e01ef}'), ]; - pub fn ID_Continue(c: char) -> bool { super::bsearch_range_table(c, ID_Continue_table) } + pub fn ID_Continue(c: char) -> bool { + super::bsearch_range_table(c, ID_Continue_table) + } pub const ID_Start_table: &[(char, char)] = &[ ('A', 'Z'), ('a', 'z'), @@ -1449,5 +1451,7 @@ pub mod derived_property { ('𰀀', '𱍊'), ('\u{31350}', '\u{323af}'), ]; - pub fn ID_Start(c: char) -> bool { super::bsearch_range_table(c, ID_Start_table) } + pub fn ID_Start(c: char) -> bool { + super::bsearch_range_table(c, ID_Start_table) + } } diff --git a/website/src/pages/lint/rules/index.mdx b/website/src/pages/lint/rules/index.mdx new file mode 100644 index 00000000000..03f3772063b --- /dev/null +++ b/website/src/pages/lint/rules/index.mdx @@ -0,0 +1,703 @@ +--- +title: Lint Rules +parent: linter/index +emoji: 📏 +description: List of available lint rules. +category: reference +mainClass: rules +--- + +# Rules + + +## Accessibility + +Rules focused on preventing accessibility problems. +
+
+

+ noAutofocus + recommended +

+Avoid the autoFocus attribute +
+
+

+ noBlankTarget + recommended +

+Disallow target="_blank" attribute without rel="noreferrer" +
+
+

+ noPositiveTabindex + recommended +

+Prevent the usage of positive integers on tabIndex property +
+
+

+ useAltText + recommended +

+It asserts that alternative text to images or areas, help to rely on to screen readers to understand the purpose and the context of the image. +
+
+

+ useAnchorContent + recommended +

+Enforce that anchor elements have content and that the content is accessible to screen readers. +
+
+

+ useButtonType + recommended +

+Enforces the usage of the attribute type for the element button +
+
+

+ useKeyWithClickEvents + recommended +

+Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. +
+
+

+ useKeyWithMouseEvents + recommended +

+Enforce that onMouseOver/onMouseOut are accompanied by onFocus/onBlur for keyboard-only users. +It is important to take into account users with physical disabilities who cannot use a mouse, +who use assistive technology or screenreader. +
+
+

+ useValidAnchor + recommended +

+Enforce that all anchors are valid, and they are navigable elements. +
+ +
+ +## Complexity + +Rules that focus on inspecting complex code that could be simplified. +
+
+

+ noExtraBooleanCast + recommended +

+Disallow unnecessary boolean casts +
+
+

+ noMultipleSpacesInRegularExpressionLiterals + recommended +

+Disallow unclear usage of multiple space characters in regular expression literals +
+
+

+ noUselessFragments +

+Disallow unnecessary fragments +
+
+

+ useFlatMap + recommended +

+Promotes the use of .flatMap() when map().flat() are used together. +
+
+

+ useOptionalChain + recommended +

+Enforce using concise optional chain instead of chained logical expressions. +
+
+

+ useSimplifiedLogicExpression + recommended +

+Discard redundant terms from logical expressions. +
+ +
+ +## Correctness + +Rules that detect code that is guaranteed to be incorrect or useless. +
+
+

+ noChildrenProp + recommended +

+Prevent passing of children as props. +
+
+

+ noConstAssign + recommended +

+Prevents from having const variables being re-assigned. +
+
+

+ noEmptyPattern + recommended +

+Disallows empty destructuring patterns. +
+
+

+ noNewSymbol + recommended +

+Disallow new operators with the Symbol object +
+
+

+ noRenderReturnValue + recommended +

+Prevent the usage of the return value of React.render. +
+
+

+ noUndeclaredVariables +

+Prevents the usage of variables that haven't been declared inside the document +
+
+

+ noUnnecessaryContinue + recommended +

+Avoid using unnecessary continue. +
+
+

+ noUnreachable + recommended +

+Disallow unreachable code +
+
+

+ noUnusedVariables +

+Disallow unused variables. +
+
+

+ noVoidElementsWithChildren + recommended +

+This rules prevents void elements (AKA self-closing elements) from having children. +
+
+

+ useValidForDirection + recommended +

+Enforce "for" loop update clause moving the counter in the right direction. +
+ +
+ +## Performance + +Rules catching ways your code could be written to run faster, or generally be more efficient. +
+
+

+ noDelete + recommended +

+Disallow the use of the delete operator +
+ +
+ +## Security + +Rules that detect potential security flaws. +
+
+

+ noDangerouslySetInnerHtml + recommended +

+Prevent the usage of dangerous JSX props +
+
+

+ noDangerouslySetInnerHtmlWithChildren + recommended +

+Report when a DOM element or a component uses both children and dangerouslySetInnerHTML prop. +
+ +
+ +## Style + +Rules enforcing a consistent and idiomatic way of writing your code. +
+
+

+ noArguments + recommended +

+Disallow the use of arguments +
+
+

+ noImplicitBoolean +

+Disallow implicit true values on JSX boolean attributes +
+
+

+ noNegationElse +

+Disallow negation in the condition of an if statement if it has an else clause +
+
+

+ noShoutyConstants +

+Disallow the use of constants which its value is the upper-case version of its name. +
+
+

+ noUnusedTemplateLiteral + recommended +

+Disallow template literals if interpolation and special-character handling are not needed +
+
+

+ useBlockStatements +

+Requires following curly brace conventions. +JavaScript allows the omission of curly braces when a block contains only one statement. However, it is considered by many to be best practice to never omit curly braces around blocks, even when they are optional, because it can lead to bugs and reduces code clarity. +
+
+

+ useFragmentSyntax +

+This rule enforces the use of <>...</> over <Fragment>...</Fragment>. +
+
+

+ useSelfClosingElements + recommended +

+Prevent extra closing tags for components without children +
+
+

+ useShorthandArrayType +

+When expressing array types, this rule promotes the usage of T[] shorthand instead of Array<T>. +
+
+

+ useSingleCaseStatement +

+Enforces case clauses have a single statement, emits a quick fix wrapping +the statements in a block +
+
+

+ useSingleVarDeclarator + recommended +

+Disallow multiple variable declarations in the same variable statement +
+
+

+ useTemplate + recommended +

+Template literals are preferred over string concatenation. +
+
+

+ useWhile + recommended +

+Enforce the use of while loops instead of for loops when the +initializer and update expressions are not needed +
+ +
+ +## Suspicious + +Rules that detect code that is likely to be incorrect or useless. +
+
+

+ noArrayIndexKey + recommended +

+Discourage the usage of Array index in keys. +
+
+

+ noAsyncPromiseExecutor + recommended +

+Disallows using an async function as a Promise executor. +
+
+

+ noCatchAssign + recommended +

+Disallow reassigning exceptions in catch clauses +
+
+

+ noCommentText + recommended +

+Prevent comments from being inserted as text nodes +
+
+

+ noCompareNegZero + recommended +

+Disallow comparing against -0 +
+
+

+ noDebugger + recommended +

+Disallow the use of debugger +
+
+

+ noDoubleEquals + recommended +

+Require the use of === and !== +
+
+

+ noDuplicateParameters + recommended +

+Disallow duplicate function arguments name. +
+
+

+ noExplicitAny + recommended +

+Disallow the any type usage +
+
+

+ noFunctionAssign + recommended +

+Disallow reassigning function declarations. +
+
+

+ noImportAssign + recommended +

+Disallow assigning to imported bindings +
+
+

+ noLabelVar + recommended +

+Disallow labels that share a name with a variable +
+
+

+ noShadowRestrictedNames + recommended +

+Disallow identifiers from shadowing restricted names. +
+
+

+ noSparseArray + recommended +

+Disallow sparse arrays +
+
+

+ noUnsafeNegation + recommended +

+Disallow using unsafe negation. +
+
+

+ useValidTypeof + recommended +

+This rule verifies the result of typeof $expr unary expressions is being +compared to valid values, either string literals containing valid type +names or other typeof expressions +
+ +
+ +## Nursery + +New rules that are still under development. + +Nursery rules require explicit opt-in via configuration on stable versions because they may still have bugs or performance problems. +They are enabled by default on nightly builds, but as they are unstable their diagnostic severity may be set to either error or +warning, depending on whether we intend for the rule to be recommended or not when it eventually gets stabilized. +Nursery rules get promoted to other groups once they become stable or may be removed. + +Rules that belong to this group are not subject to semantic version. +
+
+

+ noAccessKey +

+Enforce that the accessKey attribute is not used on any HTML element. +
+
+

+ noAssignInExpressions +

+Disallow assignments in expressions. +
+
+

+ noBannedTypes +

+Disallow certain types. +
+
+

+ noCommaOperator +

+Disallow comma operator. +
+
+

+ noConstEnum +

+Disallow TypeScript const enum +
+
+

+ noConstructorReturn +

+Disallow returning a value from a constructor. +
+
+

+ noDistractingElements +

+Enforces that no distracting elements are used. +
+
+

+ noDuplicateObjectKeys +

+Prevents object literals having more than one property declaration for the same name. +If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored, which is likely a mistake. +
+
+

+ noEmptyInterface +

+Disallow the declaration of empty interfaces. +
+
+

+ noExtraNonNullAssertion +

+Prevents the wrong usage of the non-null assertion operator (!) in TypeScript files. +
+
+

+ noExtraSemicolons +

+Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. +While not technically an error, extra semicolons can cause confusion when reading code. +
+
+

+ noHeaderScope +

+Check that the scope attribute is only used on th elements. +
+
+

+ noInvalidConstructorSuper +

+Prevents the incorrect use of super() inside classes. +It also checks whether a call super() is missing from classes that extends other constructors. +
+
+

+ noNonNullAssertion +

+Disallow non-null assertions using the ! postfix operator. +
+
+

+ noPrecisionLoss +

+Disallow literal numbers that lose precision +
+
+

+ noRedundantAlt +

+Enforce img alt prop does not contain the word "image", "picture", or "photo". +
+
+

+ noRedundantUseStrict +

+Prevents from having redundant "use strict". +
+
+

+ noRestrictedGlobals +

+This rule allows you to specify global variable names that you don’t want to use in your application. +
+
+

+ noSelfCompare +

+Disallow comparisons where both sides are exactly the same. +
+
+

+ noSetterReturn +

+Disallow returning a value from a setter +
+
+

+ noStringCaseMismatch +

+Disallow comparison of expressions modifying the string case with non-compliant value. +
+
+

+ noUnsafeFinally +

+Disallow control flow statements in finally blocks. +
+
+

+ noUselessSwitchCase +

+Disallow useless case in switch statements. +
+
+

+ noVar +

+Disallow the use of var +
+
+

+ noVoidTypeReturn +

+Disallow returning a value from a function with the return type 'void' +
+
+

+ noWith +

+Disallow with statements in non-strict contexts. +
+
+

+ useAriaPropTypes +

+Enforce that ARIA state and property values are valid. +
+
+

+ useAriaPropsForRole +

+Enforce that elements with ARIA roles must have all required ARIA attributes for that role. +
+
+

+ useCamelCase +

+Enforce camel case naming convention. +
+
+

+ useConst +

+Require const declarations for variables that are never reassigned after declared. +
+
+

+ useDefaultParameterLast +

+Enforce default function parameters and optional parameters to be last. +
+
+

+ useDefaultSwitchClauseLast +

+Enforce default clauses in switch statements to be last +
+
+

+ useEnumInitializers +

+Require that each enum member value be explicitly initialized. +
+
+

+ useExhaustiveDependencies +

+Enforce all dependencies are correctly specified. +
+
+

+ useExponentiationOperator +

+Disallow the use of Math.pow in favor of the ** operator. +
+
+

+ useHookAtTopLevel +

+Enforce that all React hooks are being called from the Top Level +component functions. +
+
+

+ useNumericLiterals +

+Disallow parseInt() and Number.parseInt() in favor of binary, octal, and hexadecimal literals +
+ +
diff --git a/website/src/pages/lint/rules/noExtraSemicolons.md b/website/src/pages/lint/rules/noExtraSemicolons.md new file mode 100644 index 00000000000..a4f52111d3c --- /dev/null +++ b/website/src/pages/lint/rules/noExtraSemicolons.md @@ -0,0 +1,200 @@ +--- +title: Lint Rule noExtraSemicolons +parent: lint/rules/index +--- + +# noExtraSemicolons (since v12.0.0) + +Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. +While not technically an error, extra semicolons can cause confusion when reading code. + +This rule disallows unnecessary semicolons. + +## Examples + +### Invalid + +```jsx + const x = 5;; +``` + +
nursery/noExtraSemicolons.js:1:15 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+  > 1 │   const x = 5;;
+                 ^
+    2 │ 
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    1 │ ··const·x·=·5;;
+                -
+
+ +```jsx + function buzz() { + const x = 10;; + } +``` + +
nursery/noExtraSemicolons.js:2:19 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+    1 │  function buzz() {
+  > 2 │      const x = 10;;
+                     ^
+    3 │  }
+    4 │ 
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    2 │ ·····const·x·=·10;;
+                    -
+
+ +```jsx + function foo() { + // code + }; +``` + +
nursery/noExtraSemicolons.js:3:4 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+    1 │   function foo() {
+    2 │     // code
+  > 3 │   };
+      ^
+    4 │ 
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    3 │ ··};
+     -
+
+ +```jsx + class C { + field;; + + method() { + // code + } + + static { + // code + } + } +``` + +
nursery/noExtraSemicolons.js:2:13 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+    1 │     class C {
+  > 2 │       field;;
+               ^
+    3 │ 
+    4 │       method() {
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    2 │ ······field;;
+              -
+
+ +```jsx + class C { + field; + + method() { + // code + }; + + static { + // code + } + } +``` + +
nursery/noExtraSemicolons.js:6:7 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+    4 │      method() {
+    5 │          // code
+  > 6 │      };
+         ^
+    7 │ 
+    8 │      static {
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    6 │ ·····};
+        -
+
+ +```jsx + class C { + field; + + method() { + // code + } + + static { + // code + }; + } +``` + +
nursery/noExtraSemicolons.js:10:7 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+     8 │      static {
+     9 │          // code
+  > 10 │      };
+          ^
+    11 │    }
+    12 │ 
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    10 │ ·····};
+        -
+
+ +```jsx + class C { + field; + + method() { + // code + } + + static { + // code + } + }; +``` + +
nursery/noExtraSemicolons.js:11:5 lint/nursery/noExtraSemicolons  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Unnecessary semicolon.
+  
+     9 │          // code
+    10 │      }
+  > 11 │    };
+        ^
+    12 │ 
+  
+   Suggested fix: Remove unnecessary semicolon.
+  
+    11 │ ···};
+      -
+
+ From 7fbc52f32180653e4ca7b64962a779feed67cecd Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Fri, 16 Dec 2022 13:26:11 -0300 Subject: [PATCH 13/14] feat(rome_js_analyzer): updated rules with merge --- .../src/configuration/linter/rules.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/rome_service/src/configuration/linter/rules.rs b/crates/rome_service/src/configuration/linter/rules.rs index 9788657dd11..3152e06b2ef 100644 --- a/crates/rome_service/src/configuration/linter/rules.rs +++ b/crates/rome_service/src/configuration/linter/rules.rs @@ -802,7 +802,7 @@ struct NurserySchema { } impl Nursery { const CATEGORY_NAME: &'static str = "nursery"; - pub(crate) const CATEGORY_RULES: [&'static str; 37] = [ + pub(crate) const CATEGORY_RULES: [&'static str; 38] = [ "noAccessKey", "noAssignInExpressions", "noBannedTypes", @@ -842,7 +842,7 @@ impl Nursery { "useHookAtTopLevel", "useNumericLiterals", ]; - const RECOMMENDED_RULES: [&'static str; 28] = [ + const RECOMMENDED_RULES: [&'static str; 29] = [ "noAssignInExpressions", "noBannedTypes", "noClassAssign", @@ -873,7 +873,7 @@ impl Nursery { "useExhaustiveDependencies", "useNumericLiterals", ]; - const RECOMMENDED_RULES_AS_FILTERS: [RuleFilter<'static>; 28] = [ + const RECOMMENDED_RULES_AS_FILTERS: [RuleFilter<'static>; 29] = [ RuleFilter::Rule("nursery", Self::CATEGORY_RULES[1]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[2]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[3]), @@ -886,8 +886,8 @@ impl Nursery { RuleFilter::Rule("nursery", Self::CATEGORY_RULES[10]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[11]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[12]), - RuleFilter::Rule("nursery", Self::CATEGORY_RULES[15]), - RuleFilter::Rule("nursery", Self::CATEGORY_RULES[18]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[13]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[16]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[19]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[20]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[21]), @@ -895,13 +895,14 @@ impl Nursery { RuleFilter::Rule("nursery", Self::CATEGORY_RULES[23]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[24]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[25]), - RuleFilter::Rule("nursery", Self::CATEGORY_RULES[27]), - RuleFilter::Rule("nursery", Self::CATEGORY_RULES[29]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[26]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[28]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[30]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[31]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[32]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[33]), - RuleFilter::Rule("nursery", Self::CATEGORY_RULES[36]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[34]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[37]), ]; pub(crate) fn is_recommended(&self) -> bool { !matches!(self.recommended, Some(false)) } pub(crate) fn get_enabled_rules(&self) -> IndexSet { @@ -928,7 +929,7 @@ impl Nursery { pub(crate) fn is_recommended_rule(rule_name: &str) -> bool { Self::RECOMMENDED_RULES.contains(&rule_name) } - pub(crate) fn recommended_rules_as_filters() -> [RuleFilter<'static>; 28] { + pub(crate) fn recommended_rules_as_filters() -> [RuleFilter<'static>; 29] { Self::RECOMMENDED_RULES_AS_FILTERS } } From b007d1728ff8d00a7c1b463a702fe55b11470401 Mon Sep 17 00:00:00 2001 From: Kaique da Silva Date: Mon, 19 Dec 2022 10:24:56 -0300 Subject: [PATCH 14/14] feat(rome_js_analyzer): check ready ok --- crates/rome_service/src/configuration/linter/rules.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/rome_service/src/configuration/linter/rules.rs b/crates/rome_service/src/configuration/linter/rules.rs index 823386dca69..6d35940101e 100644 --- a/crates/rome_service/src/configuration/linter/rules.rs +++ b/crates/rome_service/src/configuration/linter/rules.rs @@ -804,7 +804,7 @@ struct NurserySchema { } impl Nursery { const CATEGORY_NAME: &'static str = "nursery"; - pub(crate) const CATEGORY_RULES: [&'static str; 38] = [ + pub(crate) const CATEGORY_RULES: [&'static str; 39] = [ "noAccessKey", "noAssignInExpressions", "noBannedTypes", @@ -845,7 +845,7 @@ impl Nursery { "useNumericLiterals", "useValidLang", ]; - const RECOMMENDED_RULES: [&'static str; 29] = [ + const RECOMMENDED_RULES: [&'static str; 30] = [ "noAssignInExpressions", "noBannedTypes", "noClassAssign", @@ -877,7 +877,7 @@ impl Nursery { "useNumericLiterals", "useValidLang", ]; - const RECOMMENDED_RULES_AS_FILTERS: [RuleFilter<'static>; 29] = [ + const RECOMMENDED_RULES_AS_FILTERS: [RuleFilter<'static>; 30] = [ RuleFilter::Rule("nursery", Self::CATEGORY_RULES[1]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[2]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[3]), @@ -906,8 +906,8 @@ impl Nursery { RuleFilter::Rule("nursery", Self::CATEGORY_RULES[32]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[33]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[34]), - RuleFilter::Rule("nursery", Self::CATEGORY_RULES[36]), RuleFilter::Rule("nursery", Self::CATEGORY_RULES[37]), + RuleFilter::Rule("nursery", Self::CATEGORY_RULES[38]), ]; pub(crate) fn is_recommended(&self) -> bool { !matches!(self.recommended, Some(false)) } pub(crate) fn get_enabled_rules(&self) -> IndexSet { @@ -934,7 +934,7 @@ impl Nursery { pub(crate) fn is_recommended_rule(rule_name: &str) -> bool { Self::RECOMMENDED_RULES.contains(&rule_name) } - pub(crate) fn recommended_rules_as_filters() -> [RuleFilter<'static>; 29] { + pub(crate) fn recommended_rules_as_filters() -> [RuleFilter<'static>; 30] { Self::RECOMMENDED_RULES_AS_FILTERS } }