Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwep committed Sep 24, 2020
1 parent e84f984 commit ad7906e
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 36 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
Expand Up @@ -37,15 +37,22 @@
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"react/jsx-indent-props": [2, "first"],
"react/react-in-jsx-scope": "off",
"react/display-name": "off",
"react/prop-types": "off",
"react/jsx-indent": [2, 4, {"checkAttributes": true}],
"no-multi-spaces": ["error", {"exceptions": {"ImportDeclaration": true}}],
"align-import/align-import": "error",
"no-use-before-define": "off",
"no-unused-vars": "off",
"func-call-spacing": "off",
"no-void": "off",
"indent": "off"
}
}
2 changes: 1 addition & 1 deletion src/app/overlays/DialogBox.tsx
Expand Up @@ -26,7 +26,7 @@ type InternalDialogItem = {
removing: boolean;
};

type Props = {};
type Props = unknown;
type State = {
dialogs: Array<InternalDialogItem>;
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/overlays/Toast.tsx
Expand Up @@ -10,7 +10,7 @@ export type ToastItem = {
body?: string;
};

type Props = {};
type Props = unknown;
type State = {
visible: boolean;
item: ToastItem;
Expand Down
4 changes: 2 additions & 2 deletions src/app/tabs/filelist/ActionBar.tsx
Expand Up @@ -14,7 +14,7 @@ export const ActionBar: FunctionalComponent = observer(() => {

// Tell the user that uploads are about to get cancelled
if (relatedUploads) {
DialogBox.instance.open({
void DialogBox.instance.open({
icon: 'exclamation-mark',
title: 'Uh Oh! Are you sure about that?',
description: 'This actions will cause all related streams and uploads to get cancelled, are you sure?',
Expand Down Expand Up @@ -47,7 +47,7 @@ export const ActionBar: FunctionalComponent = observer(() => {

return (
<div className={styles.actionBar}>
<button onClick={() => files.openDialog()}
<button onClick={() => void files.openDialog()}
className={styles.addBtn}
aria-label="Add files manually">
<bc-icon name="plus"/>
Expand Down
4 changes: 2 additions & 2 deletions src/app/tabs/filelist/DropZone.tsx
Expand Up @@ -5,7 +5,7 @@ import {observer} from 'mobx-react';
import {Component, h} from 'preact';
import styles from './DropZone.module.scss';

type Props = {};
type Props = unknown;
type State = {
dragover: boolean;
};
Expand Down Expand Up @@ -70,7 +70,7 @@ export class DropZone extends Component<Props, State> {

@bind
chooseFiles(): void {
files.openDialog();
void files.openDialog();
}

componentWillUnmount(): void {
Expand Down
6 changes: 3 additions & 3 deletions src/app/tabs/filelist/FileItem.tsx
Expand Up @@ -36,11 +36,11 @@ export class FileItem extends Component<Props> {
* and unusable.
*/
if (navigator.share && isMobile) {
navigator.share({
void navigator.share({
title: name,
text: `Download ${name}`,
url: link
}).then(() => null).then(() => null);
}).then(() => null);
} else {
copyToClipboard(link).then(() => {
toast.show('Link copied to clipboard!');
Expand All @@ -67,7 +67,7 @@ export class FileItem extends Component<Props> {

// Tell the user that uploads are about to get cancelled
if (relatedUploads > 0) {
DialogBox.instance.open({
void DialogBox.instance.open({
icon: 'exclamation-mark',
title: 'Uh Oh! Are you sure about that?',
description: relatedUploads > 1 ?
Expand Down
5 changes: 3 additions & 2 deletions src/app/tabs/filelist/FileList.tsx
Expand Up @@ -14,14 +14,15 @@ import {SearchBar} from './SearchBar';

export type SortKey = 'index' | 'name' | 'size';

type Props = unknown;
type State = {
searchTerm: null | string;
sortKey: SortKey;
toggleSortKey: boolean;
};

@observer
export class FileList extends Component<{}, State> {
export class FileList extends Component<Props, State> {
private readonly events = createNativeEventContainer();

readonly state = {
Expand All @@ -31,7 +32,7 @@ export class FileList extends Component<{}, State> {
};

componentDidMount() {
this.events.on(window, 'keydown', (e: KeyboardEvent) => {
this.events.on(window, 'keydown', (e: KeyboardEvent): void => {
switch (e.code) {
case 'KeyA': {
if (e.ctrlKey || e.metaKey) {
Expand Down
3 changes: 2 additions & 1 deletion src/app/tabs/settings/sections/Notifications.tsx
@@ -1,6 +1,7 @@
import {Switch} from '@components/Switch';
import {Toast} from '@overlays/Toast';
import {pushNotification, settings} from '@state/index';
import {UploadExtensions} from '@state/models/UploadExtensions';
import {cn} from '@utils/preact-utils';
import {observer} from 'mobx-react';
import {FunctionalComponent, h} from 'preact';
Expand Down Expand Up @@ -30,7 +31,7 @@ export const Notifications: FunctionalComponent = observer(() => {
const request = Notification.requestPermission(resolve);

if (request instanceof Promise) {
request.then(resolve);
void request.then(resolve);
}

break;
Expand Down
2 changes: 1 addition & 1 deletion src/state/models/Upload.ts
Expand Up @@ -154,7 +154,7 @@ export class Upload implements UploadLike<UploadState> {
// Fire notification if set
if (settings.notifications.turnedOn === true &&
settings.notifications.onUploadStateChange.includes(status)) {
UploadExtensions.notifyFor(this);
void UploadExtensions.notifyFor(this);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/state/stores/Notify.ts
Expand Up @@ -14,7 +14,7 @@ export type ResolveNotification = 'click' | 'close' | string | null;
const pendingRequests = new Map<string, (s: ResolveNotification) => void>();

// Wait until service worker is initialized
navigator.serviceWorker.ready.then(() => {
void navigator.serviceWorker.ready.then(() => {

// Listen to resolved notifications
navigator.serviceWorker.addEventListener('message', ev => {
Expand Down
2 changes: 1 addition & 1 deletion src/state/stores/Socket.ts
Expand Up @@ -257,7 +257,7 @@ class Socket {
`It's currently set to ${prettyBytes(payload.limit)} and you've exceeded that limit, pending downloads have been cancelled. ` +
`Wait ${prettyRemainingTime(payload.remainingTime)} until you can upload something again.`;

DialogBox.instance.open({
void DialogBox.instance.open({
icon: 'low-connection',
title: 'You\'ve been rate limited!',
description,
Expand Down
2 changes: 1 addition & 1 deletion src/state/stores/Uploads.ts
Expand Up @@ -12,7 +12,7 @@ class Uploads extends Selectable<UploadLike> {
@observable public readonly listedUploads: Array<UploadLike> = [];

public getAvailableMassActions(uploads: Array<UploadLike>): Map<MassAction, number> {
const massActionsMap = new Map();
const massActionsMap = new Map<MassAction, number>();
const calcMassActions = (name: MassAction, predicate: (v: UploadLike) => boolean): void => {
const amount = uploads.filter(predicate).length;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/clone.ts
@@ -1 +1 @@
export const clone = <T>(data: T): T => JSON.parse(JSON.stringify(data));
export const clone = <T>(data: T): T => JSON.parse(JSON.stringify(data)) as T;
4 changes: 2 additions & 2 deletions src/utils/event-path.ts
Expand Up @@ -5,8 +5,8 @@
*/

/* eslint-disable @typescript-eslint/no-explicit-any */
export function eventPath(evt: any): Array<HTMLElement> {
let path = evt.path || (evt.composedPath && evt.composedPath());
export function eventPath(evt: any): Array<EventTarget> {
let path: Array<EventTarget> = evt.path || (evt.composedPath && evt.composedPath());
if (path) {
return path;
}
Expand Down
26 changes: 15 additions & 11 deletions src/utils/events.ts
@@ -1,23 +1,22 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-explicit-any */
type Method = 'addEventListener' | 'removeEventListener';

export type EventContainer = {
on(args: EventBindingArgs): void;
onMany(args: Array<EventBindingArgs>): void;
clear(): void;
};
type AnyFunction = (...arg: any) => any;

export type EventBindingArgs = [
EventTarget | Array<EventTarget>,
string | Array<string>,
Function,
object?
AnyFunction,
Record<string, unknown>?
];

interface EventBinding {
(
elements: EventTarget | Array<EventTarget>,
events: string | Array<string>,
fn: Function, options?: object
fn: AnyFunction,
options?: Record<string, unknown>
): EventBindingArgs;
}

Expand All @@ -26,7 +25,7 @@ function eventListener(method: Method): EventBinding {
return (
items: EventTarget | Array<EventTarget>,
events: string | Array<string>,
fn: Function, options = {}
fn: AnyFunction, options = {}
): EventBindingArgs => {

// Normalize array
Expand Down Expand Up @@ -101,7 +100,12 @@ export const createNativeEventContainer = () => {
* Simplifies a touch / mouse-event
* @param evt
*/
export const simplifyEvent = (evt: TouchEvent) => {
export const simplifyEvent = (evt: TouchEvent): {
tap: MouseEvent | Touch;
x: number;
y: number;
target: EventTarget;
} => {
const tap = (evt.touches && evt.touches[0] || evt);
return {
tap,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/fuzzy-string-similarity.ts
Expand Up @@ -6,7 +6,7 @@
export const fuzzyStringSimilarity = (
a: string,
b: string
) => {
): number => {
const [min, max] = a.length < b.length ? [a, b] : [b, a];
const minLength = min.length;
const maxLength = max.length;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/local-storage-utils.ts
Expand Up @@ -7,7 +7,7 @@ export const localStorageUtils = {
}

try {
return JSON.parse(data);
return JSON.parse(data) as T;
} catch (e) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/pick.ts
@@ -1,4 +1,4 @@
export const pick = <T extends object, P extends Partial<Array<keyof T>>>(source: T, props: P): Partial<T> => {
export const pick = <T extends Record<string | number | symbol, unknown>, P extends Partial<Array<keyof T>>>(source: T, props: P): Partial<T> => {
const target: Partial<T> = {};

for (const key in source) {
Expand Down
9 changes: 6 additions & 3 deletions src/utils/preact-singleton.tsx
@@ -1,4 +1,5 @@
import {Component, ComponentConstructor, createRef, h} from 'preact';
import {Ref} from 'preact/hooks';
import {JSXInternal} from 'preact/src/jsx';

export type SingletonComponent<T> = {
Expand All @@ -11,7 +12,9 @@ export type SingletonComponent<T> = {
* Does not work as decorator, see https://github.com/Microsoft/TypeScript/issues/4881
* @param target
*/
export function singleton<T extends Function>(
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-return */
export function singleton<T extends {prototype: Record<string, any>}>(
target: T
): SingletonComponent<T['prototype']> {
const ref = createRef();
Expand All @@ -20,8 +23,8 @@ export function singleton<T extends Function>(
const Component = target as unknown as ComponentConstructor;

Object.defineProperty(target, 'instance', {
get: () => ref.current,
set: () => {
get: (): Ref<HTMLElement> => ref.current,
set: (): void => {
throw new Error('instance is a readonly property');
}
});
Expand Down
1 change: 1 addition & 0 deletions src/utils/preact-utils.ts
Expand Up @@ -35,6 +35,7 @@ export function cn(...values: Array<string | {[key: string]: boolean}>): string
*/

/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-return */
export function bind(target: Record<string, any>, propertyKey: string, descriptor: PropertyDescriptor): any {
return {

Expand Down

0 comments on commit ad7906e

Please sign in to comment.