From 9928298301a7cec0dfef0dcb786c065b5e08dfcd Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Wed, 19 May 2021 13:11:27 -0300 Subject: [PATCH] fix(`check-line-alignment`): add multiline type workaround (#744); fixes part of #743 Workaround for recursive fixing of multiline type alignment Co-authored-by: Renatho De Carli Rosa Co-authored-by: Brett Zamir --- README.md | 17 ++++---- src/alignTransform.js | 5 +++ test/rules/assertions/checkLineAlignment.js | 43 ++++++--------------- 3 files changed, 24 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index f70838715..96b15f52d 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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"] ```` diff --git a/src/alignTransform.js b/src/alignTransform.js index 85962cdce..99f84c65a 100644 --- a/src/alignTransform.js +++ b/src/alignTransform.js @@ -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, diff --git a/test/rules/assertions/checkLineAlignment.js b/test/rules/assertions/checkLineAlignment.js index 8e6c8577e..619911ea3 100644 --- a/test/rules/assertions/checkLineAlignment.js +++ b/test/rules/assertions/checkLineAlignment.js @@ -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: [ { @@ -1467,5 +1435,16 @@ export default { }, }], }, + { + code: ` + /** + * @param {{ + * ids: number[] + * }} params + */ + const fn = ({ids}) => {} + `, + options: ['always'], + }, ], };