From 6c9d606f84c2aacb033e6d5ae43a32b5ff332f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Ka=C5=BAmierczak?= Date: Mon, 16 Sep 2024 13:09:13 +0200 Subject: [PATCH] Add eslint rule @typescript-eslint/no-floating-promises in `demos` and `docs` directory (#769) --- .vscode/settings.json | 3 ++- demos/.eslintrc.json | 6 ++++++ demos/1-videoconferencing/index.ts | 6 +++--- demos/2-tv_broadcast/index.ts | 6 +++--- demos/3-live_stream/index.ts | 8 ++++---- demos/utils/ffmpeg.ts | 4 ++-- demos/utils/generate_types.ts | 2 +- demos/utils/gst.ts | 13 +++++++------ demos/utils/run.ts | 4 ++-- docs/.eslintrc.json | 6 ++++++ docs/src/components/PlaygroundSettingsImages.tsx | 4 ++-- docs/src/components/PlaygroundSettingsInputs.tsx | 4 ++-- docs/src/components/PlaygroundSettingsShaders.tsx | 4 ++-- 13 files changed, 42 insertions(+), 28 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e7deee716..0348ca7fe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,5 +6,6 @@ ], "url": "./schemas/scene.schema.json" } - ] + ], + "eslint.workingDirectories": [{ "mode": "auto" }] } diff --git a/demos/.eslintrc.json b/demos/.eslintrc.json index f61c0e759..fc0d40cca 100644 --- a/demos/.eslintrc.json +++ b/demos/.eslintrc.json @@ -14,9 +14,15 @@ "prettier" ], "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": [ + "tsconfig.json" + ] + }, "rules": { "prettier/prettier": ["error"], "@typescript-eslint/no-explicit-any": [0, {}], + "@typescript-eslint/no-floating-promises": "error", "no-constant-condition": [0] } } diff --git a/demos/1-videoconferencing/index.ts b/demos/1-videoconferencing/index.ts index 165f62ae7..7070c9b63 100644 --- a/demos/1-videoconferencing/index.ts +++ b/demos/1-videoconferencing/index.ts @@ -65,11 +65,11 @@ async function exampleAsync() { }); if (useWebCam) { - gstStreamWebcam(IP, INPUT_PORT, DISPLAY_LOGS); + void gstStreamWebcam(IP, INPUT_PORT, DISPLAY_LOGS); } else { const callPath = path.join(__dirname, '../assets/call.mp4'); await downloadAsync(CALL_URL, callPath); - ffmpegSendVideoFromMp4(INPUT_PORT, callPath, DISPLAY_LOGS); + void ffmpegSendVideoFromMp4(INPUT_PORT, callPath, DISPLAY_LOGS); } await startAsync(); @@ -166,4 +166,4 @@ function sceneWithInputs(n: number): Component { }; } -runCompositorExample(exampleAsync, DISPLAY_LOGS); +void runCompositorExample(exampleAsync, DISPLAY_LOGS); diff --git a/demos/2-tv_broadcast/index.ts b/demos/2-tv_broadcast/index.ts index 4ece66a62..9a6c6e095 100644 --- a/demos/2-tv_broadcast/index.ts +++ b/demos/2-tv_broadcast/index.ts @@ -36,7 +36,7 @@ const LOGO_URL = 'https://raw.githubusercontent.com/membraneframework-labs/video_compositor_snapshot_tests/main/demo_assets/logo.png'; async function exampleAsync() { - ffplayStartPlayerAsync(IP, DISPLAY_LOGS, VIDEO_OUTPUT_PORT, AUDIO_OUTPUT_PORT); + void ffplayStartPlayerAsync(IP, DISPLAY_LOGS, VIDEO_OUTPUT_PORT, AUDIO_OUTPUT_PORT); await sleepAsync(2000); process.env.LIVE_COMPOSITOR_LOGGER_LEVEL = 'debug'; @@ -102,7 +102,7 @@ async function exampleAsync() { }, }); - ffmpegSendVideoFromMp4(INPUT_PORT, TV_PATH, DISPLAY_LOGS); + void ffmpegSendVideoFromMp4(INPUT_PORT, TV_PATH, DISPLAY_LOGS); await startAsync(); // First update to set start position of the bunny for transition @@ -318,4 +318,4 @@ function logo(): Component { }; } -runCompositorExample(exampleAsync, DISPLAY_LOGS); +void runCompositorExample(exampleAsync, DISPLAY_LOGS); diff --git a/demos/3-live_stream/index.ts b/demos/3-live_stream/index.ts index cc38c58b2..4e6e35754 100644 --- a/demos/3-live_stream/index.ts +++ b/demos/3-live_stream/index.ts @@ -100,13 +100,13 @@ async function exampleAsync() { }); if (useWebCam) { - gstStreamWebcam(IP, WEBCAM_INPUT_PORT, DISPLAY_LOGS); + void gstStreamWebcam(IP, WEBCAM_INPUT_PORT, DISPLAY_LOGS); } else { const callPath = path.join(__dirname, '../assets/call.mp4'); await downloadAsync(CALL_URL, callPath); - ffmpegSendVideoFromMp4(WEBCAM_INPUT_PORT, callPath, DISPLAY_LOGS); + void ffmpegSendVideoFromMp4(WEBCAM_INPUT_PORT, callPath, DISPLAY_LOGS); } - ffmpegSendVideoFromMp4(GAMEPLAY_PORT, gameplayPath, DISPLAY_LOGS); + void ffmpegSendVideoFromMp4(GAMEPLAY_PORT, gameplayPath, DISPLAY_LOGS); await sleepAsync(2000); await startAsync(); @@ -232,4 +232,4 @@ function baseScene(): Component { }; } -runCompositorExample(exampleAsync, DISPLAY_LOGS); +void runCompositorExample(exampleAsync, DISPLAY_LOGS); diff --git a/demos/utils/ffmpeg.ts b/demos/utils/ffmpeg.ts index 42842881a..bf0aeefd9 100644 --- a/demos/utils/ffmpeg.ts +++ b/demos/utils/ffmpeg.ts @@ -81,7 +81,7 @@ async function writeVideoAudioSdpFile( audio_port: number, destination: string ): Promise { - fs.writeFile( + await fs.writeFile( destination, ` v=0 @@ -100,7 +100,7 @@ a=rtcp-mux } async function writeVideoSdpFile(ip: string, port: number, destination: string): Promise { - fs.writeFile( + await fs.writeFile( destination, ` v=0 diff --git a/demos/utils/generate_types.ts b/demos/utils/generate_types.ts index fc31ca72a..5eb5e32bf 100644 --- a/demos/utils/generate_types.ts +++ b/demos/utils/generate_types.ts @@ -12,4 +12,4 @@ async function generateTypes() { fs.writeFileSync(tsOutputPath, typesTs); } -generateTypes(); +void generateTypes(); diff --git a/demos/utils/gst.ts b/demos/utils/gst.ts index ef1d54a20..ed1b2ce91 100644 --- a/demos/utils/gst.ts +++ b/demos/utils/gst.ts @@ -20,7 +20,7 @@ export function gstStreamWebcam(ip: string, port: number, displayOutput: boolean : ['v4l2src', 'x264enc', 'tune=zerolatency bitrate=2000 speed-preset=superfast']; const plugins = [gstWebcamSource, 'videoconvert', gstEncoder, 'rtph264pay', 'udpsink']; - checkGstPlugins(plugins); + void checkGstPlugins(plugins); const gstCommand = `gst-launch-1.0 -v ` + @@ -29,14 +29,15 @@ export function gstStreamWebcam(ip: string, port: number, displayOutput: boolean return spawn('bash', ['-c', gstCommand], { displayOutput }); } -function checkGstPlugins(plugins: string[]) { - plugins.forEach(plugin => { - isGstPluginAvailable(plugin).then(isAvailable => { +async function checkGstPlugins(plugins: string[]) { + await Promise.all( + plugins.map(async plugin => { + const isAvailable = await isGstPluginAvailable(plugin); if (!isAvailable) { throw Error(`Gstreamer plugin: ${plugin} is not available.`); } - }); - }); + }) + ); } function isGstPluginAvailable(pluginName: string): Promise { diff --git a/demos/utils/run.ts b/demos/utils/run.ts index 2362e6ebe..61daa408f 100644 --- a/demos/utils/run.ts +++ b/demos/utils/run.ts @@ -11,7 +11,7 @@ export async function runCompositorExample( await ensureCompositorReadyAsync(); const { command, args, cwd } = getCompositorRunCmd(); try { - spawn(command, args, { + void spawn(command, args, { displayOutput: displayOutput, cwd: cwd ?? process.cwd(), }); @@ -20,7 +20,7 @@ export async function runCompositorExample( await fn(); } catch (err) { - logError(err); + await logError(err); throw err; } } diff --git a/docs/.eslintrc.json b/docs/.eslintrc.json index 3a6771e5d..0145fb930 100644 --- a/docs/.eslintrc.json +++ b/docs/.eslintrc.json @@ -16,11 +16,17 @@ "prettier" ], "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": [ + "tsconfig.json" + ] + }, "rules": { "prettier/prettier": [ "error" ], "@typescript-eslint/no-explicit-any": 0, + "@typescript-eslint/no-floating-promises": "error", "no-constant-condition": [ 0 ], diff --git a/docs/src/components/PlaygroundSettingsImages.tsx b/docs/src/components/PlaygroundSettingsImages.tsx index 9bad6f485..1e4c6d222 100644 --- a/docs/src/components/PlaygroundSettingsImages.tsx +++ b/docs/src/components/PlaygroundSettingsImages.tsx @@ -111,8 +111,8 @@ function ImagePreview({ image_id, description, filename }: ImagePreviewProps) { {`Add `} { - navigator.clipboard.writeText(json); + onClick={async () => { + await navigator.clipboard.writeText(json); toast.success('Copied to clipboard!'); }}> {json} diff --git a/docs/src/components/PlaygroundSettingsInputs.tsx b/docs/src/components/PlaygroundSettingsInputs.tsx index e81ef0f00..e13580d4c 100644 --- a/docs/src/components/PlaygroundSettingsInputs.tsx +++ b/docs/src/components/PlaygroundSettingsInputs.tsx @@ -83,8 +83,8 @@ function InputResolutionSelect({ {`Add `} { - navigator.clipboard.writeText(json); + onClick={async () => { + await navigator.clipboard.writeText(json); toast.success('Copied to clipboard!'); }}> {json} diff --git a/docs/src/components/PlaygroundSettingsShaders.tsx b/docs/src/components/PlaygroundSettingsShaders.tsx index 4244b6706..4c369dc2d 100644 --- a/docs/src/components/PlaygroundSettingsShaders.tsx +++ b/docs/src/components/PlaygroundSettingsShaders.tsx @@ -77,8 +77,8 @@ function ShaderInfo({ shader_id, description, tooltipJson }: ShaderInfoProps) { {`Add `} { - navigator.clipboard.writeText(tooltipJson); + onClick={async () => { + await navigator.clipboard.writeText(tooltipJson); toast.success('Copied to clipboard!'); }}> {tooltipJson}