Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
docs(rome_js_analyze): improve noDuplicateParameters docs (#4257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos authored and ematipico committed Mar 10, 2023
1 parent 667974b commit d819a12
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -70,13 +76,16 @@ impl Rule for NoDuplicateParameters {

fn diagnostic(_: &RuleContext<Self>, state: &Self::State) -> Option<RuleDiagnostic> {
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."),
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
assertion_line: 91
expression: noDuplicateParameters.js
---
# Input
Expand Down Expand Up @@ -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
Expand All @@ -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 │
Expand All @@ -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 │
Expand All @@ -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 │
Expand All @@ -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 │
Expand All @@ -114,41 +123,47 @@ 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) {}
│ ^
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) {
│ ^
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 │
Expand All @@ -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 │
Expand All @@ -172,34 +189,40 @@ 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) {}
│ ^^^
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 │
> 34 │ export function f2(a, b, c = (a, b, b) => {}) {}
│ ^
35 │
i The parameter overrides a preceding parameter by using the same name.
```

Expand Down
2 changes: 1 addition & 1 deletion crates/rome_service/src/configuration/linter/rules.rs

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

2 changes: 1 addition & 1 deletion editors/vscode/configuration_schema.json

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

2 changes: 1 addition & 1 deletion npm/backend-jsonrpc/src/workspace.ts

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

2 changes: 1 addition & 1 deletion npm/rome/configuration_schema.json

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

2 changes: 1 addition & 1 deletion website/src/pages/lint/rules/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ If an object property with the same name is defined multiple times (except when
<a href="/lint/rules/noDuplicateParameters">noDuplicateParameters</a>
<span class="recommended">recommended</span>
</h3>
Disallow duplicate function arguments name.
Disallow duplicate function parameter name.
</section>
<section class="rule">
<h3 data-toc-exclude id="noEmptyInterface">
Expand Down
16 changes: 13 additions & 3 deletions website/src/pages/lint/rules/noDuplicateParameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -19,12 +25,14 @@ var f = function(a, b, b) {}

<pre class="language-text"><code class="language-text">suspicious/noDuplicateParameters.js:1:24 <a href="https://docs.rome.tools/lint/rules/noDuplicateParameters">lint/suspicious/noDuplicateParameters</a> ━━━━━━━━━━━━━━━━━━━━━

<strong><span style="color: Tomato;"> </span></strong><strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Duplicate argument name</span>
<strong><span style="color: Tomato;"> </span></strong><strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Duplicate parameter name.</span>

<strong><span style="color: Tomato;"> </span></strong><strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>var f = function(a, b, b) {}
<strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong>
<strong>2 │ </strong>

<strong><span style="color: rgb(38, 148, 255);"> </span></strong><strong><span style="color: rgb(38, 148, 255);">ℹ</span></strong> <span style="color: rgb(38, 148, 255);">The parameter overrides a preceding parameter by using the same name.</span>

</code></pre>

```jsx
Expand All @@ -33,12 +41,14 @@ function b(a, b, b) {}

<pre class="language-text"><code class="language-text">suspicious/noDuplicateParameters.js:1:18 <a href="https://docs.rome.tools/lint/rules/noDuplicateParameters">lint/suspicious/noDuplicateParameters</a> ━━━━━━━━━━━━━━━━━━━━━

<strong><span style="color: Tomato;"> </span></strong><strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Duplicate argument name</span>
<strong><span style="color: Tomato;"> </span></strong><strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Duplicate parameter name.</span>

<strong><span style="color: Tomato;"> </span></strong><strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>function b(a, b, b) {}
<strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong>
<strong>2 │ </strong>

<strong><span style="color: rgb(38, 148, 255);"> </span></strong><strong><span style="color: rgb(38, 148, 255);">ℹ</span></strong> <span style="color: rgb(38, 148, 255);">The parameter overrides a preceding parameter by using the same name.</span>

</code></pre>

### Valid
Expand Down

0 comments on commit d819a12

Please sign in to comment.