Skip to content

Commit b38b8ea

Browse files
authored
fix(prefer-to-have-style): do not offer invalid autofix for computed accessors (#306)
1 parent 96c364a commit b38b8ea

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/__tests__/lib/rules/prefer-to-have-style.js

+10
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,15 @@ ruleTester.run("prefer-to-have-style", rule, {
167167
code: `expect(element.style[0]).toBe(/RegExp/);`,
168168
errors,
169169
},
170+
{
171+
code: `expect(imageElement.style[computed]).toBe(\`inset 0px 0px 0px 400px \${c}\`)`,
172+
errors,
173+
output: null,
174+
},
175+
{
176+
code: `expect(imageElement.style[computed]).not.toBe(\`inset 0px 0px 0px 400px \${c}\`)`,
177+
errors,
178+
output: null,
179+
},
170180
],
171181
});

src/rules/prefer-to-have-style.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ export const create = (context) => {
169169

170170
if (
171171
typeof styleValue.value !== "number" &&
172-
!(styleValue.value instanceof RegExp)
172+
!(styleValue.value instanceof RegExp) &&
173+
styleName.type !== "Identifier"
173174
) {
174175
fix = (fixer) => {
175176
return [
@@ -208,7 +209,10 @@ export const create = (context) => {
208209

209210
let fix = null;
210211

211-
if (typeof styleName.value !== "number") {
212+
if (
213+
typeof styleName.value !== "number" &&
214+
styleName.type !== "Identifier"
215+
) {
212216
fix = (fixer) => {
213217
return [
214218
fixer.removeRange([

0 commit comments

Comments
 (0)