diff --git a/crates/rome_diagnostics_categories/src/categories.rs b/crates/rome_diagnostics_categories/src/categories.rs index bb1dd6a29f2..65278f7aa86 100644 --- a/crates/rome_diagnostics_categories/src/categories.rs +++ b/crates/rome_diagnostics_categories/src/categories.rs @@ -100,7 +100,7 @@ define_categories! { "lint/nursery/noParameterAssign": "https://docs.rome.tools/lint/rules/noParameterAssign", "lint/nursery/noNamespace": "https://docs.rome.tools/lint/rules/noNamespace", // Insert new nursery rule here - "lint/nursery/noRedeclaration": "https://docs.rome.tools/lint/rules/noRedeclaration", + "lint/nursery/noRedeclare": "https://docs.rome.tools/lint/rules/noRedeclare", "lint/nursery/useNamespaceKeyword": "https://docs.rome.tools/lint/rules/useNamespaceKeyword", // performance diff --git a/crates/rome_js_analyze/src/lib.rs b/crates/rome_js_analyze/src/lib.rs index cea5b44a0e6..10e06d5dd94 100644 --- a/crates/rome_js_analyze/src/lib.rs +++ b/crates/rome_js_analyze/src/lib.rs @@ -189,7 +189,7 @@ mod tests { let mut error_ranges: Vec = Vec::new(); let options = AnalyzerOptions::default(); - let rule_filter = RuleFilter::Rule("nursery", "noRedeclaration"); + let rule_filter = RuleFilter::Rule("nursery", "noRedeclare"); analyze( &parsed.tree(), AnalysisFilter { diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery.rs index ed094d956ba..c6d094905d2 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery.rs @@ -3,10 +3,10 @@ use rome_analyze::declare_group; mod no_class_assign; mod no_parameter_assign; -mod no_redeclaration; +mod no_redeclare; mod no_restricted_globals; mod use_camel_case; mod use_exhaustive_dependencies; mod use_hook_at_top_level; mod use_iframe_title; -declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_class_assign :: NoClassAssign , self :: no_parameter_assign :: NoParameterAssign , self :: no_redeclaration :: NoRedeclaration , self :: no_restricted_globals :: NoRestrictedGlobals , self :: use_camel_case :: UseCamelCase , self :: use_exhaustive_dependencies :: UseExhaustiveDependencies , self :: use_hook_at_top_level :: UseHookAtTopLevel , self :: use_iframe_title :: UseIframeTitle ,] } } +declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_class_assign :: NoClassAssign , self :: no_parameter_assign :: NoParameterAssign , self :: no_redeclare :: NoRedeclare , self :: no_restricted_globals :: NoRestrictedGlobals , self :: use_camel_case :: UseCamelCase , self :: use_exhaustive_dependencies :: UseExhaustiveDependencies , self :: use_hook_at_top_level :: UseHookAtTopLevel , self :: use_iframe_title :: UseIframeTitle ,] } } diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_redeclaration.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_redeclare.rs similarity index 92% rename from crates/rome_js_analyze/src/semantic_analyzers/nursery/no_redeclaration.rs rename to crates/rome_js_analyze/src/semantic_analyzers/nursery/no_redeclare.rs index d9b4de82bfc..451e88bcc21 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_redeclaration.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/no_redeclare.rs @@ -9,7 +9,9 @@ use rome_rowan::AstNode; use std::collections::HashMap; declare_rule! { - /// Eliminate variables that have multiple declarations in the same scope. + /// Disallow variable, function, class, and type redeclarations in the same scope. + /// + /// Source: https://typescript-eslint.io/rules/no-redeclare /// /// ## Examples /// @@ -58,9 +60,9 @@ declare_rule! { /// bar(a: A, b: B) {} /// } /// ``` - pub(crate) NoRedeclaration { + pub(crate) NoRedeclare { version: "12.0.0", - name: "noRedeclaration", + name: "noRedeclare", recommended: true, } } @@ -72,7 +74,7 @@ pub(crate) struct Redeclaration { redeclaration: TextRange, } -impl Rule for NoRedeclaration { +impl Rule for NoRedeclare { type Query = SemanticServices; type State = Redeclaration; type Signals = Vec; @@ -96,13 +98,13 @@ impl Rule for NoRedeclaration { rule_category!(), redeclaration, markup! { - "Shouldn't redeclare '"{ name }"'. Consider to delete it or rename it" + "Shouldn't redeclare '"{ name }"'. Consider to delete it or rename it." }, ) .detail( declaration, markup! { - "'"{ name }"' is defined here." + "'"{ name }"' is defined here:" }, ); Some(diag) diff --git a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid-declaration-merging.ts b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid-declaration-merging.ts similarity index 100% rename from crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid-declaration-merging.ts rename to crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid-declaration-merging.ts diff --git a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid-declaration-merging.ts.snap b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid-declaration-merging.ts.snap similarity index 71% rename from crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid-declaration-merging.ts.snap rename to crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid-declaration-merging.ts.snap index 03248bf6c2a..2c5f31c8e12 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid-declaration-merging.ts.snap +++ b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid-declaration-merging.ts.snap @@ -1,6 +1,5 @@ --- source: crates/rome_js_analyze/tests/spec_tests.rs -assertion_line: 91 expression: invalid-declaration-merging.ts --- # Input @@ -26,9 +25,9 @@ enum Order { # Diagnostics ``` -invalid-declaration-merging.ts:4:11 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid-declaration-merging.ts:4:11 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'Order'. Consider to delete it or rename it + ! Shouldn't redeclare 'Order'. Consider to delete it or rename it. 2 │ export type Order = -1 | 0 | 1; 3 │ @@ -37,7 +36,7 @@ invalid-declaration-merging.ts:4:11 lint/nursery/noRedeclaration ━━━━━ 5 │ f(): void; 6 │ } - i 'Order' is defined here. + i 'Order' is defined here: 1 │ // Type and value merging > 2 │ export type Order = -1 | 0 | 1; @@ -49,9 +48,9 @@ invalid-declaration-merging.ts:4:11 lint/nursery/noRedeclaration ━━━━━ ``` ``` -invalid-declaration-merging.ts:8:7 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid-declaration-merging.ts:8:7 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'Order'. Consider to delete it or rename it + ! Shouldn't redeclare 'Order'. Consider to delete it or rename it. 6 │ } 7 │ @@ -60,7 +59,7 @@ invalid-declaration-merging.ts:8:7 lint/nursery/noRedeclaration ━━━━━ 9 │ prop: number; 10 │ } - i 'Order' is defined here. + i 'Order' is defined here: 1 │ // Type and value merging > 2 │ export type Order = -1 | 0 | 1; @@ -72,9 +71,9 @@ invalid-declaration-merging.ts:8:7 lint/nursery/noRedeclaration ━━━━━ ``` ``` -invalid-declaration-merging.ts:12:6 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid-declaration-merging.ts:12:6 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'Order'. Consider to delete it or rename it + ! Shouldn't redeclare 'Order'. Consider to delete it or rename it. 10 │ } 11 │ @@ -83,7 +82,7 @@ invalid-declaration-merging.ts:12:6 lint/nursery/noRedeclaration ━━━━━ 13 │ Lower = -1, 14 │ Equal = 0, - i 'Order' is defined here. + i 'Order' is defined here: 1 │ // Type and value merging > 2 │ export type Order = -1 | 0 | 1; diff --git a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid.jsonc b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid.jsonc similarity index 100% rename from crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid.jsonc rename to crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid.jsonc diff --git a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid.jsonc.snap b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid.jsonc.snap similarity index 55% rename from crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid.jsonc.snap rename to crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid.jsonc.snap index 980ec9b02c9..ba3878aeaa3 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid.jsonc.snap +++ b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid.jsonc.snap @@ -1,6 +1,5 @@ --- source: crates/rome_js_analyze/tests/spec_tests.rs -assertion_line: 91 expression: invalid.jsonc --- # Input @@ -10,14 +9,14 @@ var a = 3; var a = 10; # Diagnostics ``` -invalid.jsonc:1:16 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:16 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var a = 3; var a = 10; │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var a = 3; var a = 10; │ ^ @@ -32,14 +31,14 @@ var c; { var a; var a;} # Diagnostics ``` -invalid.jsonc:1:21 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:21 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var c; { var a; var a;}· │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var c; { var a; var a;}· │ ^ @@ -54,14 +53,14 @@ var a; { function a(){} } # Diagnostics ``` -invalid.jsonc:1:19 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:19 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var a; { function a(){} } │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var a; { function a(){} } │ ^ @@ -77,15 +76,15 @@ case b: var b = 4} # Diagnostics ``` -invalid.jsonc:2:13 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:2:13 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'b'. Consider to delete it or rename it + ! Shouldn't redeclare 'b'. Consider to delete it or rename it. 1 │ switch(foo) { case a: var b = 3; > 2 │ case b: var b = 4} │ ^ - i 'b' is defined here. + i 'b' is defined here: > 1 │ switch(foo) { case a: var b = 3; │ ^ @@ -101,14 +100,14 @@ var a = 3; var a = 10; # Diagnostics ``` -invalid.jsonc:1:16 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:16 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var a = 3; var a = 10; │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var a = 3; var a = 10; │ ^ @@ -123,14 +122,14 @@ var a = {}; var a = []; # Diagnostics ``` -invalid.jsonc:1:17 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:17 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var a = {}; var a = []; │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var a = {}; var a = []; │ ^ @@ -145,14 +144,14 @@ var a; function a() {} # Diagnostics ``` -invalid.jsonc:1:17 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:17 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var a; function a() {} │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var a; function a() {} │ ^ @@ -167,14 +166,14 @@ function a() {} function a() {} # Diagnostics ``` -invalid.jsonc:1:26 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:26 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ function a() {} function a() {} │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ function a() {} function a() {} │ ^ @@ -189,14 +188,14 @@ var a = function() { }; var a = function() { } # Diagnostics ``` -invalid.jsonc:1:29 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:29 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var a = function() { }; var a = function() { } │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var a = function() { }; var a = function() { } │ ^ @@ -211,14 +210,14 @@ var a = function() { }; var a = new Date(); # Diagnostics ``` -invalid.jsonc:1:29 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:29 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var a = function() { }; var a = new Date(); │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var a = function() { }; var a = new Date(); │ ^ @@ -233,14 +232,14 @@ var a = 3; var a = 10; var a = 15; # Diagnostics ``` -invalid.jsonc:1:16 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:16 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var a = 3; var a = 10; var a = 15; │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var a = 3; var a = 10; var a = 15; │ ^ @@ -249,14 +248,14 @@ invalid.jsonc:1:16 lint/nursery/noRedeclaration ━━━━━━━━━━ ``` ``` -invalid.jsonc:1:28 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:28 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var a = 3; var a = 10; var a = 15; │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var a = 3; var a = 10; var a = 15; │ ^ @@ -271,14 +270,14 @@ var a; var a; # Diagnostics ``` -invalid.jsonc:1:12 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:12 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var a; var a; │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var a; var a; │ ^ @@ -293,14 +292,14 @@ export var a; var a; # Diagnostics ``` -invalid.jsonc:1:19 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:19 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ export var a; var a; │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ export var a; var a; │ ^ @@ -315,14 +314,14 @@ class C { static { var a; var a; } } # Diagnostics ``` -invalid.jsonc:1:31 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:31 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ class C { static { var a; var a; } } │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ class C { static { var a; var a; } } │ ^ @@ -337,14 +336,14 @@ class C { static { var a; { var a; } } } # Diagnostics ``` -invalid.jsonc:1:33 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:33 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ class C { static { var a; { var a; } } } │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ class C { static { var a; { var a; } } } │ ^ @@ -359,14 +358,14 @@ class C { static { { var a; } var a; } } # Diagnostics ``` -invalid.jsonc:1:35 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:35 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ class C { static { { var a; } var a; } } │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ class C { static { { var a; } var a; } } │ ^ @@ -381,14 +380,14 @@ class C { static { { var a; } { var a; } } } # Diagnostics ``` -invalid.jsonc:1:37 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:37 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ class C { static { { var a; } { var a; } } } │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ class C { static { { var a; } { var a; } } } │ ^ @@ -403,14 +402,14 @@ var a; var {a = 0, b: Object = 0} = {}; # Diagnostics ``` -invalid.jsonc:1:13 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:13 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var a; var {a = 0, b: Object = 0} = {}; │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var a; var {a = 0, b: Object = 0} = {}; │ ^ @@ -425,14 +424,14 @@ var a; var {a = 0, b: globalThis = 0} = {}; # Diagnostics ``` -invalid.jsonc:1:13 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:13 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ var a; var {a = 0, b: globalThis = 0} = {}; │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ var a; var {a = 0, b: globalThis = 0} = {}; │ ^ @@ -447,14 +446,14 @@ function f() { var a; var a; } # Diagnostics ``` -invalid.jsonc:1:27 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:27 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ function f() { var a; var a; } │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ function f() { var a; var a; } │ ^ @@ -469,14 +468,14 @@ function f() { var a; if (test) { var a; } } # Diagnostics ``` -invalid.jsonc:1:39 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:39 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ function f() { var a; if (test) { var a; } } │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ function f() { var a; if (test) { var a; } } │ ^ @@ -491,14 +490,14 @@ for (var a, a;;); # Diagnostics ``` -invalid.jsonc:1:13 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:13 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ for (var a, a;;); │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ for (var a, a;;); │ ^ @@ -513,14 +512,14 @@ for (;;){ var a, a,;} # Diagnostics ``` -invalid.jsonc:1:18 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsonc:1:18 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. > 1 │ for (;;){ var a, a,;} │ ^ - i 'a' is defined here. + i 'a' is defined here: > 1 │ for (;;){ var a, a,;} │ ^ diff --git a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid.ts b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid.ts similarity index 100% rename from crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid.ts rename to crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid.ts diff --git a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid.ts.snap b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid.ts.snap similarity index 64% rename from crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid.ts.snap rename to crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid.ts.snap index 5ca54236166..c720fc4bc2b 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/invalid.ts.snap +++ b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/invalid.ts.snap @@ -15,9 +15,9 @@ class C { # Diagnostics ``` -invalid.ts:4:7 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.ts:4:7 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Shouldn't redeclare 'a'. Consider to delete it or rename it + ! Shouldn't redeclare 'a'. Consider to delete it or rename it. 2 │ static { 3 │ var a; @@ -26,7 +26,7 @@ invalid.ts:4:7 lint/nursery/noRedeclaration ━━━━━━━━━━━━ 5 │ } 6 │ } - i 'a' is defined here. + i 'a' is defined here: 1 │ class C { 2 │ static { diff --git a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid-declaration-merging.ts b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/valid-declaration-merging.ts similarity index 100% rename from crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid-declaration-merging.ts rename to crates/rome_js_analyze/tests/specs/nursery/noRedeclare/valid-declaration-merging.ts diff --git a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid-declaration-merging.ts.snap b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/valid-declaration-merging.ts.snap similarity index 100% rename from crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid-declaration-merging.ts.snap rename to crates/rome_js_analyze/tests/specs/nursery/noRedeclare/valid-declaration-merging.ts.snap diff --git a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid-duplicate.ts b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/valid-duplicate.ts similarity index 100% rename from crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid-duplicate.ts rename to crates/rome_js_analyze/tests/specs/nursery/noRedeclare/valid-duplicate.ts diff --git a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid-duplicate.ts.snap b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/valid-duplicate.ts.snap similarity index 100% rename from crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid-duplicate.ts.snap rename to crates/rome_js_analyze/tests/specs/nursery/noRedeclare/valid-duplicate.ts.snap diff --git a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid.jsonc b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/valid.jsonc similarity index 100% rename from crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid.jsonc rename to crates/rome_js_analyze/tests/specs/nursery/noRedeclare/valid.jsonc diff --git a/crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid.jsonc.snap b/crates/rome_js_analyze/tests/specs/nursery/noRedeclare/valid.jsonc.snap similarity index 100% rename from crates/rome_js_analyze/tests/specs/nursery/noRedeclaration/valid.jsonc.snap rename to crates/rome_js_analyze/tests/specs/nursery/noRedeclare/valid.jsonc.snap diff --git a/crates/rome_service/src/configuration/linter/rules.rs b/crates/rome_service/src/configuration/linter/rules.rs index 82af5190ccb..d36f11e6489 100644 --- a/crates/rome_service/src/configuration/linter/rules.rs +++ b/crates/rome_service/src/configuration/linter/rules.rs @@ -1244,9 +1244,9 @@ pub struct Nursery { #[doc = "Disallow direct use of Object.prototype builtins."] #[serde(skip_serializing_if = "Option::is_none")] pub no_prototype_builtins: Option, - #[doc = "Eliminate variables that have multiple declarations in the same scope."] + #[doc = "Disallow variable, function, class, and type redeclarations in the same scope."] #[serde(skip_serializing_if = "Option::is_none")] - pub no_redeclaration: Option, + pub no_redeclare: Option, #[doc = "Enforce img alt prop does not contain the word \"image\", \"picture\", or \"photo\"."] #[serde(skip_serializing_if = "Option::is_none")] pub no_redundant_alt: Option, @@ -1345,7 +1345,7 @@ impl Nursery { "noParameterAssign", "noParameterProperties", "noPrototypeBuiltins", - "noRedeclaration", + "noRedeclare", "noRedundantAlt", "noRestrictedGlobals", "noSelfAssign", @@ -1390,7 +1390,7 @@ impl Nursery { "noNamespace", "noNoninteractiveElementToInteractiveRole", "noParameterAssign", - "noRedeclaration", + "noRedeclare", "noRedundantAlt", "noSelfAssign", "noSelfCompare", @@ -1602,7 +1602,7 @@ impl Nursery { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[18])); } } - if let Some(rule) = self.no_redeclaration.as_ref() { + if let Some(rule) = self.no_redeclare.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[19])); } @@ -1831,7 +1831,7 @@ impl Nursery { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[18])); } } - if let Some(rule) = self.no_redeclaration.as_ref() { + if let Some(rule) = self.no_redeclare.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[19])); } @@ -2013,7 +2013,7 @@ impl Nursery { "noParameterAssign" => self.no_parameter_assign.as_ref(), "noParameterProperties" => self.no_parameter_properties.as_ref(), "noPrototypeBuiltins" => self.no_prototype_builtins.as_ref(), - "noRedeclaration" => self.no_redeclaration.as_ref(), + "noRedeclare" => self.no_redeclare.as_ref(), "noRedundantAlt" => self.no_redundant_alt.as_ref(), "noRestrictedGlobals" => self.no_restricted_globals.as_ref(), "noSelfAssign" => self.no_self_assign.as_ref(), diff --git a/crates/rome_service/src/configuration/parse/json/rules.rs b/crates/rome_service/src/configuration/parse/json/rules.rs index c701844ed4d..cbdab4436a4 100644 --- a/crates/rome_service/src/configuration/parse/json/rules.rs +++ b/crates/rome_service/src/configuration/parse/json/rules.rs @@ -930,7 +930,7 @@ impl VisitNode for Nursery { "noParameterAssign", "noParameterProperties", "noPrototypeBuiltins", - "noRedeclaration", + "noRedeclare", "noRedundantAlt", "noRestrictedGlobals", "noSelfAssign", @@ -1317,16 +1317,16 @@ impl VisitNode for Nursery { )); } }, - "noRedeclaration" => match value { + "noRedeclare" => match value { AnyJsonValue::JsonStringValue(_) => { let mut configuration = RuleConfiguration::default(); self.map_to_known_string(&value, name_text, &mut configuration, diagnostics)?; - self.no_redeclaration = Some(configuration); + self.no_redeclare = Some(configuration); } AnyJsonValue::JsonObjectValue(_) => { let mut configuration = RuleConfiguration::default(); self.map_to_object(&value, name_text, &mut configuration, diagnostics)?; - self.no_redeclaration = Some(configuration); + self.no_redeclare = Some(configuration); } _ => { diagnostics.push(DeserializationDiagnostic::new_incorrect_type( diff --git a/editors/vscode/configuration_schema.json b/editors/vscode/configuration_schema.json index 27576db823b..b05d64211b8 100644 --- a/editors/vscode/configuration_schema.json +++ b/editors/vscode/configuration_schema.json @@ -615,8 +615,8 @@ { "type": "null" } ] }, - "noRedeclaration": { - "description": "Eliminate variables that have multiple declarations in the same scope.", + "noRedeclare": { + "description": "Disallow variable, function, class, and type redeclarations in the same scope.", "anyOf": [ { "$ref": "#/definitions/RuleConfiguration" }, { "type": "null" } diff --git a/npm/backend-jsonrpc/src/workspace.ts b/npm/backend-jsonrpc/src/workspace.ts index 3038d86f5f1..517704da473 100644 --- a/npm/backend-jsonrpc/src/workspace.ts +++ b/npm/backend-jsonrpc/src/workspace.ts @@ -433,9 +433,9 @@ export interface Nursery { */ noPrototypeBuiltins?: RuleConfiguration; /** - * Eliminate variables that have multiple declarations in the same scope. + * Disallow variable, function, class, and type redeclarations in the same scope. */ - noRedeclaration?: RuleConfiguration; + noRedeclare?: RuleConfiguration; /** * Enforce img alt prop does not contain the word "image", "picture", or "photo". */ @@ -936,7 +936,7 @@ export type Category = | "lint/nursery/noUselessCatch" | "lint/nursery/noParameterAssign" | "lint/nursery/noNamespace" - | "lint/nursery/noRedeclaration" + | "lint/nursery/noRedeclare" | "lint/nursery/useNamespaceKeyword" | "lint/performance/noDelete" | "lint/security/noDangerouslySetInnerHtml" diff --git a/npm/rome/configuration_schema.json b/npm/rome/configuration_schema.json index 27576db823b..b05d64211b8 100644 --- a/npm/rome/configuration_schema.json +++ b/npm/rome/configuration_schema.json @@ -615,8 +615,8 @@ { "type": "null" } ] }, - "noRedeclaration": { - "description": "Eliminate variables that have multiple declarations in the same scope.", + "noRedeclare": { + "description": "Disallow variable, function, class, and type redeclarations in the same scope.", "anyOf": [ { "$ref": "#/definitions/RuleConfiguration" }, { "type": "null" } diff --git a/website/src/pages/lint/rules/index.mdx b/website/src/pages/lint/rules/index.mdx index 2af37deb7d5..523db8450df 100644 --- a/website/src/pages/lint/rules/index.mdx +++ b/website/src/pages/lint/rules/index.mdx @@ -750,10 +750,10 @@ Disallow the use of parameter properties in class constructors. Disallow direct use of Object.prototype builtins.
-

- noRedeclaration +

+ noRedeclare

-Eliminate variables that have multiple declarations in the same scope. +Disallow variable, function, class, and type redeclarations in the same scope.

diff --git a/website/src/pages/lint/rules/noRedeclaration.md b/website/src/pages/lint/rules/noRedeclare.md similarity index 84% rename from website/src/pages/lint/rules/noRedeclaration.md rename to website/src/pages/lint/rules/noRedeclare.md index 3714adc00ef..13ec58c303c 100644 --- a/website/src/pages/lint/rules/noRedeclaration.md +++ b/website/src/pages/lint/rules/noRedeclare.md @@ -1,11 +1,13 @@ --- -title: Lint Rule noRedeclaration +title: Lint Rule noRedeclare parent: lint/rules/index --- -# noRedeclaration (since v12.0.0) +# noRedeclare (since v12.0.0) -Eliminate variables that have multiple declarations in the same scope. +Disallow variable, function, class, and type redeclarations in the same scope. + +Source: https://typescript-eslint.io/rules/no-redeclare ## Examples @@ -16,16 +18,16 @@ var a = 3; var a = 10; ``` -
nursery/noRedeclaration.js:2:5 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
nursery/noRedeclare.js:2:5 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
-   Shouldn't redeclare 'a'. Consider to delete it or rename it
+   Shouldn't redeclare 'a'. Consider to delete it or rename it.
   
     1 │ var a = 3;
   > 2 │ var a = 10;
        ^
     3 │ 
   
-   'a' is defined here.
+   'a' is defined here:
   
   > 1 │ var a = 3;
        ^
@@ -39,16 +41,16 @@ let a = 3;
 let a = 10;
 ```
 
-
nursery/noRedeclaration.js:2:5 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
nursery/noRedeclare.js:2:5 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
-   Shouldn't redeclare 'a'. Consider to delete it or rename it
+   Shouldn't redeclare 'a'. Consider to delete it or rename it.
   
     1 │ let a = 3;
   > 2 │ let a = 10;
        ^
     3 │ 
   
-   'a' is defined here.
+   'a' is defined here:
   
   > 1 │ let a = 3;
        ^
@@ -62,16 +64,16 @@ function f() {}
 function f() {}
 ```
 
-
nursery/noRedeclaration.js:2:10 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
nursery/noRedeclare.js:2:10 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
-   Shouldn't redeclare 'f'. Consider to delete it or rename it
+   Shouldn't redeclare 'f'. Consider to delete it or rename it.
   
     1 │ function f() {}
   > 2 │ function f() {}
             ^
     3 │ 
   
-   'f' is defined here.
+   'f' is defined here:
   
   > 1 │ function f() {}
             ^
@@ -89,9 +91,9 @@ class C {
 }
 ```
 
-
nursery/noRedeclaration.js:4:13 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
nursery/noRedeclare.js:4:13 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
-   Shouldn't redeclare 'c'. Consider to delete it or rename it
+   Shouldn't redeclare 'c'. Consider to delete it or rename it.
   
     2 │     static {
     3 │         var c = 3;
@@ -100,7 +102,7 @@ class C {
     5 │     }
     6 │ }
   
-   'c' is defined here.
+   'c' is defined here:
   
     1 │ class C {
     2 │     static {
@@ -116,16 +118,16 @@ type Person = { name: string; }
 class Person { name: string; }
 ```
 
-
nursery/noRedeclaration.js:2:7 lint/nursery/noRedeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
nursery/noRedeclare.js:2:7 lint/nursery/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
-   Shouldn't redeclare 'Person'. Consider to delete it or rename it
+   Shouldn't redeclare 'Person'. Consider to delete it or rename it.
   
     1 │ type Person = { name: string; }
   > 2 │ class Person { name: string; }
          ^^^^^^
     3 │ 
   
-   'Person' is defined here.
+   'Person' is defined here:
   
   > 1 │ type Person = { name: string; }
         ^^^^^^