Skip to content

🎥 Make videos programmatically with React

@remotion/eslint-plugin: Add slow-css-property rule

copilot-swe-agent[bot]d4af0bb6c51b
diff --git a/packages/eslint-plugin/src/index.ts b/packages/eslint-plugin/src/index.ts
index 875d0859b9..a1e0c6f56c 100644
--- a/packages/eslint-plugin/src/index.ts
+++ b/packages/eslint-plugin/src/index.ts
@@ -4,6 +4,7 @@ import noBackgroundImage from './rules/no-background-image';
import durationInFrames from './rules/no-duration-frames-infinity';
import noFrom0 from './rules/no-from-0';
import noStringAssets from './rules/no-string-assets';
+import slowCssProperty from './rules/slow-css-property';
import staticFileNoRelative from './rules/staticfile-no-relative';
import staticFileNoRemote from './rules/staticfile-no-remote';
import useGifComponent from './rules/use-gif-component';
@@ -23,6 +24,7 @@ const rules = {
'staticfile-no-relative': staticFileNoRelative,
'staticfile-no-remote': staticFileNoRemote,
'no-background-image': noBackgroundImage,
+ 'slow-css-property': slowCssProperty,
'v4-config-import': v4Import,
};
@@ -38,6 +40,7 @@ const recommendedRuleConfig = {
'@remotion/staticfile-no-relative': 'error',
'@remotion/staticfile-no-remote': 'error',
'@remotion/no-background-image': 'error',
+ '@remotion/slow-css-property': 'warn',
'@remotion/v4-config-import': 'error',
} as const;
diff --git a/packages/eslint-plugin/src/rules/slow-css-property.ts b/packages/eslint-plugin/src/rules/slow-css-property.ts
new file mode 100644
index 0000000000..0032a248aa
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/slow-css-property.ts
@@ -0,0 +1,48 @@
+import {ESLintUtils} from '@typescript-eslint/utils';
+
+const createRule = ESLintUtils.RuleCreator(() => {
+ return 'https://remotion.dev/docs/gpu';
+});
+
+type Options = [];
+type MessageIds = 'SlowCssProperty';
+
+const SlowCssProperty = [
+ "This GPU effect may slow down the render on machines which don't have a GPU.",
+ 'See: https://remotion.dev/docs/gpu',
+].join('\n');
+
+const slowCssProperties = new Set(['boxShadow', 'textShadow', 'filter']);
+
+export default createRule<Options, MessageIds>({
+ name: 'slow-css-property',
+ meta: {
+ type: 'problem',
+ docs: {
+ description: SlowCssProperty,
+ recommended: 'warn',
+ },
+ fixable: undefined,
+ schema: [],
+ messages: {
+ SlowCssProperty: SlowCssProperty,
+ },
+ },
+ defaultOptions: [],
+ create: (context) => {
+ return {
+ Property: (node) => {
+ if (node.key.type !== 'Identifier') {
+ return;
+ }
+
+ if (slowCssProperties.has(node.key.name)) {
+ context.report({
+ messageId: 'SlowCssProperty',
+ node,
+ });
+ }
+ },
+ };
+ },
+});
diff --git a/packages/eslint-plugin/src/tests/slow-css-property.test.ts b/packages/eslint-plugin/src/tests/slow-css-property.test.ts
new file mode 100644
index 0000000000..ff854abc2e
--- /dev/null
+++ b/packages/eslint-plugin/src/tests/slow-css-property.test.ts
@@ -0,0 +1,57 @@
+import {ESLintUtils} from '@typescript-eslint/utils';
+import rule from '../rules/slow-css-property';
+
+const ruleTester = new ESLintUtils.RuleTester({
+ parser: '@typescript-eslint/parser',
+});
+
+ruleTester.run('slow-css-property', rule, {
+ valid: [
+ `const style = {color: "red"}`,
+ `const style = {backgroundColor: "blue"}`,
+ `const style = {margin: 10}`,
+ `const style = {border: "1px solid black"}`,
+ `const style = {"box-shadow": "0 0 5px red"}`, // string key should not trigger
+ ],
+ invalid: [
+ {
+ code: `const style = {boxShadow: "0 0 5px red"}`,
+ errors: [
+ {
+ messageId: 'SlowCssProperty',
+ },
+ ],
+ },
+ {
+ code: `const style = {textShadow: "1px 1px 1px black"}`,
+ errors: [
+ {
+ messageId: 'SlowCssProperty',
+ },
+ ],
+ },
+ {
+ code: `const style = {filter: "blur(5px)"}`,
+ errors: [
+ {
+ messageId: 'SlowCssProperty',
+ },
+ ],
+ },
+ {
+ code: `const style = {
+ color: "red",
+ boxShadow: "0 0 5px red",
+ textShadow: "1px 1px 1px black"
+ }`,
+ errors: [
+ {
+ messageId: 'SlowCssProperty',
+ },
+ {
+ messageId: 'SlowCssProperty',
+ },
+ ],
+ },
+ ],
+});