Skip to content

Commit

Permalink
feat: add suggestion match-component-file-name rule
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hideaki Matsunami committed May 1, 2022
1 parent 4fc9116 commit 0a9a584
Show file tree
Hide file tree
Showing 2 changed files with 354 additions and 29 deletions.
14 changes: 13 additions & 1 deletion lib/rules/match-component-file-name.js
Expand Up @@ -31,6 +31,8 @@ function canVerify(node) {

module.exports = {
meta: {
// eslint-disable-next-line eslint-plugin/require-meta-has-suggestions
hasSuggestions: true,
type: 'suggestion',
docs: {
description: 'require component name property to match its file name',
Expand Down Expand Up @@ -114,7 +116,17 @@ module.exports = {
node,
message:
'Component name `{{name}}` should match file name `{{filename}}`.',
data: { filename, name }
data: { filename, name },
suggest: [
{
desc: 'Rename component to match file name.',
fix(fixer) {
const quote =
node.type === 'TemplateLiteral' ? '`' : node.raw[0]
return fixer.replaceText(node, `${quote}${filename}${quote}`)
}
}
]
})
}
}
Expand Down

0 comments on commit 0a9a584

Please sign in to comment.