File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 44 */
55'use strict'
66
7+ const path = require ( 'path' )
78const utils = require ( '../utils' )
89const { getVueComponentDefinitionType } = require ( '../utils' )
910
@@ -27,7 +28,8 @@ module.exports = {
2728 categories : undefined ,
2829 url : 'https://eslint.vuejs.org/rules/require-name-property.html'
2930 } ,
30- fixable : null ,
31+ fixable : 'whitespace' ,
32+ hasSuggestions : true ,
3133 schema : [ ]
3234 } ,
3335 /** @param {RuleContext } context */
@@ -47,7 +49,23 @@ module.exports = {
4749
4850 context . report ( {
4951 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+ }
5169 } )
5270 } )
5371 }
You can’t perform that action at this time.
0 commit comments