Skip to content

🎥 Make videos programmatically with React

Add ESLint Rule that automatically removes from={0}

Dhroov Makwanaf651f3fbdbe4
diff --git a/packages/eslint-plugin/src/rules/no-from-0.ts b/packages/eslint-plugin/src/rules/no-from-0.ts
new file mode 100644
index 0000000000..0cfb0af351
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/no-from-0.ts
@@ -0,0 +1,81 @@
+import { ESLintUtils } from "@typescript-eslint/utils";
+
+const createRule = ESLintUtils.RuleCreator(() => {
+ return `https://github.com/remotion-dev/remotion`;
+});
+
+type Options = [];
+
+type MessageIds = "From";
+
+const From = "0 is now the default, so you can remove the prop.";
+
+export default createRule<Options, MessageIds>({
+ name: "from",
+ meta: {
+ type: "problem",
+ docs: {
+ description: From,
+ recommended: "warn",
+ },
+ fixable: "code",
+ schema: [],
+ messages: {
+ From,
+ },
+ },
+ defaultOptions: [],
+ create: (context) => {
+ return {
+ JSXAttribute: (node) => {
+ if (node.type !== "JSXAttribute") {
+ return;
+ }
+
+ if (node.name.name !== "from") {
+ 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 === "0") {
+ context.report({
+ messageId: "From",
+ node,
+ fix: (fixer) => {
+ return fixer.removeRange([node.name.range[0], value.range[1]]);
+ },
+ });
+ }
+ },
+ };
+ },
+});