Skip to content

Commit 0a9a584

Browse files
author
Hideaki Matsunami
committed
feat: add suggestion match-component-file-name rule
improve vuejs#1816 For the following reasons why name option changed. If change file name, alto need to change import statement. Also, this rule not auto-fixed, because the file name may be incorrect.
1 parent 4fc9116 commit 0a9a584

File tree

2 files changed

+354
-29
lines changed

2 files changed

+354
-29
lines changed

lib/rules/match-component-file-name.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ function canVerify(node) {
3131

3232
module.exports = {
3333
meta: {
34+
// eslint-disable-next-line eslint-plugin/require-meta-has-suggestions
35+
hasSuggestions: true,
3436
type: 'suggestion',
3537
docs: {
3638
description: 'require component name property to match its file name',
@@ -114,7 +116,17 @@ module.exports = {
114116
node,
115117
message:
116118
'Component name `{{name}}` should match file name `{{filename}}`.',
117-
data: { filename, name }
119+
data: { filename, name },
120+
suggest: [
121+
{
122+
desc: 'Rename component to match file name.',
123+
fix(fixer) {
124+
const quote =
125+
node.type === 'TemplateLiteral' ? '`' : node.raw[0]
126+
return fixer.replaceText(node, `${quote}${filename}${quote}`)
127+
}
128+
}
129+
]
118130
})
119131
}
120132
}

0 commit comments

Comments
 (0)