Skip to content

Commit

Permalink
Fix a bunch of lint errors
Browse files Browse the repository at this point in the history
[dependabot skip]
  • Loading branch information
swissspidy committed Dec 2, 2024
1 parent 38598d8 commit a9e4ac8
Show file tree
Hide file tree
Showing 28 changed files with 49 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('AnimationProvider', () => {
rotationAngle: 0,
};
const elements = [element1, element2];
const animType = AnimationType.Move as const;
const animType = AnimationType.Move;
const args = [
{ bounces: 3, duration: 1000 },
{ blinks: 2, offset: 20, blarks: 6, duration: 1000 },
Expand Down
16 changes: 8 additions & 8 deletions packages/animation/src/utils/getOffPageOffset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ import {
type DimensionableElement,
} from '@googleforcreators/units';

function calcTopOffset(box: ElementBox, dangerZoneOffset: number) {
function calcTopOffset(box: ElementBox, dangerZoneOffset: number): number {
const { y, height } = box;
const toTop = dangerZoneOffset + y;
return -Number((toTop / height) * 100.0 + 100.0).toFixed(5);
return -Number(Number((toTop / height) * 100.0 + 100.0).toFixed(5));
}

function calcBottomOffset(box: ElementBox, dangerZoneOffset: number) {
function calcBottomOffset(box: ElementBox, dangerZoneOffset: number): number {
const { y, height } = box;
const toBottom = 100 - y + dangerZoneOffset;
return Number((toBottom / height) * 100.0).toFixed(5);
return Number(Number((toBottom / height) * 100.0).toFixed(5));
}

function calcLeftOffset(box: ElementBox) {
function calcLeftOffset(box: ElementBox): number {
const { x, width } = box;
return -Number((x / width) * 100.0 + 100.0).toFixed(5);
return -Number(Number((x / width) * 100.0 + 100.0).toFixed(5));
}

function calcRightOffset(box: ElementBox) {
function calcRightOffset(box: ElementBox): number {
const { x, width } = box;
const toRight = 100 - x;
return Number((toRight / width) * 100.0).toFixed(5);
return Number(Number((toRight / width) * 100.0).toFixed(5));
}

function getOffPageOffset(element: DimensionableElement) {
Expand Down
2 changes: 1 addition & 1 deletion packages/animation/src/utils/test/getTotalDuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const BASE_ANIMATION = {
id: '1',
targets: [],
};
const type = AnimationType.BlinkOn as const;
const type = AnimationType.BlinkOn;

describe('getTotalDuration', () => {
it('returns 0 if no animations supplied', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ const Button = forwardRef(function Button(

const handleClick = (evt: MouseEvent<HTMLButtonElement>) => {
onClick(evt);
dismissOnClick && onDismiss(evt.nativeEvent);
if (dismissOnClick) {
onDismiss(evt.nativeEvent);
}
};

const handleFocus = (evt: FocusEvent<HTMLButtonElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ function SnackbarMessage({
const handleAction = useCallback(
(evt: MouseEvent<HTMLButtonElement>) => {
onAction(evt);
!isPreventActionDismiss && onDismiss();
if (!isPreventActionDismiss) {
onDismiss();
}
},
[onAction, onDismiss, isPreventActionDismiss]
);
Expand Down
1 change: 1 addition & 0 deletions packages/design-system/src/typings/styled.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ import 'styled-components';
import type { Theme } from '../theme';

declare module 'styled-components' {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type -- On purpose.
export interface DefaultTheme extends Theme {}
}
2 changes: 1 addition & 1 deletion packages/element-library/src/text/display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function TextDisplay({
target.style.fontSize = updatedFontSize
? `${dataToEditorY(updatedFontSize)}px`
: '';
const updatedMargin = transform?.updates?.marginOffset;
const updatedMargin = transform?.updates?.marginOffset as number;
target.style.margin = updatedMargin
? `${dataToEditorY(-updatedMargin) / 2}px 0`
: '';
Expand Down
4 changes: 3 additions & 1 deletion packages/element-library/src/text/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ function TextEdit({
editWrapper.style.left = `${boxRef.current.x + dx}px`;
editWrapper.style.top = `${boxRef.current.y + dy}px`;
}
onResize && onResize();
if (onResize) {
onResize();
}
}
}, [dataToEditorY, editWrapper, element, onResize, top, bottom]);
// Invoke on each content update.
Expand Down
2 changes: 1 addition & 1 deletion packages/media/src/seekVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function seekVideo(video: HTMLVideoElement, offset = 0.99): Promise<void> {
video.addEventListener('seeking', (evt) => {
const wait = setTimeout(() => {
clearTimeout(wait);
reject(evt);
reject(evt as unknown as Error);
}, THREE_SECONDS);
});
video.addEventListener('error', reject);
Expand Down
2 changes: 1 addition & 1 deletion packages/rich-text/src/fauxSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function useFauxSelection(

// Save that as the next editor state
return selectedState;
} catch (e) {
} catch {
// If the component has unmounted/remounted, some of the above might throw
// if so, just ignore it and return old state
return oldEditorState;
Expand Down
2 changes: 1 addition & 1 deletion packages/rich-text/src/formatters/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function stylesToCSS(styles: DraftInlineStyle): null | CSSProperties {
let color: Pattern;
try {
color = styleToColor(style);
} catch (e) {
} catch {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rich-text/src/formatters/gradientColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function stylesToCSS(styles: DraftInlineStyle): null | CSSProperties {
let color: Pattern;
try {
color = styleToColor(colorStyle);
} catch (e) {
} catch {
return null;
}

Expand Down
5 changes: 1 addition & 4 deletions packages/rich-text/src/formatters/italic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ function isItalic(editorState: EditorState) {
return !styles.includes(NONE);
}

function toggleItalic(
editorState: EditorState,
flag?: undefined | boolean
): EditorState {
function toggleItalic(editorState: EditorState, flag?: boolean): EditorState {
if (typeof flag === 'boolean') {
return togglePrefixStyle(editorState, ITALIC, () => flag);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rich-text/src/formatters/underline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function isUnderline(editorState: EditorState) {
return !styles.includes(NONE);
}

function toggleUnderline(editorState: EditorState, flag?: undefined | boolean) {
function toggleUnderline(editorState: EditorState, flag?: boolean) {
if (typeof flag === 'boolean') {
return togglePrefixStyle(editorState, UNDERLINE, () => flag);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rich-text/src/formatters/uppercase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function isUppercase(editorState: EditorState) {
return !styles.includes(NONE);
}

function toggleUppercase(editorState: EditorState, flag?: undefined | boolean) {
function toggleUppercase(editorState: EditorState, flag?: boolean) {
if (typeof flag === 'boolean') {
return togglePrefixStyle(editorState, UPPERCASE, () => flag);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rich-text/src/formatters/weight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function isBold(editorState: EditorState) {
return weights.every((w) => w >= SMALLEST_BOLD);
}

function toggleBold(editorState: EditorState, flag?: undefined | boolean) {
function toggleBold(editorState: EditorState, flag?: boolean) {
if (typeof flag === 'boolean') {
if (flag) {
const getDefault = () => weightToStyle(DEFAULT_BOLD);
Expand Down
2 changes: 1 addition & 1 deletion packages/story-editor/src/app/canvas/useCanvasCopyPaste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function useCanvasGlobalKeys() {
if (files.length > 0) {
uploadWithPreview(files);
}
} catch (e) {
} catch {
// Ignore.
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function useDetectBaseColor({
});
}
}
} catch (error) {
} catch {
// This might happen as an author when trying to updateMedia() that
// was uploaded by someone else.
// Do nothing with the error for now.
Expand Down Expand Up @@ -163,7 +163,7 @@ function useDetectBaseColor({
if (posterResource) {
imageSrc = getSmallestUrlForWidth(0, posterResource);
}
} catch (error) {
} catch {
// The user might not have the permission to access the video with context=edit.
// This might happen as an author when the video
// was uploaded by someone else.
Expand All @@ -181,7 +181,7 @@ function useDetectBaseColor({
try {
const color = await getMediaBaseColor(imageSrcProxied);
await saveBaseColor(resource, color);
} catch (error) {
} catch {
// Do nothing for now.
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function useDetectVideoHasAudio({
isMuted: !hasAudio,
});
}
} catch (error) {
} catch {
// Do nothing for now.
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/story-editor/src/app/media/utils/useFFmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ function useFFmpeg() {
try {
ffmpeg?.exit();
// eslint-disable-next-line no-empty -- no-op
} catch (e) {}
} catch {}

trackTiming();
}
Expand Down Expand Up @@ -674,7 +674,7 @@ function useFFmpeg() {
try {
ffmpeg?.exit();
// eslint-disable-next-line no-empty -- no-op
} catch (e) {}
} catch {}

trackTiming();
}
Expand Down
12 changes: 6 additions & 6 deletions packages/story-editor/src/app/media/utils/useProcessMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function useProcessMedia({
let file = null;
try {
file = await fetchRemoteFile(url, mimeType);
} catch (e) {
} catch {
// Ignore for now.
return;
}
Expand Down Expand Up @@ -352,14 +352,14 @@ function useProcessMedia({
let posterFile = null;
try {
file = await fetchRemoteFile(url, mimeType);
} catch (e) {
} catch {
// Ignore for now.
return;
}
if (poster) {
try {
posterFile = await fetchRemoteBlob(poster);
} catch (e) {
} catch {
// Ignore for now.
}
}
Expand Down Expand Up @@ -451,14 +451,14 @@ function useProcessMedia({
let posterFile = null;
try {
file = await fetchRemoteFile(url, mimeType);
} catch (e) {
} catch {
// Ignore for now.
return;
}
if (poster) {
try {
posterFile = await fetchRemoteBlob(poster);
} catch (e) {
} catch {
// Ignore for now.
}
}
Expand Down Expand Up @@ -530,7 +530,7 @@ function useProcessMedia({
let file = null;
try {
file = await fetchRemoteFile(url, mimeType);
} catch (e) {
} catch {
// Ignore for now.
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function useHashState(
}
_value = JSON.parse(decodeURI(paramValue)) as string;
}
} catch (e) {
} catch {
// @TODO Add some error handling
}
return _value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function getElementProperties(type: ElementType, element: Element) {
let resource, scale, focalX, focalY, sticker;
if (elementIs.sticker(element)) {
sticker = element.sticker;
ratio = STICKERS?.[sticker.type as keyof typeof STICKERS]?.aspectRatio;
ratio = STICKERS?.[sticker.type]?.aspectRatio;
} else if (elementIs.media(element)) {
resource = element.resource;
ratio =
Expand Down
2 changes: 1 addition & 1 deletion packages/story-editor/src/utils/getMediaBaseColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function extractColorFromImage(img: HTMLImageElement): Promise<string> {
if (err instanceof Error) {
void trackError('image_base_color', err.message);
}
reject(err);
reject(err as Error);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/story-editor/src/utils/useCORSProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function useCORSProxy() {
await fetch(link, {
method: 'HEAD',
});
} catch (err) {
} catch {
shouldProxy = true;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/story-editor/src/utils/useRefreshPostEditURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function useRefreshPostEditURL(postId: number, postEditURL: string) {
),
newUrl.toString()
);
} catch (error) {
} catch {
// Do nothing for now.
}
}, [postId, postEditURL]);
Expand Down
2 changes: 1 addition & 1 deletion packages/url/src/safeDecodeUriComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
export default function safeDecodeURIComponent(uriComponent: string) {
try {
return decodeURIComponent(uriComponent);
} catch (uriComponentError) {
} catch {
return uriComponent;
}
}
2 changes: 1 addition & 1 deletion packages/url/src/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
export function toAbsoluteUrl(base: string, path: string): string {
try {
return new URL(path, base).href;
} catch (error) {
} catch {
return path;
}
}
Expand Down

0 comments on commit a9e4ac8

Please sign in to comment.