Skip to content

Commit

Permalink
fix(check-line-alignment): preserve carriage returns; fixes #745
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Jul 9, 2021
1 parent 5a928db commit 27521d2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
21 changes: 21 additions & 0 deletions README.md
Expand Up @@ -2338,6 +2338,17 @@ const fn = ( lorem, sit ) => {}
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"customSpacings":{"postName":3}}]
// Message: Expected JSDoc block lines to not be aligned.


/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
````

The following patterns are not considered problems:
Expand Down Expand Up @@ -2593,6 +2604,16 @@ const fn = ( lorem, sit ) => {}
*/
const fn = ({ids}) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]


/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
````


Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -5,8 +5,8 @@
"url": "http://gajus.com"
},
"dependencies": {
"@es-joy/jsdoccomment": "^0.8.0",
"comment-parser": "1.1.5",
"@es-joy/jsdoccomment": "^0.9.0-alpha.1",
"comment-parser": "1.1.6-beta.0",
"debug": "^4.3.2",
"esquery": "^1.4.0",
"jsdoc-type-pratt-parser": "^1.0.4",
Expand Down
2 changes: 1 addition & 1 deletion src/alignTransform.js
Expand Up @@ -169,7 +169,7 @@ const alignTransform = ({

if (!intoTags) {
if (tokens.description === '') {
tokens.postDelimiter = '';
tokens.postDelimiter = tokens.postDelimiter === '\r' ? '\r' : '';
} else if (!preserveMainDescriptionPostDelimiter) {
tokens.postDelimiter = ' ';
}
Expand Down
42 changes: 42 additions & 0 deletions test/rules/assertions/checkLineAlignment.js
Expand Up @@ -1057,6 +1057,36 @@ export default {
const fn = ( lorem, sit ) => {}
`,
},
{
code: `\r
/**\r
* Function description.\r
*\r
* @param {string} lorem Description.\r
* @param {int} sit Description multi words.\r
*/\r
const fn = ( lorem, sit ) => {}\r
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
],
options: [
'always',
],
output: `\r
/**\r
* Function description.\r
*\r
* @param {string} lorem Description.\r
* @param {int} sit Description multi words.\r
*/\r
const fn = ( lorem, sit ) => {}\r
`,
},
],
valid: [
{
Expand Down Expand Up @@ -1446,5 +1476,17 @@ export default {
`,
options: ['always'],
},
{
code: `\r
/**\r
* Function description.\r
*\r
* @param {string} lorem Description.\r
* @param {int} sit Description multi words.\r
*/\r
const fn = ( lorem, sit ) => {}\r
`,
options: ['always'],
},
],
};

0 comments on commit 27521d2

Please sign in to comment.