Skip to content

Commit 4daf4c8

Browse files
authored
feat: fixable match-component-file-name rule (#1874)
* Add typing 'Literal#raw' property vue-eslint-parser's ESLintLiteralBase Node has 'raw' property. ref: https://github.com/vuejs/vue-eslint-parser/blob/160f4efc4eaf363662b464a4a26a4c9e514deb5d/src/ast/nodes.ts#L395 It was necessary to identify quotes in the match-component-file-name's fixer. * feat: add suggestion match-component-file-name rule improve #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 9344af8 commit 4daf4c8

File tree

5 files changed

+325
-16
lines changed

5 files changed

+325
-16
lines changed

docs/rules/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ For example:
210210
| [vue/html-comment-content-newline](./html-comment-content-newline.md) | enforce unified line brake in HTML comments | :wrench: | :lipstick: |
211211
| [vue/html-comment-content-spacing](./html-comment-content-spacing.md) | enforce unified spacing in HTML comments | :wrench: | :lipstick: |
212212
| [vue/html-comment-indent](./html-comment-indent.md) | enforce consistent indentation in HTML comments | :wrench: | :lipstick: |
213-
| [vue/match-component-file-name](./match-component-file-name.md) | require component name property to match its file name | | :hammer: |
213+
| [vue/match-component-file-name](./match-component-file-name.md) | require component name property to match its file name | :bulb: | :hammer: |
214214
| [vue/match-component-import-name](./match-component-import-name.md) | require the registered component name to match the imported component name | | :warning: |
215215
| [vue/new-line-between-multi-line-property](./new-line-between-multi-line-property.md) | enforce new lines between multi-line properties in Vue components | :wrench: | :lipstick: |
216216
| [vue/next-tick-style](./next-tick-style.md) | enforce Promise or callback style in `nextTick` | :wrench: | :hammer: |

docs/rules/match-component-file-name.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ since: v5.2.0
99

1010
> require component name property to match its file name
1111
12+
- :bulb: Some problems reported by this rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
13+
1214
This rule reports if a component `name` property does not match its file name.
1315

1416
You can define an array of file extensions this rule should verify for the component's name.

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)