Skip to content

🎥 Make videos programmatically with React

eslint rule duration-in-frame

khalid ansari7050b84ddcb2
diff --git a/packages/eslint-plugin/src/index.ts b/packages/eslint-plugin/src/index.ts
index 2420ec7da5..17f2ec0fb8 100644
--- a/packages/eslint-plugin/src/index.ts
+++ b/packages/eslint-plugin/src/index.ts
@@ -3,6 +3,7 @@ import evenDimensions from "./rules/even-dimensions";
import nomp4Import from "./rules/no-mp4-import";
import noStringAssets from "./rules/no-string-assets";
import warnNativeMediaTag from "./rules/warn-native-media-tag";
+import durationInFrames from "./rules/no-duration-frames-infinity";
const rules = {
"no-mp4-import": nomp4Import,
@@ -10,6 +11,7 @@ const rules = {
"deterministic-randomness": deterministicRandomness,
"no-string-assets": noStringAssets,
"even-dimensions": evenDimensions,
+ "duration-in-frames": durationInFrames
};
export = {
diff --git a/packages/eslint-plugin/src/rules/no-duration-frames-infinity.ts b/packages/eslint-plugin/src/rules/no-duration-frames-infinity.ts
new file mode 100644
index 0000000000..6a46845b09
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/no-duration-frames-infinity.ts
@@ -0,0 +1,79 @@
+import { ESLintUtils } from "@typescript-eslint/experimental-utils";
+
+const createRule = ESLintUtils.RuleCreator((name) => {
+ return `https://github.com/remotion-dev/remotion`;
+});
+
+type Options = [];
+
+type MessageIds = "DurationInFrames";
+
+const DurationInFrames = "Sequence component prop durationInFrames by default value is Infinity";
+
+export default createRule<Options, MessageIds>({
+ name: "duration-in-frames",
+ meta: {
+ type: "problem",
+ docs: {
+ description: DurationInFrames,
+ category: "Best Practices",
+ recommended: "warn",
+ },
+ fixable: undefined,
+ schema: [],
+ messages: {
+ DurationInFrames,
+ },
+ },
+ defaultOptions: [],
+ create: (context) => {
+ return {
+ JSXAttribute: (node) => {
+ if (node.type !== "JSXAttribute") {
+ return;
+ }
+
+ if (node.name.name !== "durationInFrames") {
+ return;
+ }
+ const value = node.value;
+ if (!value || value.type !== "JSXExpressionContainer") {
+ return;
+ }
+
+ const expression = value.expression;
+ if (!expression || expression.type !== "Identifier") {
+ return;
+ }
+
+ const stringValue = expression.name;
+ if (typeof stringValue !== "string") {
+ return;
+ }
+
+ const parent = node.parent;
+ if (!parent) {
+ return;
+ }
+
+ if (parent.type !== "JSXOpeningElement") {
+ return;
+ }
+
+ const name = parent.name;
+ if (name.type !== "JSXIdentifier") {
+ return;
+ }
+ if (name.name !== "Sequence") {
+ return;
+ }
+ if (stringValue === "Infinity") {
+ context.report({
+ messageId: "DurationInFrames",
+ node,
+ });
+ }
+ },
+ };
+ },
+});
diff --git a/packages/eslint-plugin/src/tests/no-duration-frames-infinity.test.ts b/packages/eslint-plugin/src/tests/no-duration-frames-infinity.test.ts
new file mode 100644
index 0000000000..6a5fde2a67
--- /dev/null
+++ b/packages/eslint-plugin/src/tests/no-duration-frames-infinity.test.ts
@@ -0,0 +1,47 @@
+import { ESLintUtils } from "@typescript-eslint/experimental-utils";
+import rule from "../rules//no-duration-frames-infinity";
+
+const ruleTester = new ESLintUtils.RuleTester({
+ parser: "@typescript-eslint/parser",
+ parserOptions: {
+ ecmaFeatures: {
+ jsx: true,
+ },
+ },
+});
+
+ruleTester.run("no-duration-frames-infinity", rule, {
+ valid: [
+ `
+ import {Sequence} from 'remotion';
+
+ export const Re = () => {
+ return (
+ <Sequence durationInFrames={1}>
+ Hi
+ </Sequence>
+ );
+ }
+ `,
+ ],
+ invalid: [
+ {
+ code: `
+ import {Composition} from 'remotion';
+
+ export const Re = () => {
+ return (
+ <Sequence durationInFrames={Infinity} >
+ Hi
+ </Sequence>
+ );
+ }
+ `,
+ errors: [
+ {
+ messageId: "DurationInFrames",
+ },
+ ],
+ },
+ ],
+});