Skip to content

🎥 Make videos programmatically with React

@remotion/eslint-plugin: Add non-pure-animation rule to catch CSS transitions

copilot-swe-agent[bot]05a2ee402bd0
diff --git a/packages/eslint-plugin/src/index.ts b/packages/eslint-plugin/src/index.ts
index a1e0c6f56c..0e657e567f 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 nonPureAnimation from './rules/non-pure-animation';
import slowCssProperty from './rules/slow-css-property';
import staticFileNoRelative from './rules/staticfile-no-relative';
import staticFileNoRemote from './rules/staticfile-no-remote';
@@ -24,6 +25,7 @@ const rules = {
'staticfile-no-relative': staticFileNoRelative,
'staticfile-no-remote': staticFileNoRemote,
'no-background-image': noBackgroundImage,
+ 'non-pure-animation': nonPureAnimation,
'slow-css-property': slowCssProperty,
'v4-config-import': v4Import,
};
@@ -40,6 +42,7 @@ const recommendedRuleConfig = {
'@remotion/staticfile-no-relative': 'error',
'@remotion/staticfile-no-remote': 'error',
'@remotion/no-background-image': 'error',
+ '@remotion/non-pure-animation': 'warn',
'@remotion/slow-css-property': 'warn',
'@remotion/v4-config-import': 'error',
} as const;
diff --git a/packages/eslint-plugin/src/rules/non-pure-animation.ts b/packages/eslint-plugin/src/rules/non-pure-animation.ts
new file mode 100644
index 0000000000..7ee8f62805
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/non-pure-animation.ts
@@ -0,0 +1,122 @@
+import {ESLintUtils} from '@typescript-eslint/utils';
+
+const createRule = ESLintUtils.RuleCreator(() => {
+ return 'https://www.remotion.dev/docs/flickering';
+});
+
+type Options = [];
+type MessageIds = 'NonPureAnimation';
+
+const NonPureAnimation = [
+ 'This animation does not run purely off useCurrentFrame() and will lead to flickering.',
+ 'See: https://www.remotion.dev/docs/flickering',
+].join('\n');
+
+const nonPureAnimationProperties = new Set(['transition']);
+const nonPureAnimationPropertiesKebab = new Set(['transition']);
+
+// Tailwind classes that correspond to non-pure animations
+const nonPureAnimationTailwindClasses = [
+ // Basic transition classes
+ /\btransition\b/,
+ /\btransition-(?:all|none|colors|opacity|shadow|transform)\b/,
+ // Additional common transition properties
+ /\btransition-(?:spacing|size|width|height|margin|padding)\b/,
+ // Custom transition properties (catch-all for any transition-*)
+ /\btransition-\w+\b/,
+];
+
+function containsNonPureAnimationTailwindClass(classString: string): boolean {
+ return nonPureAnimationTailwindClasses.some((pattern) =>
+ pattern.test(classString),
+ );
+}
+
+export default createRule<Options, MessageIds>({
+ name: 'non-pure-animation',
+ meta: {
+ type: 'problem',
+ docs: {
+ description: NonPureAnimation,
+ recommended: 'warn',
+ },
+ fixable: undefined,
+ schema: [],
+ messages: {
+ NonPureAnimation: NonPureAnimation,
+ },
+ },
+ defaultOptions: [],
+ create: (context) => {
+ return {
+ Property: (node) => {
+ let propertyName: string | undefined;
+
+ if (node.key.type === 'Identifier') {
+ propertyName = node.key.name;
+ } else if (
+ node.key.type === 'Literal' &&
+ typeof node.key.value === 'string'
+ ) {
+ propertyName = node.key.value;
+ }
+
+ if (!propertyName) {
+ return;
+ }
+
+ const isNonPureProperty =
+ nonPureAnimationProperties.has(propertyName) ||
+ nonPureAnimationPropertiesKebab.has(propertyName);
+
+ if (isNonPureProperty) {
+ context.report({
+ messageId: 'NonPureAnimation',
+ node,
+ });
+ }
+ },
+ JSXAttribute: (node) => {
+ if (
+ node.name.type === 'JSXIdentifier' &&
+ node.name.name === 'className' &&
+ node.value
+ ) {
+ let classString: string | undefined;
+
+ if (
+ node.value.type === 'Literal' &&
+ typeof node.value.value === 'string'
+ ) {
+ classString = node.value.value;
+ } else if (
+ node.value.type === 'JSXExpressionContainer' &&
+ node.value.expression.type === 'Literal' &&
+ typeof node.value.expression.value === 'string'
+ ) {
+ classString = node.value.expression.value;
+ } else if (
+ node.value.type === 'JSXExpressionContainer' &&
+ node.value.expression.type === 'TemplateLiteral'
+ ) {
+ // For template literals, check all string parts
+ const templateLiteral = node.value.expression;
+ classString = templateLiteral.quasis
+ .map((q) => q.value.cooked || q.value.raw)
+ .join(' ');
+ }
+
+ if (
+ classString &&
+ containsNonPureAnimationTailwindClass(classString)
+ ) {
+ context.report({
+ messageId: 'NonPureAnimation',
+ node,
+ });
+ }
+ }
+ },
+ };
+ },
+});
diff --git a/packages/eslint-plugin/src/tests/non-pure-animation.test.ts b/packages/eslint-plugin/src/tests/non-pure-animation.test.ts
new file mode 100644
index 0000000000..c72fb7914e
--- /dev/null
+++ b/packages/eslint-plugin/src/tests/non-pure-animation.test.ts
@@ -0,0 +1,168 @@
+import {ESLintUtils} from '@typescript-eslint/utils';
+import rule from '../rules/non-pure-animation';
+
+const ruleTester = new ESLintUtils.RuleTester({
+ parser: '@typescript-eslint/parser',
+ parserOptions: {
+ ecmaFeatures: {
+ jsx: true,
+ },
+ },
+});
+
+ruleTester.run('non-pure-animation', rule, {
+ valid: [
+ `const style = {color: "red"}`,
+ `const style = {backgroundColor: "blue"}`,
+ `const style = {transform: "translateX(10px)"}`,
+ `const style = {opacity: 0.5}`,
+ // Valid Tailwind classes (no transition properties)
+ `<div className="text-red-500 bg-blue-500 p-4" />`,
+ `<div className="font-bold text-lg" />`,
+ `<div className="transform translate-x-4" />`,
+ `<div className="opacity-50" />`,
+ `<div className={"text-blue-500"} />`,
+ // These should NOT match because they don't have transition
+ `<div className="translate-x-4 rotate-45" />`,
+ `<div className="duration-300" />`, // duration without transition is fine
+ `<div className="ease-in-out" />`, // easing without transition is fine,
+ ],
+ invalid: [
+ {
+ code: `const style = {transition: "all 0.3s ease"}`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ {
+ code: `const style = {"transition": "opacity 0.5s"}`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ {
+ code: `const style = {
+ color: "red",
+ transition: "all 0.3s ease"
+ }`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ // Tailwind transition classes
+ {
+ code: `<div className="transition" />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ {
+ code: `<div className="transition-all" />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ {
+ code: `<div className="transition-opacity" />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ {
+ code: `<div className="transition-colors" />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ {
+ code: `<div className="transition-transform" />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ {
+ code: `<div className="transition-shadow" />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ {
+ code: `<div className="transition-spacing" />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ {
+ code: `<div className="text-red-500 transition-all p-4" />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ {
+ code: `<div className="transition-opacity bg-blue-500" />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ // JSX Expression Container
+ {
+ code: `<div className={"transition-all"} />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ // Template literal
+ {
+ code: `<div className={\`transition-colors \${variant}\`} />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ // Multiple transition classes
+ {
+ code: `<div className="transition-opacity transition-transform" />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ // Edge case: transition-none should still be flagged
+ {
+ code: `<div className="transition-none" />`,
+ errors: [
+ {
+ messageId: 'NonPureAnimation',
+ },
+ ],
+ },
+ ],
+});