Skip to content

Commit

Permalink
Fix false positives for CSS v-bind() in vue/no-extra-parens rule (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Jan 24, 2022
1 parent 017cc22 commit 0ca5f9d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/rules/no-extra-parens.js
Expand Up @@ -5,6 +5,7 @@

const { isParenthesized } = require('eslint-utils')
const { wrapCoreRule } = require('../utils')
const { getStyleVariablesContext } = require('../utils/style-variables')

// eslint-disable-next-line no-invalid-meta, no-invalid-meta-docs-categories
module.exports = wrapCoreRule('no-extra-parens', {
Expand Down Expand Up @@ -116,6 +117,22 @@ function createForVueSyntax(context) {
}
return false
}
/**
* Checks if the given node is CSS v-bind() without quote.
* @param {VExpressionContainer} node
* @param {Expression} expression
*/
function isStyleVariableWithoutQuote(node, expression) {
const styleVars = getStyleVariablesContext(context)
if (!styleVars || !styleVars.vBinds.includes(node)) {
return false
}

const vBindToken = tokenStore.getFirstToken(node)
const tokens = tokenStore.getTokensBetween(vBindToken, expression)

return tokens.every(isLeftParen)
}
/**
* @param {VExpressionContainer & { expression: Expression | VFilterSequenceExpression | null }} node
*/
Expand Down Expand Up @@ -143,6 +160,9 @@ function createForVueSyntax(context) {
if (isUnwrapChangeToFilter(expression)) {
return
}
if (isStyleVariableWithoutQuote(node, expression)) {
return
}
}
report(expression)
}
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/no-extra-parens.js
Expand Up @@ -48,6 +48,12 @@ tester.run('no-extra-parens', rule, {
.text {
color: v-bind('a')
}
</style>`,
`
<style>
.text {
color: v-bind(a)
}
</style>`
],
invalid: [
Expand Down

0 comments on commit 0ca5f9d

Please sign in to comment.