Skip to content

Commit

Permalink
fix(newline-afer-description): correctly treat carriage return imme…
Browse files Browse the repository at this point in the history
…diately 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.
  • Loading branch information
brettz9 committed Nov 25, 2019
1 parent 744f2cb commit 2fd8ecc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -4454,6 +4454,19 @@ function quux () {
}
// Options: ["always"]
/**
* Parses query string to object containing URL parameters
*
* @param queryString
* Input string
*
* @returns
* Object containing URL parameters
*/
export function parseQueryString(queryString: string): { [key: string]: string } { // <-- Line 10 that fails
}
````
Expand Down
2 changes: 1 addition & 1 deletion src/rules/newlineAfterDescription.js
Expand Up @@ -21,7 +21,7 @@ export default iterateJsdoc(({
always = true;
}

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

if (always) {
if (!descriptionEndsWithANewline) {
Expand Down
21 changes: 21 additions & 0 deletions test/rules/assertions/newlineAfterDescription.js
Expand Up @@ -299,5 +299,26 @@ export default {
'always',
],
},
{
// https://github.com/gajus/eslint-plugin-jsdoc/issues/437
code: `
/**\r
* Parses query string to object containing URL parameters\r
* \r
* @param queryString\r
* Input string\r
* \r
* @returns\r
* Object containing URL parameters\r
*/\r
export function parseQueryString(queryString: string): { [key: string]: string } { // <-- Line 10 that fails\r
\r
}\r
`,
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
sourceType: 'module',
},
},
],
};

0 comments on commit 2fd8ecc

Please sign in to comment.