From ab1ab10666ea8f9f1abfd5b897ebb9fd4f6d9d5e Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 11 Feb 2023 08:03:13 -0700 Subject: [PATCH] fix(`check-line-alignment`): avoid adding whitespace if hyphen at end of line; fixes #983 --- README.md | 6 ++++++ src/rules/checkLineAlignment.js | 2 +- test/rules/assertions/checkLineAlignment.js | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2631b212e..a7a054495 100644 --- a/README.md +++ b/README.md @@ -2864,6 +2864,12 @@ const fn = ( lorem, sit ) => {}; */ const fn = ( a, b ) => {}; // "jsdoc/check-line-alignment": ["error"|"warn", "always"] + +/** + * @param {string|string[]|TemplateResult|TemplateResult[]} event.detail.description - + * Notification description + */ +function quux () {} ```` diff --git a/src/rules/checkLineAlignment.js b/src/rules/checkLineAlignment.js index fb20a0632..12435bc54 100644 --- a/src/rules/checkLineAlignment.js +++ b/src/rules/checkLineAlignment.js @@ -66,7 +66,7 @@ const checkNotAlignedPerTag = (utils, tag, customSpacings) => { const postHyphenSpacing = customSpacings?.postHyphen ?? 1; const exactHyphenSpacing = new RegExp(`^\\s*-\\s{${postHyphenSpacing},${postHyphenSpacing}}(?!\\s)`, 'u'); - const hasNoHyphen = !(/^\s*-/u).test(tokens.description); + const hasNoHyphen = !(/^\s*-(?!$)/u).test(tokens.description); const hasExactHyphenSpacing = exactHyphenSpacing.test( tokens.description, ); diff --git a/test/rules/assertions/checkLineAlignment.js b/test/rules/assertions/checkLineAlignment.js index 83c83b182..1e928e447 100644 --- a/test/rules/assertions/checkLineAlignment.js +++ b/test/rules/assertions/checkLineAlignment.js @@ -1909,5 +1909,14 @@ export default { 'always', ], }, + { + code: ` + /** + * @param {string|string[]|TemplateResult|TemplateResult[]} event.detail.description - + * Notification description + */ + function quux () {} + `, + }, ], };