From 52d7eff53820f2a0d22b3c80a1930a3a023b5cef Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sun, 18 Jul 2021 13:13:22 +0800 Subject: [PATCH] fix(`tag-lines`): allow `any` in `tags[tag].lines` option to allow lines per tag when otherwise blocked --- .README/rules/tag-lines.md | 2 +- README.md | 17 +++++++++++++++- src/rules/tagLines.js | 4 ++-- test/rules/assertions/tagLines.js | 33 +++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/.README/rules/tag-lines.md b/.README/rules/tag-lines.md index 53c80e3f5..db4771c4d 100644 --- a/.README/rules/tag-lines.md +++ b/.README/rules/tag-lines.md @@ -28,7 +28,7 @@ Overrides the default behavior depending on specific tags. An object whose keys are tag names and whose values are objects with the following keys: -1. `lines` - Set to `always` or `never` to override. +1. `lines` - Set to `always`, `never`, or `any` to override. 2. `count` - Overrides main `count` (for "always") ||| diff --git a/README.md b/README.md index 13edeaf5a..15ac135a2 100644 --- a/README.md +++ b/README.md @@ -19522,7 +19522,7 @@ Overrides the default behavior depending on specific tags. An object whose keys are tag names and whose values are objects with the following keys: -1. `lines` - Set to `always` or `never` to override. +1. `lines` - Set to `always`, `never`, or `any` to override. 2. `count` - Overrides main `count` (for "always") ||| @@ -19730,6 +19730,13 @@ The following patterns are not considered problems: */ // "jsdoc/tag-lines": ["error"|"warn", "never",{"tags":{"param":{"lines":"any"}}}] +/** + * Some description + * @param {string} a + * @param {number} b + */ +// "jsdoc/tag-lines": ["error"|"warn", "always",{"tags":{"param":{"lines":"any"}}}] + /** * Some description * @param {string} a @@ -19744,6 +19751,14 @@ The following patterns are not considered problems: */ // "jsdoc/tag-lines": ["error"|"warn", "never",{"tags":{"param":{"lines":"any"}}}] +/** + * Some description + * @param {number} a + * + * @param {number} b + */ +// "jsdoc/tag-lines": ["error"|"warn", "never",{"tags":{"param":{"lines":"any"}}}] + /** * Some description * @param {number} a diff --git a/src/rules/tagLines.js b/src/rules/tagLines.js index dede7835a..886dca228 100644 --- a/src/rules/tagLines.js +++ b/src/rules/tagLines.js @@ -23,7 +23,7 @@ export default iterateJsdoc(({ if (description) { reportIndex = null; } - if (lastTag && tags[lastTag.slice(1)]?.lines === 'always') { + if (lastTag && ['any', 'always'].includes(tags[lastTag.slice(1)]?.lines)) { return; } @@ -138,7 +138,7 @@ export default iterateJsdoc(({ type: 'integer', }, lines: { - enum: ['always', 'never'], + enum: ['always', 'never', 'any'], type: 'string', }, }, diff --git a/test/rules/assertions/tagLines.js b/test/rules/assertions/tagLines.js index e6092d000..cab0fb8ed 100644 --- a/test/rules/assertions/tagLines.js +++ b/test/rules/assertions/tagLines.js @@ -499,6 +499,22 @@ export default { }, }], }, + { + code: ` + /** + * Some description + * @param {string} a + * @param {number} b + */ + `, + options: ['always', { + tags: { + param: { + lines: 'any', + }, + }, + }], + }, { code: ` /** @@ -531,6 +547,23 @@ export default { }, }], }, + { + code: ` + /** + * Some description + * @param {number} a + * + * @param {number} b + */ + `, + options: ['never', { + tags: { + param: { + lines: 'any', + }, + }, + }], + }, { code: ` /**