Skip to content

Commit e4b29bb

Browse files
CopilotJonnyBurger
andcommitted
@remotion/eslint-plugin: Support string literal CSS properties in slow-css-property rule
Co-authored-by: JonnyBurger <[email protected]>
1 parent d4af0bb commit e4b29bb

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

packages/eslint-plugin/src/rules/slow-css-property.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const SlowCssProperty = [
1313
].join('\n');
1414

1515
const slowCssProperties = new Set(['boxShadow', 'textShadow', 'filter']);
16+
const slowCssPropertiesKebab = new Set(['box-shadow', 'text-shadow', 'filter']);
1617

1718
export default createRule<Options, MessageIds>({
1819
name: 'slow-css-property',
@@ -32,11 +33,26 @@ export default createRule<Options, MessageIds>({
3233
create: (context) => {
3334
return {
3435
Property: (node) => {
35-
if (node.key.type !== 'Identifier') {
36+
let propertyName: string | undefined;
37+
38+
if (node.key.type === 'Identifier') {
39+
propertyName = node.key.name;
40+
} else if (
41+
node.key.type === 'Literal' &&
42+
typeof node.key.value === 'string'
43+
) {
44+
propertyName = node.key.value;
45+
}
46+
47+
if (!propertyName) {
3648
return;
3749
}
3850

39-
if (slowCssProperties.has(node.key.name)) {
51+
const isSlowProperty =
52+
slowCssProperties.has(propertyName) ||
53+
slowCssPropertiesKebab.has(propertyName);
54+
55+
if (isSlowProperty) {
4056
context.report({
4157
messageId: 'SlowCssProperty',
4258
node,

packages/eslint-plugin/src/tests/slow-css-property.test.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ ruleTester.run('slow-css-property', rule, {
1111
`const style = {backgroundColor: "blue"}`,
1212
`const style = {margin: 10}`,
1313
`const style = {border: "1px solid black"}`,
14-
`const style = {"box-shadow": "0 0 5px red"}`, // string key should not trigger
1514
],
1615
invalid: [
1716
{
@@ -53,5 +52,44 @@ ruleTester.run('slow-css-property', rule, {
5352
},
5453
],
5554
},
55+
{
56+
code: `const style = {"box-shadow": "0 0 5px red"}`,
57+
errors: [
58+
{
59+
messageId: 'SlowCssProperty',
60+
},
61+
],
62+
},
63+
{
64+
code: `const style = {"text-shadow": "1px 1px 1px black"}`,
65+
errors: [
66+
{
67+
messageId: 'SlowCssProperty',
68+
},
69+
],
70+
},
71+
{
72+
code: `const style = {"filter": "blur(5px)"}`,
73+
errors: [
74+
{
75+
messageId: 'SlowCssProperty',
76+
},
77+
],
78+
},
79+
{
80+
code: `const style = {
81+
color: "red",
82+
"box-shadow": "0 0 5px red",
83+
"text-shadow": "1px 1px 1px black"
84+
}`,
85+
errors: [
86+
{
87+
messageId: 'SlowCssProperty',
88+
},
89+
{
90+
messageId: 'SlowCssProperty',
91+
},
92+
],
93+
},
5694
],
5795
});

0 commit comments

Comments
 (0)