-
-
Notifications
You must be signed in to change notification settings - Fork 696
fix(v-on-handler-style): fixed the breaking change caused by the auto-fix on functions without parameters(#2538) #2539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d166023
Fix the `vue/v-on-handler-style` breaking change (#2538)
heggria 6498a89
Modify test of`vue/v-on-handler-style` (#2538)
heggria 9d0d0d2
Merge branch 'vuejs:master' into master
heggria 45b4557
feat(v-on-handler-style): change errors into suggestions
heggria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,7 @@ module.exports = { | |
url: 'https://eslint.vuejs.org/rules/v-on-handler-style.html' | ||
}, | ||
fixable: 'code', | ||
hasSuggestions: true, | ||
schema: [ | ||
{ | ||
oneOf: [ | ||
|
@@ -157,7 +158,11 @@ module.exports = { | |
preferInlineFunctionOverMethod: | ||
'Prefer inline function over method handler in v-on.', | ||
preferInlineFunctionOverInline: | ||
'Prefer inline function over inline handler in v-on.' | ||
'Prefer inline function over inline handler in v-on.', | ||
removeParenthesesOverInline: | ||
'Remove the parentheses from the inline handler in v-on.', | ||
removeParenthesesOverInlineFunction: | ||
'Remove the parentheses from the inline function in v-on.' | ||
} | ||
}, | ||
/** @param {RuleContext} context */ | ||
|
@@ -300,6 +305,36 @@ module.exports = { | |
return false | ||
} | ||
|
||
// disable the auto-fixed when the node does't have params | ||
if ( | ||
!hasComment /* The statement contains comment and cannot be fixed. */ && | ||
idCallExpr /* The statement is not a simple identifier call and cannot be fixed. */ && | ||
idCallExpr.arguments.length === 0 | ||
) { | ||
const paramCount = methodParamCountMap.get(idCallExpr.callee.name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this rule also has the number of arguments defined in the method. If we check that, I think some code can be safely fixed automatically. |
||
if ( | ||
idCallExpr && | ||
(idCallExpr.arguments.length === 0 || paramCount === 0) | ||
) { | ||
context.report({ | ||
node, | ||
messageId: 'preferMethodOverInline', | ||
suggest: [ | ||
{ | ||
messageId: 'removeParenthesesOverInline', | ||
fix(fixer) { | ||
return fixer.replaceTextRange( | ||
rangeWithoutQuotes, | ||
context.getSourceCode().getText(idCallExpr.callee) | ||
) | ||
} | ||
} | ||
] | ||
}) | ||
return true | ||
} | ||
} | ||
|
||
context.report({ | ||
node, | ||
messageId: idCallExpr | ||
|
@@ -324,6 +359,7 @@ module.exports = { | |
) | ||
} | ||
}) | ||
|
||
return true | ||
} | ||
/** | ||
|
@@ -356,6 +392,30 @@ module.exports = { | |
return false | ||
} | ||
|
||
// disable the auto-fixed when the node does't have params | ||
if ( | ||
!hasComment /* The statement contains comment and cannot be fixed. */ && | ||
idCallExpr /* The statement is not a simple identifier call and cannot be fixed. */ && | ||
(node.params.length === 0 || !isSameParamsAndArgs(idCallExpr)) | ||
) { | ||
context.report({ | ||
node, | ||
messageId: 'preferMethodOverInlineFunction', | ||
suggest: [ | ||
{ | ||
messageId: 'removeParenthesesOverInlineFunction', | ||
fix(fixer) { | ||
return fixer.replaceTextRange( | ||
rangeWithoutQuotes, | ||
context.getSourceCode().getText(idCallExpr.callee) | ||
) | ||
} | ||
} | ||
] | ||
}) | ||
return true | ||
} | ||
|
||
context.report({ | ||
node, | ||
messageId: idCallExpr | ||
|
@@ -368,10 +428,6 @@ module.exports = { | |
) { | ||
return null | ||
} | ||
if (!isSameParamsAndArgs(idCallExpr)) { | ||
// It is not a call with the arguments given as is. | ||
return null | ||
} | ||
const paramCount = methodParamCountMap.get(idCallExpr.callee.name) | ||
if ( | ||
paramCount != null && | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.