Skip to content

Commit 42706cb

Browse files
committed
feat: add rule check-indentation
1 parent 070f535 commit 42706cb

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable import/max-dependencies */
22
import checkExamples from './rules/checkExamples';
3+
import checkIndentation from './rules/checkIndentation';
34
import checkParamNames from './rules/checkParamNames';
45
import checkTagNames from './rules/checkTagNames';
56
import checkTypes from './rules/checkTypes';
@@ -24,6 +25,7 @@ export default {
2425
recommended: {
2526
rules: {
2627
'jsdoc/check-examples': 'off',
28+
'jsdoc/check-indentation': 'off',
2729
'jsdoc/check-param-names': 'warn',
2830
'jsdoc/check-tag-names': 'warn',
2931
'jsdoc/check-types': 'warn',
@@ -47,6 +49,7 @@ export default {
4749
},
4850
rules: {
4951
'check-examples': checkExamples,
52+
'check-indentation': checkIndentation,
5053
'check-param-names': checkParamNames,
5154
'check-tag-names': checkTagNames,
5255
'check-types': checkTypes,

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
@@ -8,6 +8,7 @@ const ruleTester = new RuleTester();
88

99
_.forEach([
1010
'check-examples',
11+
'check-indentation',
1112
'check-param-names',
1213
'check-tag-names',
1314
'check-types',

0 commit comments

Comments
 (0)