Skip to content

🎥 Make videos programmatically with React

eslint rule preventing unintended logs

Jonny Burger5abf73d20e22
diff --git a/packages/core/.eslintrc b/packages/core/.eslintrc
index 14328b84f6..e1b7605318 100644
--- a/packages/core/.eslintrc
+++ b/packages/core/.eslintrc
@@ -1,3 +1,6 @@
{
- "extends": ["@jonny"]
+ "extends": ["@jonny"],
+ "rules": {
+ "no-console": "error"
+ }
}
diff --git a/packages/core/src/IFrame.tsx b/packages/core/src/IFrame.tsx
index c9bb886267..64225193b3 100644
--- a/packages/core/src/IFrame.tsx
+++ b/packages/core/src/IFrame.tsx
@@ -26,6 +26,7 @@ const IFrameRefForwarding: React.ForwardRefRenderFunction<
if (onError) {
onError(e);
} else {
+ // eslint-disable-next-line no-console
console.error(
'Error loading iframe:',
e,
diff --git a/packages/core/src/Img.tsx b/packages/core/src/Img.tsx
index 19587786ce..cc6d84a4ac 100644
--- a/packages/core/src/Img.tsx
+++ b/packages/core/src/Img.tsx
@@ -90,6 +90,7 @@ const ImgRefForwarding: React.ForwardRefRenderFunction<
const backoff = exponentialBackoff(
errors.current[imageRef.current?.src as string] ?? 0,
);
+ // eslint-disable-next-line no-console
console.warn(
`Could not load image with source ${
imageRef.current?.src as string
@@ -120,6 +121,7 @@ const ImgRefForwarding: React.ForwardRefRenderFunction<
const onComplete = () => {
if ((errors.current[imageRef.current?.src as string] ?? 0) > 0) {
delete errors.current[imageRef.current?.src as string];
+ // eslint-disable-next-line no-console
console.info(
`Retry successful - ${
imageRef.current?.src as string
diff --git a/packages/core/src/audio/Audio.tsx b/packages/core/src/audio/Audio.tsx
index 0e13a6d595..5b2f3d3615 100644
--- a/packages/core/src/audio/Audio.tsx
+++ b/packages/core/src/audio/Audio.tsx
@@ -40,6 +40,7 @@ const AudioRefForwardingFunction: React.ForwardRefRenderFunction<
const onError: React.ReactEventHandler<HTMLAudioElement> = useCallback(
(e) => {
+ // eslint-disable-next-line no-console
console.log(e.currentTarget.error);
// If there is no `loop` property, we don't need to get the duration
@@ -49,6 +50,7 @@ const AudioRefForwardingFunction: React.ForwardRefRenderFunction<
if (loop) {
cancelRender(new Error(errMessage));
} else {
+ // eslint-disable-next-line no-console
console.warn(errMessage);
}
},
diff --git a/packages/core/src/config/input-props.ts b/packages/core/src/config/input-props.ts
index c8007584c0..6f43e0671c 100644
--- a/packages/core/src/config/input-props.ts
+++ b/packages/core/src/config/input-props.ts
@@ -9,10 +9,13 @@ const warnOnceSSRImport = () => {
}
didWarnSSRImport = true;
+ // eslint-disable-next-line no-console
console.warn(
'Called `getInputProps()` on the server. This function is not available server-side and has returned an empty object.',
);
+ // eslint-disable-next-line no-console
console.warn("To hide this warning, don't call this function on the server:");
+ // eslint-disable-next-line no-console
console.warn(" typeof window === 'undefined' ? {} : getInputProps()");
};
diff --git a/packages/core/src/get-static-files.ts b/packages/core/src/get-static-files.ts
index 22aa95033d..2a6a296da1 100644
--- a/packages/core/src/get-static-files.ts
+++ b/packages/core/src/get-static-files.ts
@@ -7,6 +7,7 @@ const warnServerOnce = () => {
}
warnedServer = true;
+ // eslint-disable-next-line no-console
console.warn(
'Called getStaticFiles() on the server. The API is only available in the browser. An empty array was returned.',
);
@@ -18,6 +19,7 @@ const warnPlayerOnce = () => {
}
warnedPlayer = true;
+ // eslint-disable-next-line no-console
console.warn(
'Called getStaticFiles() while using the Remotion Player. The API is only available while using the Remotion Studio. An empty array was returned.',
);
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 3d7c36d330..fb89632dcf 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -165,6 +165,7 @@ export const Config = new Proxy(proxyObj, {
}
return () => {
+ /* eslint-disable no-console */
console.warn(
'⚠️ The CLI configuration has been extracted from Remotion Core.',
);
@@ -178,6 +179,7 @@ export const Config = new Proxy(proxyObj, {
console.warn(
'For more information, see https://www.remotion.dev/docs/4-0-migration.',
);
+ /* eslint-enable no-console */
process.exit(1);
};
diff --git a/packages/core/src/play-and-handle-not-allowed-error.ts b/packages/core/src/play-and-handle-not-allowed-error.ts
index d3860fd5ad..b59c11ee1d 100644
--- a/packages/core/src/play-and-handle-not-allowed-error.ts
+++ b/packages/core/src/play-and-handle-not-allowed-error.ts
@@ -49,8 +49,10 @@ export const playAndHandleNotAllowedError = (
return;
}
+ // eslint-disable-next-line no-console
console.log(`Could not play ${mediaType} due to following error: `, err);
if (!current.muted) {
+ // eslint-disable-next-line no-console
console.log(`The video will be muted and we'll retry playing it.`, err);
current.muted = true;
current.play();
diff --git a/packages/core/src/prefetch.ts b/packages/core/src/prefetch.ts
index 1bd78f4d15..1a575f5b15 100644
--- a/packages/core/src/prefetch.ts
+++ b/packages/core/src/prefetch.ts
@@ -88,6 +88,7 @@ export const prefetch = (
!buf.type.startsWith('audio/') &&
!options?.contentType
) {
+ // eslint-disable-next-line no-console
console.warn(
`Called prefetch() on ${src} which returned a "Content-Type" of ${buf.type}. Prefetched content should have a proper content type (video/... or audio/...) or a contentType passed the options of prefetch(). Otherwise, prefetching will not work properly in all browsers.`,
);
diff --git a/packages/core/src/static-file.ts b/packages/core/src/static-file.ts
index 40efd18f61..a5be72a374 100644
--- a/packages/core/src/static-file.ts
+++ b/packages/core/src/static-file.ts
@@ -35,6 +35,7 @@ const warnOnce = (message: string) => {
return;
}
+ // eslint-disable-next-line no-console
console.warn(message);
didWarn[message] = true;
};
diff --git a/packages/core/src/test/expect-to-throw.ts b/packages/core/src/test/expect-to-throw.ts
index 2a31ce7377..c2a5003c13 100644
--- a/packages/core/src/test/expect-to-throw.ts
+++ b/packages/core/src/test/expect-to-throw.ts
@@ -5,10 +5,12 @@ export const expectToThrow = (func: Function, err: RegExp) => {
// so we mock that out to avoid the wall of red text.
vitest.spyOn(console, 'error');
// @ts-expect-error
+ // eslint-disable-next-line no-console
console.error.mockImplementation(() => undefined);
expect(func).toThrow(err);
// @ts-expect-error
+ // eslint-disable-next-line no-console
console.error.mockRestore();
};
diff --git a/packages/core/src/use-media-in-timeline.ts b/packages/core/src/use-media-in-timeline.ts
index d203a30372..6683535049 100644
--- a/packages/core/src/use-media-in-timeline.ts
+++ b/packages/core/src/use-media-in-timeline.ts
@@ -19,6 +19,7 @@ const warnOnce = (message: string) => {
return;
}
+ // eslint-disable-next-line no-console
console.warn(message);
didWarn[message] = true;
};
diff --git a/packages/core/src/use-media-playback.ts b/packages/core/src/use-media-playback.ts
index 83a1342e04..a74d38a0c3 100644
--- a/packages/core/src/use-media-playback.ts
+++ b/packages/core/src/use-media-playback.ts
@@ -104,7 +104,6 @@ export const useMediaPlayback = ({
!Number.isNaN(duration) && Number.isFinite(duration)
? Math.min(duration, desiredUnclampedTime)
: desiredUnclampedTime;
-
const isTime = mediaRef.current.currentTime;
const timeShift = Math.abs(shouldBeTime - isTime);
diff --git a/packages/core/src/video/VideoForDevelopment.tsx b/packages/core/src/video/VideoForDevelopment.tsx
index 28eff2bbbf..a2f7d5c883 100644
--- a/packages/core/src/video/VideoForDevelopment.tsx
+++ b/packages/core/src/video/VideoForDevelopment.tsx
@@ -125,6 +125,7 @@ const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<
const errorHandler = () => {
if (current?.error) {
+ // eslint-disable-next-line no-console
console.error('Error occurred in video', current?.error);
// If user is handling the error, we don't cause an unhandled exception
if (props.onError) {
diff --git a/packages/core/src/video/VideoForRendering.tsx b/packages/core/src/video/VideoForRendering.tsx
index ad9fcd2454..cd011c6991 100644
--- a/packages/core/src/video/VideoForRendering.tsx
+++ b/packages/core/src/video/VideoForRendering.tsx
@@ -209,6 +209,7 @@ const VideoForRenderingForwardFunction: React.ForwardRefRenderFunction<
const errorHandler = () => {
if (current?.error) {
+ // eslint-disable-next-line no-console
console.error('Error occurred in video', current?.error);
// If user is handling the error, we don't cause an unhandled exception
diff --git a/packages/core/src/warn-about-non-seekable-media.ts b/packages/core/src/warn-about-non-seekable-media.ts
index 158c58e4ed..07ab798113 100644
--- a/packages/core/src/warn-about-non-seekable-media.ts
+++ b/packages/core/src/warn-about-non-seekable-media.ts
@@ -28,8 +28,10 @@ export const warnAboutNonSeekableMedia = (
const msg = `The media ${ref.src} cannot be seeked. This could be one of two reasons: 1) The media resource was replaced while the video is playing but it was not loaded yet. 2) The media does not support seeking. Please see https://remotion.dev/docs/non-seekable-media for assistance.`;
if (type === 'console-error') {
+ // eslint-disable-next-line no-console
console.error(msg);
} else if (type === 'console-warning') {
+ // eslint-disable-next-line no-console
console.warn(
`The media ${ref.src} does not support seeking. The video will render fine, but may not play correctly in the Remotion Studio and in the <Player>. See https://remotion.dev/docs/non-seekable-media for an explanation.`,
);
diff --git a/packages/core/src/watch-static-file.ts b/packages/core/src/watch-static-file.ts
index f8888fcaed..91b6d3d7cb 100644
--- a/packages/core/src/watch-static-file.ts
+++ b/packages/core/src/watch-static-file.ts
@@ -22,6 +22,7 @@ export const watchStaticFile = (
): {cancel: () => void} => {
// Check if function is called in Remotion Studio
if (!getRemotionEnvironment().isStudio) {
+ // eslint-disable-next-line no-console
console.warn('The API is only available while using the Remotion Studio.');
return {cancel: () => undefined};
}