Skip to content

Commit 37df54d

Browse files
davidmurdochbrettz9
authored andcommitted
feat(check-line-alignment): add disableWrapIndent` option
1 parent e9a9b74 commit 37df54d

File tree

5 files changed

+80
-6
lines changed

5 files changed

+80
-6
lines changed

.README/rules/check-line-alignment.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ main description. If `false` or unset, will be set to a single space.
4949
The indent that will be applied for tag text after the first line.
5050
Default to the empty string (no indent).
5151

52+
### `disableWrapIndent`
53+
54+
Disables `wrapIndent`; existing wrap indentation is preserved without changes.
55+
5256
## Context and settings
5357

5458
|||
5559
|---|---|
5660
|Context|everywhere|
57-
|Options|string ("always", "never", "any") followed by object with `customSpacings`, `preserveMainDescriptionPostDelimiter`, `tags`, `wrapIndent`|
61+
|Options|string ("always", "never", "any") followed by object with `customSpacings`, `preserveMainDescriptionPostDelimiter`, `tags`, `wrapIndent`, `disableWrapIndent`|
5862
|Tags|`param`, `property`, `returns` and others added by `tags`|
5963
|Aliases|`arg`, `argument`, `prop`, `return`|
6064
|Recommended|false|

docs/rules/check-line-alignment.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [`customSpacings`](#user-content-check-line-alignment-options-customspacings)
99
* [`preserveMainDescriptionPostDelimiter`](#user-content-check-line-alignment-options-preservemaindescriptionpostdelimiter)
1010
* [`wrapIndent`](#user-content-check-line-alignment-options-wrapindent)
11+
* [`disableWrapIndent`](#user-content-check-line-alignment-options-disablewrapindent)
1112
* [Context and settings](#user-content-check-line-alignment-context-and-settings)
1213
* [Failing examples](#user-content-check-line-alignment-failing-examples)
1314
* [Passing examples](#user-content-check-line-alignment-passing-examples)
@@ -72,14 +73,20 @@ main description. If `false` or unset, will be set to a single space.
7273
The indent that will be applied for tag text after the first line.
7374
Default to the empty string (no indent).
7475

76+
<a name="user-content-check-line-alignment-options-disablewrapindent"></a>
77+
<a name="check-line-alignment-options-disablewrapindent"></a>
78+
### <code>disableWrapIndent</code>
79+
80+
Disables `wrapIndent`; existing wrap indentation is preserved without changes.
81+
7582
<a name="user-content-check-line-alignment-context-and-settings"></a>
7683
<a name="check-line-alignment-context-and-settings"></a>
7784
## Context and settings
7885

7986
|||
8087
|---|---|
8188
|Context|everywhere|
82-
|Options|string ("always", "never", "any") followed by object with `customSpacings`, `preserveMainDescriptionPostDelimiter`, `tags`, `wrapIndent`|
89+
|Options|string ("always", "never", "any") followed by object with `customSpacings`, `preserveMainDescriptionPostDelimiter`, `tags`, `wrapIndent`, `disableWrapIndent`|
8390
|Tags|`param`, `property`, `returns` and others added by `tags`|
8491
|Aliases|`arg`, `argument`, `prop`, `return`|
8592
|Recommended|false|
@@ -998,5 +1005,23 @@ function quux () {}
9981005
* @returns {number} -1 if world transform has negative scale, 1 otherwise.
9991006
*/
10001007
// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
1008+
1009+
/**
1010+
* @param {string} lorem Description
1011+
* with multiple lines preserving existing indentation when wrapIndent is disabled.
1012+
*/
1013+
function quux () {
1014+
}
1015+
// "jsdoc/check-line-alignment": ["error"|"warn", "any",{"disableWrapIndent":true}]
1016+
1017+
/**
1018+
* Function description with disableWrapIndent true, but wrapIndent defined.
1019+
* Preserves existing indentation regardless of wrapIndent value.
1020+
*
1021+
* @param {string} lorem Description
1022+
* with multiple lines.
1023+
*/
1024+
const fn = ( lorem ) => {}
1025+
// "jsdoc/check-line-alignment": ["error"|"warn", "any",{"disableWrapIndent":true,"wrapIndent":" "}]
10011026
````
10021027

src/alignTransform.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ const space = (len) => {
151151
* indent: string,
152152
* preserveMainDescriptionPostDelimiter: boolean,
153153
* wrapIndent: string,
154+
* disableWrapIndent: boolean,
154155
* }} cfg
155156
* @returns {(
156157
* block: import('comment-parser').Block
@@ -162,6 +163,7 @@ const alignTransform = ({
162163
indent,
163164
preserveMainDescriptionPostDelimiter,
164165
wrapIndent,
166+
disableWrapIndent,
165167
}) => {
166168
let intoTags = false;
167169
/** @type {Width} */
@@ -314,7 +316,7 @@ const alignTransform = ({
314316
// Not align.
315317
if (shouldAlign(tags, index, source)) {
316318
alignTokens(tokens, typelessInfo);
317-
if (indentTag) {
319+
if (!disableWrapIndent && indentTag) {
318320
tokens.postDelimiter += wrapIndent;
319321
}
320322
}
@@ -340,10 +342,10 @@ const alignTransform = ({
340342
return rewireSource({
341343
...fields,
342344
source: source.map((line, index) => {
343-
const indentTag = tagIndentMode && !line.tokens.tag && line.tokens.description;
345+
const indentTag = !disableWrapIndent && tagIndentMode && !line.tokens.tag && line.tokens.description;
344346
const ret = update(line, index, source, typelessInfo, indentTag);
345347

346-
if (line.tokens.tag) {
348+
if (!disableWrapIndent && line.tokens.tag) {
347349
tagIndentMode = true;
348350
}
349351

src/rules/checkLineAlignment.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const checkNotAlignedPerTag = (utils, tag, customSpacings) => {
169169
* @param {string[]} cfg.tags
170170
* @param {import('../iterateJsdoc.js').Utils} cfg.utils
171171
* @param {string} cfg.wrapIndent
172+
* @param {boolean} cfg.disableWrapIndent
172173
* @returns {void}
173174
*/
174175
const checkAlignment = ({
@@ -181,6 +182,7 @@ const checkAlignment = ({
181182
tags,
182183
utils,
183184
wrapIndent,
185+
disableWrapIndent,
184186
}) => {
185187
const transform = commentFlow(
186188
alignTransform({
@@ -189,6 +191,7 @@ const checkAlignment = ({
189191
preserveMainDescriptionPostDelimiter,
190192
tags,
191193
wrapIndent,
194+
disableWrapIndent,
192195
}),
193196
);
194197
const transformedJsdoc = transform(jsdoc);
@@ -228,6 +231,7 @@ export default iterateJsdoc(({
228231
preserveMainDescriptionPostDelimiter,
229232
customSpacings,
230233
wrapIndent = '',
234+
disableWrapIndent = false,
231235
} = context.options[1] || {};
232236

233237
if (context.options[0] === 'always') {
@@ -253,6 +257,7 @@ export default iterateJsdoc(({
253257
tags: applicableTags,
254258
utils,
255259
wrapIndent,
260+
disableWrapIndent,
256261
});
257262

258263
return;
@@ -293,7 +298,7 @@ export default iterateJsdoc(({
293298
}
294299

295300
// Don't include a single separating space/tab
296-
if (tokens.postDelimiter.slice(1) !== wrapIndent) {
301+
if (!disableWrapIndent && tokens.postDelimiter.slice(1) !== wrapIndent) {
297302
utils.reportJSDoc('Expected wrap indent', {
298303
line: tag.source[0].number + idx,
299304
}, () => {
@@ -355,6 +360,9 @@ export default iterateJsdoc(({
355360
wrapIndent: {
356361
type: 'string',
357362
},
363+
disableWrapIndent: {
364+
type: 'boolean',
365+
},
358366
},
359367
type: 'object',
360368
},

test/rules/assertions/checkLineAlignment.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,5 +2182,40 @@ export default {
21822182
'never',
21832183
],
21842184
},
2185+
{
2186+
code: `
2187+
/**
2188+
* @param {string} lorem Description
2189+
* with multiple lines preserving existing indentation when wrapIndent is disabled.
2190+
*/
2191+
function quux () {
2192+
}
2193+
`,
2194+
options: [
2195+
'any',
2196+
{
2197+
disableWrapIndent: true,
2198+
},
2199+
],
2200+
},
2201+
{
2202+
code: `
2203+
/**
2204+
* Function description with disableWrapIndent true, but wrapIndent defined.
2205+
* Preserves existing indentation regardless of wrapIndent value.
2206+
*
2207+
* @param {string} lorem Description
2208+
* with multiple lines.
2209+
*/
2210+
const fn = ( lorem ) => {}
2211+
`,
2212+
options: [
2213+
'any',
2214+
{
2215+
disableWrapIndent: true,
2216+
wrapIndent: ' ',
2217+
},
2218+
],
2219+
},
21852220
],
21862221
};

0 commit comments

Comments
 (0)