From acc3fc1c577527ade66f2fa0f4001ea717bfb03a Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sun, 3 Jan 2021 23:10:02 +0800 Subject: [PATCH] fix(`require-hyphen-before-param-description`): regression failing to only check for hyphen at beginning; fixes #665 --- README.md | 8 ++++++++ src/rules/requireHyphenBeforeParamDescription.js | 4 ++-- .../assertions/requireHyphenBeforeParamDescription.js | 11 +++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f76967b2e..f2d1ab62c 100644 --- a/README.md +++ b/README.md @@ -9572,6 +9572,14 @@ function quux () { * @property foo - Foo. */ // Options: ["never",{"tags":{"*":"always"}}] + +/** Entry point for module. + * + * @param {!Array} argv Command-line arguments. + */ +function main(argv) { +}; +// Options: ["never"] ```` diff --git a/src/rules/requireHyphenBeforeParamDescription.js b/src/rules/requireHyphenBeforeParamDescription.js index 8b5b00b6b..2c560f30f 100644 --- a/src/rules/requireHyphenBeforeParamDescription.js +++ b/src/rules/requireHyphenBeforeParamDescription.js @@ -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) => { @@ -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) diff --git a/test/rules/assertions/requireHyphenBeforeParamDescription.js b/test/rules/assertions/requireHyphenBeforeParamDescription.js index 503a7b8fd..2efc93fc4 100644 --- a/test/rules/assertions/requireHyphenBeforeParamDescription.js +++ b/test/rules/assertions/requireHyphenBeforeParamDescription.js @@ -488,5 +488,16 @@ export default { }}, ], }, + { + code: ` + /** Entry point for module. + * + * @param {!Array} argv Command-line arguments. + */ + function main(argv) { + }; + `, + options: ['never'], + }, ], };