Skip to content

Commit 6824ab6

Browse files
committed
fix(check-line-alignment): only treat hyphen as separator if followed by whitespace; fixes #1091
1 parent d730290 commit 6824ab6

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

docs/rules/check-line-alignment.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,5 +991,12 @@ function quux () {
991991
*/
992992
function quux () {}
993993
// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"wrapIndent":" "}]
994+
995+
/**
996+
* Returns cached value of negative scale of the world transform.
997+
*
998+
* @returns {number} -1 if world transform has negative scale, 1 otherwise.
999+
*/
1000+
// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
9941001
````
9951002

src/alignTransform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ const alignTransform = ({
306306
}
307307

308308
const postHyphenSpacing = customSpacings?.postHyphen ?? 1;
309-
const hyphenSpacing = /^\s*-\s*/u;
309+
const hyphenSpacing = /^\s*-\s+/u;
310310
tokens.description = tokens.description.replace(
311311
hyphenSpacing, '-' + ''.padStart(postHyphenSpacing, ' '),
312312
);

src/rules/checkLineAlignment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const checkNotAlignedPerTag = (utils, tag, customSpacings) => {
9494

9595
const postHyphenSpacing = customSpacings?.postHyphen ?? 1;
9696
const exactHyphenSpacing = new RegExp(`^\\s*-\\s{${postHyphenSpacing},${postHyphenSpacing}}(?!\\s)`, 'u');
97-
const hasNoHyphen = !(/^\s*-(?!$)/u).test(tokens.description);
97+
const hasNoHyphen = !(/^\s*-(?!$)(?=\s)/u).test(tokens.description);
9898
const hasExactHyphenSpacing = exactHyphenSpacing.test(
9999
tokens.description,
100100
);
@@ -144,7 +144,7 @@ const checkNotAlignedPerTag = (utils, tag, customSpacings) => {
144144
}
145145

146146
if (!hasExactHyphenSpacing) {
147-
const hyphenSpacing = /^\s*-\s*/u;
147+
const hyphenSpacing = /^\s*-\s+/u;
148148
tokens.description = tokens.description.replace(
149149
hyphenSpacing, '-' + ''.padStart(postHyphenSpacing, ' '),
150150
);

test/rules/assertions/checkLineAlignment.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,5 +2170,17 @@ export default {
21702170
},
21712171
],
21722172
},
2173+
{
2174+
code: `
2175+
/**
2176+
* Returns cached value of negative scale of the world transform.
2177+
*
2178+
* @returns {number} -1 if world transform has negative scale, 1 otherwise.
2179+
*/
2180+
`,
2181+
options: [
2182+
'never',
2183+
],
2184+
},
21732185
],
21742186
};

0 commit comments

Comments
 (0)