Skip to content

🎥 Make videos programmatically with React

even dimensions

Jonny Burger316bb4b13529
diff --git a/packages/eslint-config/src/index.ts b/packages/eslint-config/src/index.ts
index f902da762d..5fc247df49 100644
--- a/packages/eslint-config/src/index.ts
+++ b/packages/eslint-config/src/index.ts
@@ -43,6 +43,7 @@ const getRules = (typescript: boolean) => {
"@remotion/warn-native-media-tag": "warn",
"@remotion/deterministic-randomness": "warn",
"@remotion/no-string-assets": "warn",
+ "@remotion/even-dimensions": "warn",
"@typescript-eslint/explicit-module-boundary-types": "off",
};
};
diff --git a/packages/eslint-plugin/src/index.ts b/packages/eslint-plugin/src/index.ts
index 09d1056f59..2420ec7da5 100644
--- a/packages/eslint-plugin/src/index.ts
+++ b/packages/eslint-plugin/src/index.ts
@@ -1,4 +1,5 @@
import deterministicRandomness from "./rules/deterministic-randomness";
+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";
@@ -8,6 +9,7 @@ const rules = {
"warn-native-media-tag": warnNativeMediaTag,
"deterministic-randomness": deterministicRandomness,
"no-string-assets": noStringAssets,
+ "even-dimensions": evenDimensions,
};
export = {
diff --git a/packages/eslint-plugin/src/rules/even-dimensions.ts b/packages/eslint-plugin/src/rules/even-dimensions.ts
new file mode 100644
index 0000000000..9f7c61071f
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/even-dimensions.ts
@@ -0,0 +1,78 @@
+import { ESLintUtils } from "@typescript-eslint/experimental-utils";
+
+const createRule = ESLintUtils.RuleCreator((name) => {
+ return `https://github.com/remotion-dev/remotion`;
+});
+
+type Options = [];
+
+type MessageIds = "EvenDimensions";
+
+const EvenDimensions =
+ "Videos rendered in H264 codec do not support dimensions that are not divisible by 2. Make the number even to resolve this warning. Ignore this warning if you don't plan on rendering this video with a H264 codec.";
+
+export default createRule<Options, MessageIds>({
+ name: "even-dimensions",
+ meta: {
+ type: "problem",
+ docs: {
+ description: EvenDimensions,
+ category: "Possible Errors",
+ recommended: "warn",
+ },
+ fixable: undefined,
+ schema: [],
+ messages: {
+ EvenDimensions,
+ },
+ },
+ defaultOptions: [],
+ create: (context) => {
+ return {
+ JSXAttribute: (node) => {
+ if (node.type !== "JSXAttribute") {
+ return;
+ }
+ if (node.name.name !== "width" && node.name.name !== "height") {
+ return;
+ }
+ const value = node.value;
+ if (!value || value.type !== "JSXExpressionContainer") {
+ return;
+ }
+
+ const expression = value.expression;
+ if (!expression || expression.type !== "Literal") {
+ return;
+ }
+
+ const stringValue = expression.value;
+ if (typeof stringValue !== "number") {
+ 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 !== "Composition") {
+ return;
+ }
+ if (stringValue % 2 !== 0) {
+ context.report({
+ messageId: "EvenDimensions",
+ node,
+ });
+ }
+ },
+ };
+ },
+});
diff --git a/packages/eslint-plugin/src/tests/even-dimensions.test.ts b/packages/eslint-plugin/src/tests/even-dimensions.test.ts
new file mode 100644
index 0000000000..825baf2615
--- /dev/null
+++ b/packages/eslint-plugin/src/tests/even-dimensions.test.ts
@@ -0,0 +1,77 @@
+import { ESLintUtils } from "@typescript-eslint/experimental-utils";
+import rule from "../rules/even-dimensions";
+
+const ruleTester = new ESLintUtils.RuleTester({
+ parser: "@typescript-eslint/parser",
+ parserOptions: {
+ ecmaFeatures: {
+ jsx: true,
+ },
+ },
+});
+
+ruleTester.run("even-dimensions", rule, {
+ valid: [
+ `
+import {Composition} from 'remotion';
+
+export const Re = () => {
+ return (
+ <Composition height={1000} />
+ );
+}
+ `,
+ `
+import {Composition} from 'remotion';
+
+export const Re = () => {
+ return (
+ <Composition width={1000} height={20} />
+ );
+}
+ `,
+ `
+import {Still} from 'remotion';
+
+export const Re = () => {
+ return (
+ <Still width={1001} height={20} />
+ );
+}
+ `,
+ ],
+ invalid: [
+ {
+ code: `
+import {Composition} from 'remotion';
+
+export const Re = () => {
+ return (
+ <Composition height={1001} />
+ );
+}
+ `,
+ errors: [
+ {
+ messageId: "EvenDimensions",
+ },
+ ],
+ },
+ {
+ code: `
+import {Composition} from 'remotion';
+
+export const Re = () => {
+ return (
+ <Composition width={1001} />
+ );
+}
+ `,
+ errors: [
+ {
+ messageId: "EvenDimensions",
+ },
+ ],
+ },
+ ],
+});