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' ;
12import iterateJsdoc from '../iterateJsdoc' ;
23
34export default iterateJsdoc ( ( {
@@ -17,14 +18,28 @@ export default iterateJsdoc(({
1718 return ! line . trim ( ) . length ;
1819 } ) ;
1920
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+
2034 for ( const line of sourceLines ) {
2135 if ( line . length !== indentLevel ) {
22- report ( 'Expected JSDoc block to be aligned.' ) ;
36+ report ( 'Expected JSDoc block to be aligned.' , fix ) ;
2337 break ;
2438 }
2539 }
2640} , {
2741 meta : {
42+ fixable : 'code' ,
2843 type : 'layout'
2944 }
3045} ) ;
Original file line number Diff line number Diff line change @@ -13,7 +13,15 @@ export default {
1313 {
1414 message : 'Expected JSDoc block to be aligned.'
1515 }
16- ]
16+ ] ,
17+ output : `
18+ /**
19+ * @param {Number} foo
20+ */
21+ function quux (foo) {
22+
23+ }
24+ `
1725 } ,
1826 {
1927 code : `
@@ -28,7 +36,15 @@ export default {
2836 {
2937 message : 'Expected JSDoc block to be aligned.'
3038 }
31- ]
39+ ] ,
40+ output : `
41+ /**
42+ * @param {Number} foo
43+ */
44+ function quux (foo) {
45+
46+ }
47+ `
3248 } ,
3349 {
3450 code : `
@@ -43,7 +59,15 @@ export default {
4359 {
4460 message : 'Expected JSDoc block to be aligned.'
4561 }
46- ]
62+ ] ,
63+ output : `
64+ /**
65+ * @param {Number} foo
66+ */
67+ function quux (foo) {
68+
69+ }
70+ `
4771 } ,
4872 {
4973 code : `
@@ -58,7 +82,15 @@ export default {
5882 {
5983 message : 'Expected JSDoc block to be aligned.'
6084 }
61- ]
85+ ] ,
86+ output : `
87+ /**
88+ * @param {Number} foo
89+ */
90+ function quux (foo) {
91+
92+ }
93+ `
6294 } ,
6395 {
6496 code : `
@@ -73,7 +105,15 @@ export default {
73105 {
74106 message : 'Expected JSDoc block to be aligned.'
75107 }
76- ]
108+ ] ,
109+ output : `
110+ /**
111+ * @param {Number} foo
112+ */
113+ function quux (foo) {
114+
115+ }
116+ `
77117 }
78118 ] ,
79119 valid : [
You can’t perform that action at this time.
0 commit comments