Skip to content

Commit

Permalink
fix(require-hyphen-before-param-description): regression failing to…
Browse files Browse the repository at this point in the history
… only check for hyphen at beginning; fixes #665
  • Loading branch information
brettz9 committed Jan 3, 2021
1 parent 62abd11 commit acc3fc1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -9572,6 +9572,14 @@ function quux () {
* @property foo - Foo.
*/
// Options: ["never",{"tags":{"*":"always"}}]
/** Entry point for module.
*
* @param {!Array<string>} argv Command-line arguments.
*/
function main(argv) {
};
// Options: ["never"]
````
Expand Down
4 changes: 2 additions & 2 deletions src/rules/requireHyphenBeforeParamDescription.js
Expand Up @@ -16,7 +16,7 @@ export default iterateJsdoc(({
return;
}

const startsWithHyphen = (/-/u).test(jsdocTag.description);
const startsWithHyphen = (/^\s*-/u).test(jsdocTag.description);
if (always) {
if (!startsWithHyphen) {
report(`There must be a hyphen before @${targetTagName} description.`, (fixer) => {
Expand All @@ -37,7 +37,7 @@ export default iterateJsdoc(({
}
} else if (startsWithHyphen) {
report(`There must be no hyphen before @${targetTagName} description.`, (fixer) => {
const [unwantedPart] = /\s*-\s*/u.exec(jsdocTag.description);
const [unwantedPart] = /^\s*-\s*/u.exec(jsdocTag.description);

const replacement = sourceCode
.getText(jsdocNode)
Expand Down
11 changes: 11 additions & 0 deletions test/rules/assertions/requireHyphenBeforeParamDescription.js
Expand Up @@ -488,5 +488,16 @@ export default {
}},
],
},
{
code: `
/** Entry point for module.
*
* @param {!Array<string>} argv Command-line arguments.
*/
function main(argv) {
};
`,
options: ['never'],
},
],
};

0 comments on commit acc3fc1

Please sign in to comment.