diff --git a/README.md b/README.md index f89b5023f..3db2b2e30 100644 --- a/README.md +++ b/README.md @@ -9432,6 +9432,15 @@ function quux () { // Options: ["never"] // Message: There must be no hyphen before @param description. +/** + * @param foo - Foo. + */ +function quux () { + +} +// Options: ["never"] +// Message: There must be no hyphen before @param description. + /** * @param foo - foo * @param foo foo @@ -9504,6 +9513,14 @@ function quux () { } // Options: ["always"] +/** + * @param foo - Foo. + */ +function quux () { + +} +// Options: ["always"] + /** * @param foo - Foo. * @returns {SomeType} A description. diff --git a/src/rules/requireHyphenBeforeParamDescription.js b/src/rules/requireHyphenBeforeParamDescription.js index fc78a38f5..8b5b00b6b 100644 --- a/src/rules/requireHyphenBeforeParamDescription.js +++ b/src/rules/requireHyphenBeforeParamDescription.js @@ -16,8 +16,9 @@ export default iterateJsdoc(({ return; } + const startsWithHyphen = (/-/u).test(jsdocTag.description); if (always) { - if (!jsdocTag.description.startsWith('-')) { + if (!startsWithHyphen) { report(`There must be a hyphen before @${targetTagName} description.`, (fixer) => { const lineIndex = jsdocTag.line; const sourceLines = sourceCode.getText(jsdocNode).split('\n'); @@ -34,9 +35,9 @@ export default iterateJsdoc(({ return fixer.replaceText(jsdocNode, replacement); }, jsdocTag); } - } else if (jsdocTag.description.startsWith('-')) { + } else if (startsWithHyphen) { report(`There must be no hyphen before @${targetTagName} description.`, (fixer) => { - const [unwantedPart] = /-\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 1960b7aff..503a7b8fd 100644 --- a/test/rules/assertions/requireHyphenBeforeParamDescription.js +++ b/test/rules/assertions/requireHyphenBeforeParamDescription.js @@ -145,6 +145,33 @@ export default { } `, }, + { + code: ` + /** + * @param foo - Foo. + */ + function quux () { + + } + `, + errors: [ + { + line: 3, + message: 'There must be no hyphen before @param description.', + }, + ], + options: [ + 'never', + ], + output: ` + /** + * @param foo Foo. + */ + function quux () { + + } + `, + }, { code: ` /** @@ -353,6 +380,19 @@ export default { 'always', ], }, + { + code: ` + /** + * @param foo - Foo. + */ + function quux () { + + } + `, + options: [ + 'always', + ], + }, { code: ` /**