Skip to content

Commit

Permalink
fix(check-line-alignment): add multiline type workaround (#744); fi…
Browse files Browse the repository at this point in the history
…xes part of #743

Workaround for recursive fixing of multiline type alignment

Co-authored-by: Renatho De Carli Rosa <renatho@automattic.com>
Co-authored-by: Brett Zamir <brettz9@yahoo.com>
  • Loading branch information
3 people committed May 19, 2021
1 parent d39292f commit 9928298
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 41 deletions.
17 changes: 8 additions & 9 deletions README.md
Expand Up @@ -2320,15 +2320,6 @@ 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.

/**
* @param {{
* ids: number[]
* }} params
*/
const myMethod = ({ids}) => {}
// "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 @@ -2576,6 +2567,14 @@ const fn = ( lorem, sit ) => {}
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"customSpacings":{"postDelimiter":2,"postTag":3,"postType":2}}]

/**
* @param {{
* ids: number[]
* }} params
*/
const fn = ({ids}) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
````


Expand Down
5 changes: 5 additions & 0 deletions src/alignTransform.js
Expand Up @@ -101,6 +101,11 @@ const alignTransform = ({
}
}

// Todo: Avoid fixing alignment of blocks with multiline wrapping of type
if (tokens.tag === '' && tokens.type) {
return tokens;
}

const spacings = {
postDelimiter: customSpacings?.postDelimiter || 1,
postName: customSpacings?.postName || 1,
Expand Down
43 changes: 11 additions & 32 deletions test/rules/assertions/checkLineAlignment.js
Expand Up @@ -1057,38 +1057,6 @@ export default {
const fn = ( lorem, sit ) => {}
`,
},
{
/* eslint-disable no-tabs */
code: `
/**
* @param {{
* ids: number[]
* }} params
*/
const myMethod = ({ids}) => {}
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
],
options: ['always'],
output: `
/**
* @param {{
* ids: number[]
* }} params
*/
const myMethod = ({ids}) => {}
`,
/* eslint-enable no-tabs */
parser: require.resolve('@babel/eslint-parser'),
parserOptions: {
ecmaVersion: 2_021,
},
},
],
valid: [
{
Expand Down Expand Up @@ -1467,5 +1435,16 @@ export default {
},
}],
},
{
code: `
/**
* @param {{
* ids: number[]
* }} params
*/
const fn = ({ids}) => {}
`,
options: ['always'],
},
],
};

0 comments on commit 9928298

Please sign in to comment.