Skip to content

🎥 Make videos programmatically with React

new ESLint rule for helping migrate to new V4 import statement

Jonny Burger62e70abf766a
diff --git a/packages/eslint-plugin/src/index.ts b/packages/eslint-plugin/src/index.ts
index 3d6ade36b1..d684afd0f8 100644
--- a/packages/eslint-plugin/src/index.ts
+++ b/packages/eslint-plugin/src/index.ts
@@ -10,6 +10,7 @@ import staticFileNoRemote from "./rules/staticfile-no-remote";
import useGifComponent from "./rules/use-gif-component";
import volumeCallback from "./rules/volume-callback";
import warnNativeMediaTag from "./rules/warn-native-media-tag";
+import v4Import from "./rules/v4-import";
const rules = {
"no-mp4-import": nomp4Import,
@@ -24,6 +25,7 @@ const rules = {
"staticfile-no-relative": staticFileNoRelative,
"staticfile-no-remote": staticFileNoRemote,
"no-background-image": noBackgroundImage,
+ "v4-config-import": v4Import,
};
export = {
@@ -43,6 +45,7 @@ export = {
"@remotion/staticfile-no-relative": "error",
"@remotion/staticfile-no-remote": "error",
"@remotion/no-background-image": "error",
+ "@remotion/v4-config-import": "error",
},
},
},
diff --git a/packages/eslint-plugin/src/rules/v4-import.ts b/packages/eslint-plugin/src/rules/v4-import.ts
new file mode 100644
index 0000000000..3c832f936b
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/v4-import.ts
@@ -0,0 +1,49 @@
+import { ESLintUtils } from "@typescript-eslint/utils";
+
+const createRule = ESLintUtils.RuleCreator(() => {
+ return `https://v4.remotion.dev/docs/4-0-migration`;
+});
+
+type Options = [];
+
+type MessageIds = "ImportConfig";
+
+const ImportConfig =
+ "Update the import to the new V4 location: import {Config} from '@remotion/cli/config'";
+
+const rule = createRule<Options, MessageIds>({
+ name: "v4-config-import",
+ meta: {
+ type: "problem",
+ docs: {
+ description: ImportConfig,
+ recommended: "warn",
+ },
+ fixable: undefined,
+ schema: [],
+ messages: {
+ ImportConfig,
+ },
+ },
+ defaultOptions: [],
+ create: (context) => {
+ return {
+ ImportDeclaration: (node) => {
+ if (node.source.value !== "remotion") {
+ return;
+ }
+ const config = node.specifiers.find(
+ (s) => s.type === "ImportSpecifier" && s.imported.name === "Config"
+ );
+ if (config) {
+ context.report({
+ messageId: "ImportConfig",
+ node,
+ });
+ }
+ },
+ };
+ },
+});
+
+export default rule;
diff --git a/packages/eslint-plugin/src/tests/v4-import.test.ts b/packages/eslint-plugin/src/tests/v4-import.test.ts
new file mode 100644
index 0000000000..29a6879318
--- /dev/null
+++ b/packages/eslint-plugin/src/tests/v4-import.test.ts
@@ -0,0 +1,31 @@
+import { ESLintUtils } from "@typescript-eslint/utils";
+import rule from "../rules/v4-import";
+
+const ruleTester = new ESLintUtils.RuleTester({
+ parser: "@typescript-eslint/parser",
+});
+
+ruleTester.run("no-mp4-import", rule, {
+ valid: [
+ 'import {interpolate} from "remotion"',
+ 'import {Config} from "@remotion/cli/config"',
+ ],
+ invalid: [
+ {
+ code: 'import {Config} from "remotion"',
+ errors: [
+ {
+ messageId: "ImportConfig",
+ },
+ ],
+ },
+ {
+ code: 'import {Config, interpolate} from "remotion"',
+ errors: [
+ {
+ messageId: "ImportConfig",
+ },
+ ],
+ },
+ ],
+});