Skip to content

Commit ea84996

Browse files
authored
Merge pull request #187 from vulkd/vk/rule-check-indentation
feat: add rule check indentation
2 parents 62a56f5 + 05685b1 commit ea84996

File tree

7 files changed

+110
-0
lines changed

7 files changed

+110
-0
lines changed

.README/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This table maps the rules between `eslint-plugin-jsdoc` and `jscs-jsdoc`.
1616
| --- | --- |
1717
| [`check-alignment`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-alignment) | N/A |
1818
| [`check-examples`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples) | N/A |
19+
| [`check-indentation`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-indentation) | N/A |
1920
| [`check-param-names`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names) | [`checkParamNames`](https://github.com/jscs-dev/jscs-jsdoc#checkparamnames) |
2021
| [`check-syntax`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-syntax) | N/A |
2122
| [`check-tag-names`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-tag-names) | N/A ~ [`checkAnnotations`](https://github.com/jscs-dev/jscs-jsdoc#checkannotations) |
@@ -75,6 +76,7 @@ Finally, enable all of the rules that you would like to use.
7576
"rules": {
7677
"jsdoc/check-alignment": 1,
7778
"jsdoc/check-examples": 1,
79+
"jsdoc/check-indentation": 1,
7880
"jsdoc/check-param-names": 1,
7981
"jsdoc/check-syntax": 1,
8082
"jsdoc/check-tag-names": 1,
@@ -251,6 +253,7 @@ Finally, the following rule pertains to inline disable directives:
251253

252254
{"gitdown": "include", "file": "./rules/check-alignment.md"}
253255
{"gitdown": "include", "file": "./rules/check-examples.md"}
256+
{"gitdown": "include", "file": "./rules/check-indentation.md"}
254257
{"gitdown": "include", "file": "./rules/check-param-names.md"}
255258
{"gitdown": "include", "file": "./rules/check-syntax.md"}
256259
{"gitdown": "include", "file": "./rules/check-tag-names.md"}

.README/rules/check-indentation.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
### `check-indentation`
2+
3+
Reports invalid padding inside JSDoc block.
4+
5+
|||
6+
|---|---|
7+
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
8+
|Tags|N/A|
9+
10+
<!-- assertions checkIndentation -->

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ JSDoc linting rules for ESLint.
1919
* [Rules](#eslint-plugin-jsdoc-rules)
2020
* [`check-alignment`](#eslint-plugin-jsdoc-rules-check-alignment)
2121
* [`check-examples`](#eslint-plugin-jsdoc-rules-check-examples)
22+
* [`check-indentation`](#eslint-plugin-jsdoc-rules-check-indentation)
2223
* [`check-param-names`](#eslint-plugin-jsdoc-rules-check-param-names)
2324
* [`check-syntax`](#eslint-plugin-jsdoc-rules-check-syntax)
2425
* [`check-tag-names`](#eslint-plugin-jsdoc-rules-check-tag-names)
@@ -49,6 +50,7 @@ This table maps the rules between `eslint-plugin-jsdoc` and `jscs-jsdoc`.
4950
| --- | --- |
5051
| [`check-alignment`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-alignment) | N/A |
5152
| [`check-examples`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples) | N/A |
53+
| [`check-indentation`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-indentation) | N/A |
5254
| [`check-param-names`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names) | [`checkParamNames`](https://github.com/jscs-dev/jscs-jsdoc#checkparamnames) |
5355
| [`check-syntax`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-syntax) | N/A |
5456
| [`check-tag-names`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-tag-names) | N/A ~ [`checkAnnotations`](https://github.com/jscs-dev/jscs-jsdoc#checkannotations) |
@@ -110,6 +112,7 @@ Finally, enable all of the rules that you would like to use.
110112
"rules": {
111113
"jsdoc/check-alignment": 1,
112114
"jsdoc/check-examples": 1,
115+
"jsdoc/check-indentation": 1,
113116
"jsdoc/check-param-names": 1,
114117
"jsdoc/check-syntax": 1,
115118
"jsdoc/check-tag-names": 1,
@@ -572,6 +575,46 @@ function quux () {}
572575
````
573576

574577

578+
<a name="eslint-plugin-jsdoc-rules-check-indentation"></a>
579+
### <code>check-indentation</code>
580+
581+
Reports invalid padding inside JSDoc block.
582+
583+
|||
584+
|---|---|
585+
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
586+
|Tags|N/A|
587+
588+
The following patterns are considered problems:
589+
590+
````js
591+
/**
592+
* foo
593+
*
594+
* @param bar
595+
* baz
596+
*/
597+
function quux () {
598+
599+
}
600+
// Message: There must be no indentation.
601+
````
602+
603+
The following patterns are not considered problems:
604+
605+
````js
606+
/**
607+
* foo
608+
*
609+
* @param bar
610+
* baz
611+
*/
612+
function quux () {
613+
614+
}
615+
````
616+
617+
575618
<a name="eslint-plugin-jsdoc-rules-check-param-names"></a>
576619
### <code>check-param-names</code>
577620

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable import/max-dependencies */
22
import checkAlignment from './rules/checkAlignment';
33
import checkExamples from './rules/checkExamples';
4+
import checkIndentation from './rules/checkIndentation';
45
import checkParamNames from './rules/checkParamNames';
56
import checkSyntax from './rules/checkSyntax';
67
import checkTagNames from './rules/checkTagNames';
@@ -27,6 +28,7 @@ export default {
2728
rules: {
2829
'jsdoc/check-alignment': 'warn',
2930
'jsdoc/check-examples': 'off',
31+
'jsdoc/check-indentation': 'off',
3032
'jsdoc/check-param-names': 'warn',
3133
'jsdoc/check-syntax': 'off',
3234
'jsdoc/check-tag-names': 'warn',
@@ -52,6 +54,7 @@ export default {
5254
rules: {
5355
'check-alignment': checkAlignment,
5456
'check-examples': checkExamples,
57+
'check-indentation': checkIndentation,
5558
'check-param-names': checkParamNames,
5659
'check-syntax': checkSyntax,
5760
'check-tag-names': checkTagNames,

src/rules/checkIndentation.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import iterateJsdoc from '../iterateJsdoc';
2+
3+
export default iterateJsdoc(({
4+
sourceCode,
5+
jsdocNode,
6+
report
7+
}) => {
8+
const reg = new RegExp(/^[ \t]+\*[ \t]{2}/m);
9+
const text = sourceCode.getText(jsdocNode);
10+
if (reg.test(text)) {
11+
report('There must be no indentation.');
12+
}
13+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export default {
2+
invalid: [
3+
{
4+
code: `
5+
/**
6+
* foo
7+
*
8+
* @param bar
9+
* baz
10+
*/
11+
function quux () {
12+
13+
}
14+
`,
15+
errors: [
16+
{
17+
message: 'There must be no indentation.'
18+
}
19+
]
20+
}
21+
],
22+
valid: [
23+
{
24+
code: `
25+
/**
26+
* foo
27+
*
28+
* @param bar
29+
* baz
30+
*/
31+
function quux () {
32+
33+
}
34+
`
35+
}
36+
]
37+
};

test/rules/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const ruleTester = new RuleTester();
99
_.forEach([
1010
'check-alignment',
1111
'check-examples',
12+
'check-indentation',
1213
'check-param-names',
1314
'check-syntax',
1415
'check-tag-names',

0 commit comments

Comments
 (0)