diff --git a/src/__tests__/lib/rules/prefer-to-have-style.js b/src/__tests__/lib/rules/prefer-to-have-style.js index ac2b947..dbc7066 100644 --- a/src/__tests__/lib/rules/prefer-to-have-style.js +++ b/src/__tests__/lib/rules/prefer-to-have-style.js @@ -167,5 +167,15 @@ ruleTester.run("prefer-to-have-style", rule, { code: `expect(element.style[0]).toBe(/RegExp/);`, errors, }, + { + code: `expect(imageElement.style[computed]).toBe(\`inset 0px 0px 0px 400px \${c}\`)`, + errors, + output: null, + }, + { + code: `expect(imageElement.style[computed]).not.toBe(\`inset 0px 0px 0px 400px \${c}\`)`, + errors, + output: null, + }, ], }); diff --git a/src/rules/prefer-to-have-style.js b/src/rules/prefer-to-have-style.js index 1d0dead..9440cbd 100644 --- a/src/rules/prefer-to-have-style.js +++ b/src/rules/prefer-to-have-style.js @@ -169,7 +169,8 @@ export const create = (context) => { if ( typeof styleValue.value !== "number" && - !(styleValue.value instanceof RegExp) + !(styleValue.value instanceof RegExp) && + styleName.type !== "Identifier" ) { fix = (fixer) => { return [ @@ -208,7 +209,10 @@ export const create = (context) => { let fix = null; - if (typeof styleName.value !== "number") { + if ( + typeof styleName.value !== "number" && + styleName.type !== "Identifier" + ) { fix = (fixer) => { return [ fixer.removeRange([