File tree 1 file changed +20
-2
lines changed
1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 4
4
*/
5
5
'use strict'
6
6
7
+ const path = require ( 'path' )
7
8
const utils = require ( '../utils' )
8
9
const { getVueComponentDefinitionType } = require ( '../utils' )
9
10
@@ -27,7 +28,8 @@ module.exports = {
27
28
categories : undefined ,
28
29
url : 'https://eslint.vuejs.org/rules/require-name-property.html'
29
30
} ,
30
- fixable : null ,
31
+ fixable : 'whitespace' ,
32
+ hasSuggestions : true ,
31
33
schema : [ ]
32
34
} ,
33
35
/** @param {RuleContext } context */
@@ -47,7 +49,23 @@ module.exports = {
47
49
48
50
context . report ( {
49
51
node : component ,
50
- message : 'Required name property is not set.'
52
+ message : 'Required name property is not set.' ,
53
+ fix : ( fixer ) => {
54
+ const extension = path . extname ( context . getFilename ( ) )
55
+ const filename = path . basename ( context . getFilename ( ) , extension )
56
+ // fix only when property is not empty
57
+ if ( component . properties . length > 0 ) {
58
+ const startColumn = component . properties [ 0 ] . loc . start . column
59
+ // insert name property before the first property
60
+ return fixer . insertTextBefore (
61
+ component . properties [ 0 ] ,
62
+ `name: '${ filename } ',\n${ Array . from ( {
63
+ length : startColumn + 1
64
+ } ) . join ( ' ' ) } `
65
+ )
66
+ }
67
+ return null
68
+ }
51
69
} )
52
70
} )
53
71
}
You can’t perform that action at this time.
0 commit comments