Skip to content

Commit

Permalink
fix(prefer-to-have-style): do not offer invalid autofix for computed …
Browse files Browse the repository at this point in the history
…accessors (#306)
  • Loading branch information
G-Rath authored Jun 4, 2023
1 parent 96c364a commit b38b8ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/__tests__/lib/rules/prefer-to-have-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
});
8 changes: 6 additions & 2 deletions src/rules/prefer-to-have-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit b38b8ea

Please sign in to comment.