From d819a12b8a0f26294e851cf24b73d6741f02545e Mon Sep 17 00:00:00 2001 From: Victorien ELVINGER Date: Sun, 5 Mar 2023 15:57:35 +0100 Subject: [PATCH] docs(rome_js_analyze): improve noDuplicateParameters docs (#4257) --- .../suspicious/no_duplicate_parameters.rs | 25 +++++++---- .../suspicious/noDuplicateParameters.js.snap | 45 ++++++++++++++----- .../src/configuration/linter/rules.rs | 2 +- editors/vscode/configuration_schema.json | 2 +- npm/backend-jsonrpc/src/workspace.ts | 2 +- npm/rome/configuration_schema.json | 2 +- website/src/pages/lint/rules/index.mdx | 2 +- .../pages/lint/rules/noDuplicateParameters.md | 16 +++++-- 8 files changed, 69 insertions(+), 27 deletions(-) diff --git a/crates/rome_js_analyze/src/semantic_analyzers/suspicious/no_duplicate_parameters.rs b/crates/rome_js_analyze/src/semantic_analyzers/suspicious/no_duplicate_parameters.rs index e132a85ff0a..ab5426b39c7 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/suspicious/no_duplicate_parameters.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/suspicious/no_duplicate_parameters.rs @@ -10,7 +10,13 @@ use rome_rowan::{declare_node_union, AstNode}; use rustc_hash::FxHashSet; declare_rule! { - /// Disallow duplicate function arguments name. + /// Disallow duplicate function parameter name. + /// + /// If more than one parameter has the same name in a function definition, + /// the last occurrence overrides the preceding occurrences. + /// A duplicated name might be a typing error. + /// + /// Source: https://eslint.org/docs/latest/rules/no-dupe-args /// /// ## Examples /// @@ -70,13 +76,16 @@ impl Rule for NoDuplicateParameters { fn diagnostic(_: &RuleContext, state: &Self::State) -> Option { let binding_syntax_node = state; - Some(RuleDiagnostic::new( - rule_category!(), - binding_syntax_node.syntax().text_trimmed_range(), - markup! { - "Duplicate argument name" - }, - )) + Some( + RuleDiagnostic::new( + rule_category!(), + binding_syntax_node.syntax().text_trimmed_range(), + markup! { + "Duplicate parameter name." + }, + ) + .note("The parameter overrides a preceding parameter by using the same name."), + ) } } diff --git a/crates/rome_js_analyze/tests/specs/suspicious/noDuplicateParameters.js.snap b/crates/rome_js_analyze/tests/specs/suspicious/noDuplicateParameters.js.snap index 3b90c43f3b6..b43061be63e 100644 --- a/crates/rome_js_analyze/tests/specs/suspicious/noDuplicateParameters.js.snap +++ b/crates/rome_js_analyze/tests/specs/suspicious/noDuplicateParameters.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_analyze/tests/spec_tests.rs +assertion_line: 91 expression: noDuplicateParameters.js --- # Input @@ -45,7 +46,7 @@ export function f2(a, b, c = (a, b, b) => {}) {} ``` noDuplicateParameters.js:9:18 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Duplicate argument name + ! Duplicate parameter name. 7 │ function test(a = function (a) {}) {} 8 │ // invalid @@ -54,13 +55,15 @@ noDuplicateParameters.js:9:18 lint/suspicious/noDuplicateParameters ━━━━ 10 │ 11 │ function c(a, a, a) {} + i The parameter overrides a preceding parameter by using the same name. + ``` ``` noDuplicateParameters.js:11:15 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Duplicate argument name + ! Duplicate parameter name. 9 │ function b(a, b, b) {} 10 │ @@ -69,13 +72,15 @@ noDuplicateParameters.js:11:15 lint/suspicious/noDuplicateParameters ━━━ 12 │ 13 │ const d = (a, b, a) => {}; + i The parameter overrides a preceding parameter by using the same name. + ``` ``` noDuplicateParameters.js:13:18 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Duplicate argument name + ! Duplicate parameter name. 11 │ function c(a, a, a) {} 12 │ @@ -84,13 +89,15 @@ noDuplicateParameters.js:13:18 lint/suspicious/noDuplicateParameters ━━━ 14 │ 15 │ function e(a, b, a, b) {} + i The parameter overrides a preceding parameter by using the same name. + ``` ``` noDuplicateParameters.js:15:18 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Duplicate argument name + ! Duplicate parameter name. 13 │ const d = (a, b, a) => {}; 14 │ @@ -99,13 +106,15 @@ noDuplicateParameters.js:15:18 lint/suspicious/noDuplicateParameters ━━━ 16 │ 17 │ var f = function (a, b, b) {}; + i The parameter overrides a preceding parameter by using the same name. + ``` ``` noDuplicateParameters.js:17:25 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Duplicate argument name + ! Duplicate parameter name. 15 │ function e(a, b, a, b) {} 16 │ @@ -114,13 +123,15 @@ noDuplicateParameters.js:17:25 lint/suspicious/noDuplicateParameters ━━━ 18 │ 19 │ class G { + i The parameter overrides a preceding parameter by using the same name. + ``` ``` noDuplicateParameters.js:20:9 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Duplicate argument name + ! Duplicate parameter name. 19 │ class G { > 20 │ ggg(a, a, a) {} @@ -128,13 +139,15 @@ noDuplicateParameters.js:20:9 lint/suspicious/noDuplicateParameters ━━━━ 21 │ } 22 │ + i The parameter overrides a preceding parameter by using the same name. + ``` ``` noDuplicateParameters.js:24:18 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Duplicate argument name + ! Duplicate parameter name. 23 │ let objectMethods = { > 24 │ method(a, b, c, c) { @@ -142,13 +155,15 @@ noDuplicateParameters.js:24:18 lint/suspicious/noDuplicateParameters ━━━ 25 │ 26 │ } + i The parameter overrides a preceding parameter by using the same name. + ``` ``` noDuplicateParameters.js:29:25 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Duplicate argument name + ! Duplicate parameter name. 27 │ } 28 │ @@ -157,13 +172,15 @@ noDuplicateParameters.js:29:25 lint/suspicious/noDuplicateParameters ━━━ 30 │ 31 │ export default function (a, b, a, a) {} + i The parameter overrides a preceding parameter by using the same name. + ``` ``` noDuplicateParameters.js:31:32 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Duplicate argument name + ! Duplicate parameter name. 29 │ var h = function (a, b, a) {}; 30 │ @@ -172,13 +189,15 @@ noDuplicateParameters.js:31:32 lint/suspicious/noDuplicateParameters ━━━ 32 │ function f({ test: res = 3 }, res) {} 33 │ + i The parameter overrides a preceding parameter by using the same name. + ``` ``` noDuplicateParameters.js:32:31 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Duplicate argument name + ! Duplicate parameter name. 31 │ export default function (a, b, a, a) {} > 32 │ function f({ test: res = 3 }, res) {} @@ -186,13 +205,15 @@ noDuplicateParameters.js:32:31 lint/suspicious/noDuplicateParameters ━━━ 33 │ 34 │ export function f2(a, b, c = (a, b, b) => {}) {} + i The parameter overrides a preceding parameter by using the same name. + ``` ``` noDuplicateParameters.js:34:37 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Duplicate argument name + ! Duplicate parameter name. 32 │ function f({ test: res = 3 }, res) {} 33 │ @@ -200,6 +221,8 @@ noDuplicateParameters.js:34:37 lint/suspicious/noDuplicateParameters ━━━ │ ^ 35 │ + i The parameter overrides a preceding parameter by using the same name. + ``` diff --git a/crates/rome_service/src/configuration/linter/rules.rs b/crates/rome_service/src/configuration/linter/rules.rs index 80e72bf5b06..3d24207b8b8 100644 --- a/crates/rome_service/src/configuration/linter/rules.rs +++ b/crates/rome_service/src/configuration/linter/rules.rs @@ -2595,7 +2595,7 @@ pub struct Suspicious { #[doc = "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."] #[serde(skip_serializing_if = "Option::is_none")] pub no_duplicate_object_keys: Option, - #[doc = "Disallow duplicate function arguments name."] + #[doc = "Disallow duplicate function parameter name."] #[serde(skip_serializing_if = "Option::is_none")] pub no_duplicate_parameters: Option, #[doc = "Disallow the declaration of empty interfaces."] diff --git a/editors/vscode/configuration_schema.json b/editors/vscode/configuration_schema.json index 6c131df6ae3..d239b1bc986 100644 --- a/editors/vscode/configuration_schema.json +++ b/editors/vscode/configuration_schema.json @@ -1129,7 +1129,7 @@ ] }, "noDuplicateParameters": { - "description": "Disallow duplicate function arguments name.", + "description": "Disallow duplicate function parameter name.", "anyOf": [ { "$ref": "#/definitions/RuleConfiguration" }, { "type": "null" } diff --git a/npm/backend-jsonrpc/src/workspace.ts b/npm/backend-jsonrpc/src/workspace.ts index c34345423a7..1fdfea3b76d 100644 --- a/npm/backend-jsonrpc/src/workspace.ts +++ b/npm/backend-jsonrpc/src/workspace.ts @@ -701,7 +701,7 @@ export interface Suspicious { */ noDuplicateObjectKeys?: RuleConfiguration; /** - * Disallow duplicate function arguments name. + * Disallow duplicate function parameter name. */ noDuplicateParameters?: RuleConfiguration; /** diff --git a/npm/rome/configuration_schema.json b/npm/rome/configuration_schema.json index 6c131df6ae3..d239b1bc986 100644 --- a/npm/rome/configuration_schema.json +++ b/npm/rome/configuration_schema.json @@ -1129,7 +1129,7 @@ ] }, "noDuplicateParameters": { - "description": "Disallow duplicate function arguments name.", + "description": "Disallow duplicate function parameter name.", "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 d8f800a77a9..6b5ee5d4c4e 100644 --- a/website/src/pages/lint/rules/index.mdx +++ b/website/src/pages/lint/rules/index.mdx @@ -531,7 +531,7 @@ If an object property with the same name is defined multiple times (except when noDuplicateParameters recommended -Disallow duplicate function arguments name. +Disallow duplicate function parameter name.

diff --git a/website/src/pages/lint/rules/noDuplicateParameters.md b/website/src/pages/lint/rules/noDuplicateParameters.md index ffd68a8d3f2..d5d620ade4a 100644 --- a/website/src/pages/lint/rules/noDuplicateParameters.md +++ b/website/src/pages/lint/rules/noDuplicateParameters.md @@ -7,7 +7,13 @@ parent: lint/rules/index > This rule is recommended by Rome. -Disallow duplicate function arguments name. +Disallow duplicate function parameter name. + +If more than one parameter has the same name in a function definition, +the last occurrence overrides the preceding occurrences. +A duplicated name might be a typing error. + +Source: https://eslint.org/docs/latest/rules/no-dupe-args ## Examples @@ -19,12 +25,14 @@ var f = function(a, b, b) {}
suspicious/noDuplicateParameters.js:1:24 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━
 
-   Duplicate argument name
+   Duplicate parameter name.
   
   > 1 │ var f = function(a, b, b) {}
                           ^
     2 │ 
   
+   The parameter overrides a preceding parameter by using the same name.
+  
 
```jsx @@ -33,12 +41,14 @@ function b(a, b, b) {}
suspicious/noDuplicateParameters.js:1:18 lint/suspicious/noDuplicateParameters ━━━━━━━━━━━━━━━━━━━━━
 
-   Duplicate argument name
+   Duplicate parameter name.
   
   > 1 │ function b(a, b, b) {}
                     ^
     2 │ 
   
+   The parameter overrides a preceding parameter by using the same name.
+  
 
### Valid