Skip to content

Commit 933b74a

Browse files
ahwayakchihchiawendt
authored andcommitted
fix(check-indentation): update README, default to false, lint ok
Ideally this would default to `true`, but that could break existing setups.
1 parent 6de2256 commit 933b74a

File tree

4 files changed

+91
-44
lines changed

4 files changed

+91
-44
lines changed

.README/rules/check-indentation.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,33 @@
22

33
Reports invalid padding inside JSDoc block.
44

5+
#### Options
6+
7+
This rule has an object option.
8+
9+
##### `excludeExamples`
10+
11+
This boolean property allows to "hide" example code from reports.
12+
13+
By default, whole JSDoc block is checked for invalid padding.
14+
That includes example blocks too, which may get in the way of adding full,
15+
readable examples of code without ending up with multiple linting issues.
16+
17+
When enabled, following code will lint without any padding issue:
18+
19+
```js
20+
/**
21+
* @example
22+
* anArray.filter((a) => {
23+
* return a.b;
24+
* });
25+
*/
26+
```
27+
528
|||
629
|---|---|
730
|Context|everywhere|
831
|Tags|N/A|
32+
|Options| `excludeExamples` |
933

1034
<!-- assertions checkIndentation -->

README.md

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,36 @@ function quux () {}
835835

836836
Reports invalid padding inside JSDoc block.
837837

838+
<a name="eslint-plugin-jsdoc-rules-check-indentation-options-1"></a>
839+
#### Options
840+
841+
This rule has an object option.
842+
843+
<a name="eslint-plugin-jsdoc-rules-check-indentation-options-1-excludeexamples"></a>
844+
##### <code>excludeExamples</code>
845+
846+
This boolean property allows to "hide" example code from reports.
847+
848+
By default, whole JSDoc block is checked for invalid padding.
849+
That includes example blocks too, which may get in the way of adding full,
850+
readable examples of code without ending up with multiple linting issues.
851+
852+
When enabled, following code will lint without any padding issue:
853+
854+
```js
855+
/**
856+
* @example
857+
* anArray.filter((a) => {
858+
* return a.b;
859+
* });
860+
*/
861+
```
862+
838863
|||
839864
|---|---|
840865
|Context|everywhere|
841866
|Tags|N/A|
867+
|Options| `excludeExamples` |
842868

843869
The following patterns are considered problems:
844870

@@ -871,14 +897,13 @@ class Moo {}
871897
* foo
872898
*
873899
* @example
874-
* function xFoo () {
875-
* return 'foo';
876-
* }
900+
* anArray.filter((a) => {
901+
* return a.b;
902+
* });
877903
*/
878904
function quux () {
879905

880906
}
881-
// Options: ["excludeExamples":false}]
882907
// Message: There must be no indentation.
883908
````
884909

@@ -904,14 +929,14 @@ function quux () {
904929
* foo
905930
*
906931
* @example
907-
* function xFoo () {
908-
* return 'foo';
909-
* }
932+
* anArray.filter((a) => {
933+
* return a.b;
934+
* });
910935
*/
911936
function quux () {
912937

913938
}
914-
// Options: ["excludeExamples":true}]
939+
// Options: [{"excludeExamples":true}]
915940
````
916941

917942

@@ -1265,10 +1290,10 @@ yields
12651290

12661291
Note that the tags indicated as replacements in `settings.jsdoc.tagNamePreference` will automatically be considered as valid.
12671292

1268-
<a name="eslint-plugin-jsdoc-rules-check-tag-names-options-1"></a>
1293+
<a name="eslint-plugin-jsdoc-rules-check-tag-names-options-2"></a>
12691294
#### Options
12701295

1271-
<a name="eslint-plugin-jsdoc-rules-check-tag-names-options-1-definedtags"></a>
1296+
<a name="eslint-plugin-jsdoc-rules-check-tag-names-options-2-definedtags"></a>
12721297
##### <code>definedTags</code>
12731298

12741299
Use an array of `definedTags` strings to configure additional, allowed JSDoc tags.
@@ -1610,7 +1635,7 @@ Date
16101635
RegExp
16111636
```
16121637

1613-
<a name="eslint-plugin-jsdoc-rules-check-types-options-2"></a>
1638+
<a name="eslint-plugin-jsdoc-rules-check-types-options-3"></a>
16141639
#### Options
16151640

16161641
`check-types` allows one option:
@@ -2511,10 +2536,10 @@ by our supported Node versions):
25112536
Applies to the jsdoc block description and `@description` (or `@desc`)
25122537
by default but the `tags` option (see below) may be used to match other tags.
25132538

2514-
<a name="eslint-plugin-jsdoc-rules-match-description-options-3"></a>
2539+
<a name="eslint-plugin-jsdoc-rules-match-description-options-4"></a>
25152540
#### Options
25162541

2517-
<a name="eslint-plugin-jsdoc-rules-match-description-options-3-matchdescription"></a>
2542+
<a name="eslint-plugin-jsdoc-rules-match-description-options-4-matchdescription"></a>
25182543
##### <code>matchDescription</code>
25192544

25202545
You can supply your own expression to override the default, passing a
@@ -2529,7 +2554,7 @@ You can supply your own expression to override the default, passing a
25292554
As with the default, the supplied regular expression will be applied with the
25302555
Unicode (`"u"`) flag and is *not* case-insensitive.
25312556

2532-
<a name="eslint-plugin-jsdoc-rules-match-description-options-3-tags"></a>
2557+
<a name="eslint-plugin-jsdoc-rules-match-description-options-4-tags"></a>
25332558
##### <code>tags</code>
25342559

25352560
If you want different regular expressions to apply to tags, you may use
@@ -2566,7 +2591,7 @@ its "description" (e.g., for `@returns {someType} some description`, the
25662591
description is `some description` while for `@some-tag xyz`, the description
25672592
is `xyz`).
25682593

2569-
<a name="eslint-plugin-jsdoc-rules-match-description-options-3-maindescription"></a>
2594+
<a name="eslint-plugin-jsdoc-rules-match-description-options-4-maindescription"></a>
25702595
##### <code>mainDescription</code>
25712596

25722597
If you wish to override the main function description without changing the
@@ -2588,7 +2613,7 @@ There is no need to add `mainDescription: true`, as by default, the main
25882613
function (and only the main function) is linted, though you may disable checking
25892614
it by setting it to `false`.
25902615

2591-
<a name="eslint-plugin-jsdoc-rules-match-description-options-3-contexts"></a>
2616+
<a name="eslint-plugin-jsdoc-rules-match-description-options-4-contexts"></a>
25922617
##### <code>contexts</code>
25932618

25942619
Set this to an array of strings representing the AST context
@@ -3208,7 +3233,7 @@ function quux () {
32083233

32093234
Enforces a consistent padding of the block description.
32103235

3211-
<a name="eslint-plugin-jsdoc-rules-newline-after-description-options-4"></a>
3236+
<a name="eslint-plugin-jsdoc-rules-newline-after-description-options-5"></a>
32123237
#### Options
32133238

32143239
This rule allows one optional string argument. If it is `"always"` then a problem is raised when there is a newline after the description. If it is `"never"` then a problem is raised when there is no newline after the description. The default value is `"always"`.
@@ -3388,7 +3413,7 @@ The following types are always considered defined.
33883413
Note that preferred types indicated within `settings.jsdoc.preferredTypes` will
33893414
also be assumed to be defined.
33903415

3391-
<a name="eslint-plugin-jsdoc-rules-no-undefined-types-options-5"></a>
3416+
<a name="eslint-plugin-jsdoc-rules-no-undefined-types-options-6"></a>
33923417
#### Options
33933418

33943419
An option object may have the following key:
@@ -3717,10 +3742,10 @@ tag descriptions are written in complete sentences, i.e.,
37173742
* Every line in a paragraph (except the first) which starts with an uppercase
37183743
character must be preceded by a line ending with a period.
37193744

3720-
<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-6"></a>
3745+
<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-7"></a>
37213746
#### Options
37223747

3723-
<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-6-tags-1"></a>
3748+
<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-7-tags-1"></a>
37243749
##### <code>tags</code>
37253750

37263751
If you want additional tags to be checked for their descriptions, you may
@@ -4176,7 +4201,7 @@ Requires that all functions have a description.
41764201
`"tag"`) must have a non-empty description that explains the purpose of the
41774202
method.
41784203

4179-
<a name="eslint-plugin-jsdoc-rules-require-description-options-7"></a>
4204+
<a name="eslint-plugin-jsdoc-rules-require-description-options-8"></a>
41804205
#### Options
41814206

41824207
An options object may have any of the following properties:
@@ -4453,25 +4478,25 @@ Requires that all functions have examples.
44534478
* All functions must have one or more `@example` tags.
44544479
* Every example tag must have a non-empty description that explains the method's usage.
44554480

4456-
<a name="eslint-plugin-jsdoc-rules-require-example-options-8"></a>
4481+
<a name="eslint-plugin-jsdoc-rules-require-example-options-9"></a>
44574482
#### Options
44584483

44594484
This rule has an object option.
44604485

4461-
<a name="eslint-plugin-jsdoc-rules-require-example-options-8-exemptedby"></a>
4486+
<a name="eslint-plugin-jsdoc-rules-require-example-options-9-exemptedby"></a>
44624487
##### <code>exemptedBy</code>
44634488

44644489
Array of tags (e.g., `['type']`) whose presence on the document
44654490
block avoids the need for an `@example`. Defaults to an empty array.
44664491

4467-
<a name="eslint-plugin-jsdoc-rules-require-example-options-8-avoidexampleonconstructors"></a>
4492+
<a name="eslint-plugin-jsdoc-rules-require-example-options-9-avoidexampleonconstructors"></a>
44684493
##### <code>avoidExampleOnConstructors</code>
44694494

44704495
Set to `true` to avoid the need for an example on a constructor (whether
44714496
indicated as such by a jsdoc tag or by being within an ES6 `class`).
44724497
Defaults to `false`.
44734498

4474-
<a name="eslint-plugin-jsdoc-rules-require-example-options-8-contexts-1"></a>
4499+
<a name="eslint-plugin-jsdoc-rules-require-example-options-9-contexts-1"></a>
44754500
##### <code>contexts</code>
44764501

44774502
Set this to an array of strings representing the AST context
@@ -4641,7 +4666,7 @@ function quux () {
46414666

46424667
Requires a hyphen before the `@param` description.
46434668

4644-
<a name="eslint-plugin-jsdoc-rules-require-hyphen-before-param-description-options-9"></a>
4669+
<a name="eslint-plugin-jsdoc-rules-require-hyphen-before-param-description-options-10"></a>
46454670
#### Options
46464671

46474672
This rule takes one optional string argument. If it is `"always"` then a problem is raised when there is no hyphen before the description. If it is `"never"` then a problem is raised when there is a hyphen before the description. The default value is `"always"`.
@@ -4747,7 +4772,7 @@ function quux () {
47474772
Checks for presence of jsdoc comments, on class declarations as well as
47484773
functions.
47494774

4750-
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-10"></a>
4775+
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-11"></a>
47514776
#### Options
47524777

47534778
Accepts one optional options object with the following optional keys.
@@ -5887,7 +5912,7 @@ function quux (foo) {
58875912

58885913
Requires that all function parameters are documented.
58895914

5890-
<a name="eslint-plugin-jsdoc-rules-require-param-options-11"></a>
5915+
<a name="eslint-plugin-jsdoc-rules-require-param-options-12"></a>
58915916
#### Options
58925917

58935918
An options object accepts one optional property:
@@ -6914,7 +6939,7 @@ Requires returns are documented.
69146939

69156940
Will also report if multiple `@returns` tags are present.
69166941

6917-
<a name="eslint-plugin-jsdoc-rules-require-returns-options-12"></a>
6942+
<a name="eslint-plugin-jsdoc-rules-require-returns-options-13"></a>
69186943
#### Options
69196944

69206945
- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document
@@ -7370,7 +7395,7 @@ Also impacts behaviors on namepath (or event)-defining and pointing tags:
73707395
allow `#`, `.`, or `~` at the end (which is not allowed at the end of
73717396
normal paths).
73727397

7373-
<a name="eslint-plugin-jsdoc-rules-valid-types-options-13"></a>
7398+
<a name="eslint-plugin-jsdoc-rules-valid-types-options-14"></a>
73747399
#### Options
73757400

73767401
- `allowEmptyNamepaths` (default: true) - Set to `false` to disallow

src/rules/checkIndentation.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import iterateJsdoc from '../iterateJsdoc';
22

33
const maskExamples = (str) => {
44
const regExamples = /([ \t]+\*)[ \t]@example(?=[ \n])([\w|\W]*?\n)(?=[ \t]*\*(?:[ \t]*@|\/))/g;
5-
return str.replace(regExamples, function hideCode (m, margin, code) {
5+
6+
return str.replace(regExamples, (match, margin, code) => {
67
return (new Array(code.match(/\n/g).length + 1)).join(margin + '\n');
78
});
89
};
@@ -15,7 +16,7 @@ export default iterateJsdoc(({
1516
}) => {
1617
const options = context.options[0] || {};
1718
const {
18-
excludeExamples = true
19+
excludeExamples = false,
1920
} = options;
2021

2122
const reg = new RegExp(/^(?:\/?\**|[ \t]*)\*[ \t]{2}/gm);
@@ -34,11 +35,11 @@ export default iterateJsdoc(({
3435
additionalProperties: false,
3536
properties: {
3637
excludeExamples: {
37-
default: true,
38-
type: 'boolean'
38+
default: false,
39+
type: 'boolean',
3940
},
4041
},
41-
type: 'object'
42+
type: 'object',
4243
}],
4344
type: 'layout',
4445
},

test/rules/assertions/checkIndentation.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ export default {
5454
* foo
5555
*
5656
* @example
57-
* function xFoo () {
58-
* return 'foo';
59-
* }
57+
* anArray.filter((a) => {
58+
* return a.b;
59+
* });
6060
*/
6161
function quux () {
6262
@@ -68,9 +68,6 @@ export default {
6868
message: 'There must be no indentation.',
6969
},
7070
],
71-
options: [{
72-
excludeExamples: false,
73-
}],
7471
},
7572
],
7673
valid: [
@@ -101,9 +98,9 @@ export default {
10198
* foo
10299
*
103100
* @example
104-
* function xFoo () {
105-
* return 'foo';
106-
* }
101+
* anArray.filter((a) => {
102+
* return a.b;
103+
* });
107104
*/
108105
function quux () {
109106

0 commit comments

Comments
 (0)