File tree Expand file tree Collapse file tree 2 files changed +61
-6
lines changed Expand file tree Collapse file tree 2 files changed +61
-6
lines changed Original file line number Diff line number Diff line change
1
+ import _ from 'lodash' ;
1
2
import iterateJsdoc from '../iterateJsdoc' ;
2
3
3
4
export default iterateJsdoc ( ( {
@@ -17,14 +18,28 @@ export default iterateJsdoc(({
17
18
return ! line . trim ( ) . length ;
18
19
} ) ;
19
20
21
+ const fix = ( fixer ) => {
22
+ const replacement = sourceCode . getText ( jsdocNode ) . split ( '\n' )
23
+ . map ( ( line , index ) => {
24
+ // Ignore the first line and all lines not starting with `*`
25
+ const ignored = ! index || line . split ( '*' ) [ 0 ] . trim ( ) . length ;
26
+
27
+ return ignored ? line : indent + ' ' + _ . trimStart ( line ) ;
28
+ } )
29
+ . join ( '\n' ) ;
30
+
31
+ return fixer . replaceText ( jsdocNode , replacement ) ;
32
+ } ;
33
+
20
34
for ( const line of sourceLines ) {
21
35
if ( line . length !== indentLevel ) {
22
- report ( 'Expected JSDoc block to be aligned.' ) ;
36
+ report ( 'Expected JSDoc block to be aligned.' , fix ) ;
23
37
break ;
24
38
}
25
39
}
26
40
} , {
27
41
meta : {
42
+ fixable : 'code' ,
28
43
type : 'layout'
29
44
}
30
45
} ) ;
Original file line number Diff line number Diff line change @@ -13,7 +13,15 @@ export default {
13
13
{
14
14
message : 'Expected JSDoc block to be aligned.'
15
15
}
16
- ]
16
+ ] ,
17
+ output : `
18
+ /**
19
+ * @param {Number} foo
20
+ */
21
+ function quux (foo) {
22
+
23
+ }
24
+ `
17
25
} ,
18
26
{
19
27
code : `
@@ -28,7 +36,15 @@ export default {
28
36
{
29
37
message : 'Expected JSDoc block to be aligned.'
30
38
}
31
- ]
39
+ ] ,
40
+ output : `
41
+ /**
42
+ * @param {Number} foo
43
+ */
44
+ function quux (foo) {
45
+
46
+ }
47
+ `
32
48
} ,
33
49
{
34
50
code : `
@@ -43,7 +59,15 @@ export default {
43
59
{
44
60
message : 'Expected JSDoc block to be aligned.'
45
61
}
46
- ]
62
+ ] ,
63
+ output : `
64
+ /**
65
+ * @param {Number} foo
66
+ */
67
+ function quux (foo) {
68
+
69
+ }
70
+ `
47
71
} ,
48
72
{
49
73
code : `
@@ -58,7 +82,15 @@ export default {
58
82
{
59
83
message : 'Expected JSDoc block to be aligned.'
60
84
}
61
- ]
85
+ ] ,
86
+ output : `
87
+ /**
88
+ * @param {Number} foo
89
+ */
90
+ function quux (foo) {
91
+
92
+ }
93
+ `
62
94
} ,
63
95
{
64
96
code : `
@@ -73,7 +105,15 @@ export default {
73
105
{
74
106
message : 'Expected JSDoc block to be aligned.'
75
107
}
76
- ]
108
+ ] ,
109
+ output : `
110
+ /**
111
+ * @param {Number} foo
112
+ */
113
+ function quux (foo) {
114
+
115
+ }
116
+ `
77
117
}
78
118
] ,
79
119
valid : [
You can’t perform that action at this time.
0 commit comments