Skip to content

fix(prefer-to-have-style): do not offer invalid autofix for computed accessors #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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