Skip to content

🎥 Make videos programmatically with React

eslint plugin: warn about `<Video src={"string-asset"}>`, not just `<Video src="string-asset">`

Jonny Burgerbe46f3dca368
diff --git a/packages/eslint-plugin/src/rules/no-string-assets.ts b/packages/eslint-plugin/src/rules/no-string-assets.ts
index ed0283d450..3b4fcb16c8 100644
--- a/packages/eslint-plugin/src/rules/no-string-assets.ts
+++ b/packages/eslint-plugin/src/rules/no-string-assets.ts
@@ -38,13 +38,26 @@ export default createRule<Options, MessageIds>({
return;
}
const value = node.value;
- if (!value || value.type !== "Literal") {
+ // src={"some string"}
+ const insideCurlyBraces =
+ value &&
+ value.type === "JSXExpressionContainer" &&
+ value.expression.type === "Literal";
+ if (!value || (value.type !== "Literal" && !insideCurlyBraces)) {
return;
}
- const stringValue = value.value;
+ const stringValue =
+ value &&
+ value.type === "JSXExpressionContainer" &&
+ value.expression.type === "Literal"
+ ? value.expression.value
+ : value.type === "Literal"
+ ? value.value
+ : null;
if (typeof stringValue !== "string") {
return;
}
+
const parent = node.parent;
if (!parent) {
return;
diff --git a/packages/eslint-plugin/src/tests/no-string-assets.test.ts b/packages/eslint-plugin/src/tests/no-string-assets.test.ts
index 9d83a59a4f..6057aca58e 100644
--- a/packages/eslint-plugin/src/tests/no-string-assets.test.ts
+++ b/packages/eslint-plugin/src/tests/no-string-assets.test.ts
@@ -67,6 +67,22 @@ export const Re = () => {
},
{
code: `
+import {Img} from 'remotion';
+
+export const Re = () => {
+ return (
+ <Img src={"curly"} />
+ );
+}
+ `,
+ errors: [
+ {
+ messageId: "NoStringAssets",
+ },
+ ],
+ },
+ {
+ code: `
import {Audio} from 'remotion';
export const Re = () => {