Skip to content

Commit 0ca5f9d

Browse files
authored
Fix false positives for CSS v-bind() in vue/no-extra-parens rule (#1775)
1 parent 017cc22 commit 0ca5f9d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Diff for: lib/rules/no-extra-parens.js

+20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
const { isParenthesized } = require('eslint-utils')
77
const { wrapCoreRule } = require('../utils')
8+
const { getStyleVariablesContext } = require('../utils/style-variables')
89

910
// eslint-disable-next-line no-invalid-meta, no-invalid-meta-docs-categories
1011
module.exports = wrapCoreRule('no-extra-parens', {
@@ -116,6 +117,22 @@ function createForVueSyntax(context) {
116117
}
117118
return false
118119
}
120+
/**
121+
* Checks if the given node is CSS v-bind() without quote.
122+
* @param {VExpressionContainer} node
123+
* @param {Expression} expression
124+
*/
125+
function isStyleVariableWithoutQuote(node, expression) {
126+
const styleVars = getStyleVariablesContext(context)
127+
if (!styleVars || !styleVars.vBinds.includes(node)) {
128+
return false
129+
}
130+
131+
const vBindToken = tokenStore.getFirstToken(node)
132+
const tokens = tokenStore.getTokensBetween(vBindToken, expression)
133+
134+
return tokens.every(isLeftParen)
135+
}
119136
/**
120137
* @param {VExpressionContainer & { expression: Expression | VFilterSequenceExpression | null }} node
121138
*/
@@ -143,6 +160,9 @@ function createForVueSyntax(context) {
143160
if (isUnwrapChangeToFilter(expression)) {
144161
return
145162
}
163+
if (isStyleVariableWithoutQuote(node, expression)) {
164+
return
165+
}
146166
}
147167
report(expression)
148168
}

Diff for: tests/lib/rules/no-extra-parens.js

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ tester.run('no-extra-parens', rule, {
4848
.text {
4949
color: v-bind('a')
5050
}
51+
</style>`,
52+
`
53+
<style>
54+
.text {
55+
color: v-bind(a)
56+
}
5157
</style>`
5258
],
5359
invalid: [

0 commit comments

Comments
 (0)