Skip to content

Commit ecbbf5d

Browse files
authored
Merge pull request #231 from brettz9/duplicate-params
Duplicate params
2 parents 81241b8 + 94df60f commit ecbbf5d

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,33 @@ function quux (foo) {
689689

690690
}
691691
// Message: @param "bar" does not match an existing function parameter.
692+
693+
/**
694+
* @param foo
695+
* @param foo
696+
*/
697+
function quux (foo) {
698+
699+
}
700+
// Message: Duplicate @param "foo"
701+
702+
/**
703+
* @param foo
704+
* @param foo
705+
*/
706+
function quux (foo, bar) {
707+
708+
}
709+
// Message: Duplicate @param "foo"
710+
711+
/**
712+
* @param foo
713+
* @param foo
714+
*/
715+
function quux (foo, foo) {
716+
717+
}
718+
// Message: Duplicate @param "foo"
692719
````
693720

694721
The following patterns are not considered problems:

src/rules/checkParamNames.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ const validateParameterNames = (targetTagName : string, functionParameterNames :
1010
});
1111

1212
return paramTags.some((tag, index) => {
13+
if (paramTags.some((tg, idx) => {
14+
return tg.name === tag.name && idx !== index;
15+
})) {
16+
report('Duplicate @' + targetTagName + ' "' + tag.name + '"');
17+
18+
return true;
19+
}
1320
const functionParameterName = functionParameterNames[index];
1421

1522
if (!functionParameterName) {

test/rules/assertions/checkParamNames.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,54 @@ export default {
117117
message: '@param "bar" does not match an existing function parameter.'
118118
}
119119
]
120+
},
121+
{
122+
code: `
123+
/**
124+
* @param foo
125+
* @param foo
126+
*/
127+
function quux (foo) {
128+
129+
}
130+
`,
131+
errors: [
132+
{
133+
message: 'Duplicate @param "foo"'
134+
}
135+
]
136+
},
137+
{
138+
code: `
139+
/**
140+
* @param foo
141+
* @param foo
142+
*/
143+
function quux (foo, bar) {
144+
145+
}
146+
`,
147+
errors: [
148+
{
149+
message: 'Duplicate @param "foo"'
150+
}
151+
]
152+
},
153+
{
154+
code: `
155+
/**
156+
* @param foo
157+
* @param foo
158+
*/
159+
function quux (foo, foo) {
160+
161+
}
162+
`,
163+
errors: [
164+
{
165+
message: 'Duplicate @param "foo"'
166+
}
167+
]
120168
}
121169
],
122170
valid: [

0 commit comments

Comments
 (0)