Skip to content

🎥 Make videos programmatically with React

don't give ESLint error on `<Gif src={staticFile("gif.gif")}>`

Jonny Burgerd85c84733345
diff --git a/packages/eslint-plugin/src/rules/use-gif-component.ts b/packages/eslint-plugin/src/rules/use-gif-component.ts
index 699afa2ec1..64a9977f4e 100644
--- a/packages/eslint-plugin/src/rules/use-gif-component.ts
+++ b/packages/eslint-plugin/src/rules/use-gif-component.ts
@@ -38,6 +38,21 @@ export default createRule<Options, MessageIds>({
if (node.name.name !== "src") {
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 !== "Img" && name.name !== "img") {
+ return;
+ }
+
const value = node.value;
// src={"some string"}
if (!value) {
@@ -53,25 +68,12 @@ export default createRule<Options, MessageIds>({
: null;
// src="image.gif"
if (typeof stringValue === "string") {
- const parent = node.parent;
- if (!parent) {
- return;
- }
- if (parent.type !== "JSXOpeningElement") {
- return;
- }
- const name = parent.name;
- if (name.type !== "JSXIdentifier") {
- return;
- }
- if (name.name === "Img" || name.name === "img") {
- // Network and inline URLs are okay
- if (stringValue.includes(".gif")) {
- context.report({
- messageId: "UseGifComponent",
- node,
- });
- }
+ // Network and inline URLs are okay
+ if (stringValue.includes(".gif")) {
+ context.report({
+ messageId: "UseGifComponent",
+ node,
+ });
}
}
diff --git a/packages/eslint-plugin/src/tests/use-gif-component.test.ts b/packages/eslint-plugin/src/tests/use-gif-component.test.ts
index bf9bcff1da..1a7b2d6e98 100644
--- a/packages/eslint-plugin/src/tests/use-gif-component.test.ts
+++ b/packages/eslint-plugin/src/tests/use-gif-component.test.ts
@@ -54,6 +54,16 @@ export const Re = () => {
return (
<Img src={img} />
);
+}
+ `,
+ `
+import {Gif} from '@remotion/gif';
+import {staticFile} from 'remotion';
+
+export const Re = () => {
+ return (
+ <Gif src={staticFile('gif.gif')} />
+ );
}
`,
],