From ccfae04cb4f6772b2f90a6e9b69b693b04c360d9 Mon Sep 17 00:00:00 2001 From: Arnei Date: Thu, 18 Jan 2024 12:44:28 +0100 Subject: [PATCH] Enforce eslint no-non-null-assertion Typescript specific. --- .eslintrc.js | 3 --- src/main/Header.tsx | 2 +- src/main/Tooltip.tsx | 2 +- src/main/VideoPlayers.tsx | 8 ++++++++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 196521403..82c508a8a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -24,9 +24,6 @@ module.exports = { // same line as `{`. "brace-style": "off", - // A few of those are used. - "@typescript-eslint/no-non-null-assertion": "off", - // Until we figure out how to get to React 18 "react/no-deprecated": "off", }, diff --git a/src/main/Header.tsx b/src/main/Header.tsx index f3ba406a5..0b21e214c 100644 --- a/src/main/Header.tsx +++ b/src/main/Header.tsx @@ -157,7 +157,7 @@ const LanguageButton: React.FC = () => { checked: isCurrentLanguage(lng.value), children: <>{lng.label}, onClick: () => { - changeLanguage(lng!.value); + changeLanguage(lng?.value); }, })); diff --git a/src/main/Tooltip.tsx b/src/main/Tooltip.tsx index 302a172cf..b170920ea 100644 --- a/src/main/Tooltip.tsx +++ b/src/main/Tooltip.tsx @@ -29,7 +29,7 @@ export const ThemedTooltip = ({ className, ...props }: TooltipProps) => { getBoundingClientRect: () => { return new DOMRect( positionRef.current.x, - areaRef.current!.getBoundingClientRect().y, + areaRef.current?.getBoundingClientRect().y, 0, positionRef.current.y, ); diff --git a/src/main/VideoPlayers.tsx b/src/main/VideoPlayers.tsx index 63270d581..18a8ac14d 100644 --- a/src/main/VideoPlayers.tsx +++ b/src/main/VideoPlayers.tsx @@ -306,13 +306,19 @@ export const VideoPlayer = React.forwardRef( // eslint-disable-next-line array-callback-return playerConfig.file.tracks.map((t, trackIdx) => { const track = document.createElement('track'); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion track.kind = t.kind!; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion track.label = t.label!; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion track.srclang = t.srcLang!; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion track.default = t.default!; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion track.src = t.src!; track.track.mode = 'showing' // Because the load callback may sometimes not execute properly track.addEventListener('error', (_e: Event) => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion console.warn(`Cannot load track ${t.src!}`) }); track.addEventListener('load', (e: Event) => { @@ -320,9 +326,11 @@ export const VideoPlayer = React.forwardRef( if (textTrack) { if (t.default === true) { textTrack.track.mode = 'showing'; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion video!.textTracks[trackIdx].mode = 'showing'; // thanks Firefox } else { textTrack.track.mode = 'hidden'; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion video!.textTracks[trackIdx].mode = 'hidden'; // thanks Firefox } }