Skip to content

Commit 2fd8ecc

Browse files
committed
fix(newline-afer-description): correctly treat carriage return immediately after newline as ending with a newline; fixes #437
Since `comment-parser` cuts off at newlines, we can get stuck with a carriage return at end when in a non-trimming rule; handle this.
1 parent 744f2cb commit 2fd8ecc

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4454,6 +4454,19 @@ function quux () {
44544454
44554455
}
44564456
// Options: ["always"]
4457+
4458+
/**
4459+
* Parses query string to object containing URL parameters
4460+
*
4461+
* @param queryString
4462+
* Input string
4463+
*
4464+
* @returns
4465+
* Object containing URL parameters
4466+
*/
4467+
export function parseQueryString(queryString: string): { [key: string]: string } { // <-- Line 10 that fails
4468+
4469+
}
44574470
````
44584471
44594472

src/rules/newlineAfterDescription.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default iterateJsdoc(({
2121
always = true;
2222
}
2323

24-
const descriptionEndsWithANewline = jsdoc.description.endsWith('\n');
24+
const descriptionEndsWithANewline = (/\n\r?$/).test(jsdoc.description);
2525

2626
if (always) {
2727
if (!descriptionEndsWithANewline) {

test/rules/assertions/newlineAfterDescription.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,26 @@ export default {
299299
'always',
300300
],
301301
},
302+
{
303+
// https://github.com/gajus/eslint-plugin-jsdoc/issues/437
304+
code: `
305+
/**\r
306+
* Parses query string to object containing URL parameters\r
307+
* \r
308+
* @param queryString\r
309+
* Input string\r
310+
* \r
311+
* @returns\r
312+
* Object containing URL parameters\r
313+
*/\r
314+
export function parseQueryString(queryString: string): { [key: string]: string } { // <-- Line 10 that fails\r
315+
\r
316+
}\r
317+
`,
318+
parser: require.resolve('@typescript-eslint/parser'),
319+
parserOptions: {
320+
sourceType: 'module',
321+
},
322+
},
302323
],
303324
};

0 commit comments

Comments
 (0)