Skip to content

Commit

Permalink
fix(check-param-names): failure to handle default params with spaci…
Browse files Browse the repository at this point in the history
…ng; closes #377
  • Loading branch information
OmgImAlexis authored and brettz9 committed Dec 2, 2019
1 parent 67df3dd commit c361ef6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
15 changes: 15 additions & 0 deletions README.md
Expand Up @@ -1515,6 +1515,14 @@ function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
// Message: Unexpected tag `@param`

/**
* @param {Error} error Exit code
* @param {number} [code = 1] Exit code
*/
function quux (error, cde = 1) {
};
// Message: Expected @param names to be "error, cde". Got "error, code".
````

The following patterns are not considered problems:
Expand Down Expand Up @@ -1603,6 +1611,13 @@ export class SomeClass {
*/
constructor(private property: string) {}
}

/**
* @param {Error} error Exit code
* @param {number} [code = 1] Exit code
*/
function quux (error, code = 1) {
};
````


Expand Down
4 changes: 2 additions & 2 deletions src/rules/checkParamNames.js
Expand Up @@ -40,10 +40,10 @@ const validateParameterNames = (targetTagName : string, functionParameterNames :
return false;
}

if (functionParameterName !== tag.name) {
if (functionParameterName !== tag.name.trim()) {
const expectedNames = functionParameterNames.join(', ');
const actualNames = paramTags.map(([, {name}]) => {
return name;
return name.trim();
}).join(', ');

report(
Expand Down
26 changes: 26 additions & 0 deletions test/rules/assertions/checkParamNames.js
Expand Up @@ -231,6 +231,22 @@ export default {
},
},
},
{
code: `
/**
* @param {Error} error Exit code
* @param {number} [code = 1] Exit code
*/
function quux (error, cde = 1) {
};
`,
errors: [
{
line: 4,
message: 'Expected @param names to be "error, cde". Got "error, code".',
},
],
},
],
valid: [
{
Expand Down Expand Up @@ -354,5 +370,15 @@ export default {
sourceType: 'module',
},
},
{
code: `
/**
* @param {Error} error Exit code
* @param {number} [code = 1] Exit code
*/
function quux (error, code = 1) {
};
`,
},
],
};

0 comments on commit c361ef6

Please sign in to comment.