File tree Expand file tree Collapse file tree 4 files changed +139
-0
lines changed Expand file tree Collapse file tree 4 files changed +139
-0
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-disable import/max-dependencies */
2
+ import checkAlignment from './rules/checkAlignment' ;
2
3
import checkExamples from './rules/checkExamples' ;
3
4
import checkParamNames from './rules/checkParamNames' ;
4
5
import checkTagNames from './rules/checkTagNames' ;
@@ -23,6 +24,7 @@ export default {
23
24
configs : {
24
25
recommended : {
25
26
rules : {
27
+ 'jsdoc/check-alignment' : 'warn' ,
26
28
'jsdoc/check-examples' : 'off' ,
27
29
'jsdoc/check-param-names' : 'warn' ,
28
30
'jsdoc/check-tag-names' : 'warn' ,
@@ -46,6 +48,7 @@ export default {
46
48
}
47
49
} ,
48
50
rules : {
51
+ 'check-alignment' : checkAlignment ,
49
52
'check-examples' : checkExamples ,
50
53
'check-param-names' : checkParamNames ,
51
54
'check-tag-names' : checkTagNames ,
Original file line number Diff line number Diff line change
1
+ import iterateJsdoc from '../iterateJsdoc' ;
2
+
3
+ export default iterateJsdoc ( ( {
4
+ sourceCode,
5
+ jsdocNode,
6
+ report,
7
+ indent
8
+ } ) => {
9
+ // `indent` is whitespace from line 1 (`/**`), so slice and account for "/".
10
+ const indentLevel = indent . length + 1 ;
11
+ const sourceLines = sourceCode . getText ( jsdocNode ) . split ( '\n' )
12
+ . slice ( 1 )
13
+ . map ( ( line ) => {
14
+ return line . split ( '*' ) [ 0 ] ;
15
+ } )
16
+ . filter ( ( line ) => {
17
+ return ! line . trim ( ) . length ;
18
+ } ) ;
19
+
20
+ for ( const line of sourceLines ) {
21
+ if ( line . length !== indentLevel ) {
22
+ report ( 'Expected JSDoc block to be aligned.' ) ;
23
+ break ;
24
+ }
25
+ }
26
+ } ) ;
Original file line number Diff line number Diff line change
1
+ export default {
2
+ invalid : [
3
+ {
4
+ code : `
5
+ /**
6
+ * @param {Number} foo
7
+ */
8
+ function quux (foo) {
9
+
10
+ }
11
+ ` ,
12
+ errors : [
13
+ {
14
+ message : 'Expected JSDoc block to be aligned.'
15
+ }
16
+ ]
17
+ } ,
18
+ {
19
+ code : `
20
+ /**
21
+ * @param {Number} foo
22
+ */
23
+ function quux (foo) {
24
+
25
+ }
26
+ ` ,
27
+ errors : [
28
+ {
29
+ message : 'Expected JSDoc block to be aligned.'
30
+ }
31
+ ]
32
+ } ,
33
+ {
34
+ code : `
35
+ /**
36
+ * @param {Number} foo
37
+ */
38
+ function quux (foo) {
39
+
40
+ }
41
+ ` ,
42
+ errors : [
43
+ {
44
+ message : 'Expected JSDoc block to be aligned.'
45
+ }
46
+ ]
47
+ } ,
48
+ {
49
+ code : `
50
+ /**
51
+ * @param {Number} foo
52
+ */
53
+ function quux (foo) {
54
+
55
+ }
56
+ ` ,
57
+ errors : [
58
+ {
59
+ message : 'Expected JSDoc block to be aligned.'
60
+ }
61
+ ]
62
+ } ,
63
+ {
64
+ code : `
65
+ /**
66
+ * @param {Number} foo
67
+ */
68
+ function quux (foo) {
69
+
70
+ }
71
+ ` ,
72
+ errors : [
73
+ {
74
+ message : 'Expected JSDoc block to be aligned.'
75
+ }
76
+ ]
77
+ }
78
+ ] ,
79
+ valid : [
80
+ {
81
+ code : `
82
+ /**
83
+ * Desc
84
+ *
85
+ * @param {Number} foo
86
+ */
87
+ function quux (foo) {
88
+
89
+ }
90
+ `
91
+ } ,
92
+ {
93
+ code : `
94
+ /**
95
+ * Desc
96
+ *
97
+ * @param {{
98
+ foo: Bar,
99
+ bar: Baz
100
+ * }} foo
101
+ *
102
+ */
103
+ function quux (foo) {
104
+
105
+ }
106
+ `
107
+ }
108
+ ]
109
+ } ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import config from '../../src';
7
7
const ruleTester = new RuleTester ( ) ;
8
8
9
9
_ . forEach ( [
10
+ 'check-alignment' ,
10
11
'check-examples' ,
11
12
'check-param-names' ,
12
13
'check-tag-names' ,
You can’t perform that action at this time.
0 commit comments