Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eslint rules #644

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"airbnb",
"airbnb-typescript",
"airbnb/hooks",
"plugin:tailwindcss/recommended"
"plugin:tailwindcss/recommended",
"plugin:@typescript-eslint/recommended"
],
"ignorePatterns": [
"/*",
Expand Down Expand Up @@ -45,6 +46,7 @@
"error",
"type"
],
"@typescript-eslint/array-type": "error",
"arrow-parens": [
"error",
"as-needed",
Expand Down
2 changes: 1 addition & 1 deletion src/components/BackgroundImagePlaceholderDiv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cx from 'classnames';
import type { ImageType } from '@/core/types/api/common';

type Props = {
children?: any;
children?: React.ReactNode;
className?: string;
image: ImageType | null;
hidePlaceholderOnHover?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/CharacterImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Icon } from '@mdi/react';
import cx from 'classnames';

type Props = {
children?: any;
children?: React.ReactNode;
className?: string;
imageSrc: string | null;
hidePlaceholderOnHover?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Collection/AnidbDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const AnidbDescription = ({ text }: { text: string }) => {
.replaceAll(RemoveSummaryRegex, '')
.replaceAll(CleanMultiEmptyLinesRegex, '\n');

const lines = [] as Array<React.ReactNode>;
const lines = [] as React.ReactNode[];
let prevPos = 0;
let pos = 0;
let link = LinkRegex.exec(cleanedText);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Collection/CardViewItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { SeriesSizesFileSourcesType } from '@/core/types/api/series';
import type { WebuiGroupExtra } from '@/core/types/api/webui';

const renderFileSources = (sources: SeriesSizesFileSourcesType): string => {
const output: Array<string> = [];
const output: string[] = [];
forEach(sources, (source, type) => {
if (source !== 0) output.push(type);
});
Expand Down
10 changes: 7 additions & 3 deletions src/components/Dialogs/ActionsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import toast from '@/components/Toast';
import TransitionDiv from '@/components/TransitionDiv';
import quickActions from '@/core/quick-actions';
import { useRunActionMutation } from '@/core/rtkQuery/splitV3Api/actionsApi';
import { isErrorWithMessage } from '@/core/util';

const actions = {
import: {
Expand Down Expand Up @@ -89,10 +90,13 @@ const Action = ({ actionKey }: { actionKey: string }) => {
const [runActionTrigger] = useRunActionMutation();

const runAction = async (name: string, action) => {
// TODO: figure out better type for this
const result: any = await runActionTrigger(action);
if (!result.error) {
try {
await runActionTrigger(action);
toast.success(`Running action "${name}"`);
} catch (err) {
if (isErrorWithMessage(err)) {
console.error(err.message);
}
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/components/Dialogs/FiltersModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type Props = {
function FiltersModal({ onClose, show }: Props) {
const [trigger, filtersResult] = useLazyGetTopFiltersQuery({});
const [triggerSubFilter, subFiltersResult] = useLazyGetFiltersQuery({});
const filters: Array<CollectionFilterType> = filtersResult?.data?.List ?? [] as Array<CollectionFilterType>;
const subFilters: Array<CollectionFilterType> = useMemo(
() => subFiltersResult?.data?.List ?? [] as Array<CollectionFilterType>,
const filters: CollectionFilterType[] = filtersResult?.data?.List ?? [] as CollectionFilterType[];
const subFilters: CollectionFilterType[] = useMemo(
() => subFiltersResult?.data?.List ?? [] as CollectionFilterType[],
[subFiltersResult],
);

Expand Down
30 changes: 20 additions & 10 deletions src/components/Dialogs/ImportFolderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '@/core/rtkQuery/splitV3Api/importFolderApi';
import { setStatus as setBrowseStatus } from '@/core/slices/modals/browseFolder';
import { setStatus } from '@/core/slices/modals/importFolder';
import { isErrorWithMessage } from '@/core/util';

import BrowseFolderModal from './BrowseFolderModal';

Expand Down Expand Up @@ -53,7 +54,7 @@ function ImportFolderModal() {
}
};

const handleInputChange = (event: any) => {
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const name = event.target.id;
const value = name === 'WatchForNewFiles' ? event.target.value === '1' : event.target.value;
setImportFolder({ ...importFolder, [name]: value });
Expand All @@ -62,28 +63,37 @@ function ImportFolderModal() {
const handleBrowse = () => dispatch(setBrowseStatus(true));
const handleClose = () => dispatch(setStatus(false));
const handleDelete = async () => {
// TODO: can this be better typed?
const result: any = await deleteFolder({ folderId: ID });
if (!result.error) {
try {
await deleteFolder({ folderId: ID }).unwrap();
toast.success('Import folder deleted!');
dispatch(setStatus(false));
} catch (err) {
if (isErrorWithMessage(err)) {
console.error(err.message);
}
}
};

const handleSave = async () => {
// TODO: can this be better typed?
let result;
if (edit) {
result = await updateFolder(importFolder);
if (!result.error) {
try {
await updateFolder(importFolder);
toast.success('Import folder edited!');
dispatch(setStatus(false));
} catch (err) {
if (isErrorWithMessage(err)) {
console.error(err.message);
}
}
} else {
result = await createFolder(importFolder);
if (!result.error) {
try {
await createFolder(importFolder);
toast.success('Import folder added!');
dispatch(setStatus(false));
} catch (err) {
if (isErrorWithMessage(err)) {
console.error(err.message);
}
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/Dialogs/LanguagesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function LanguagesModal({ onClose, type }: Props) {
);
const [patchSettings] = usePatchSettingsMutation();

const [languages, setLanguages] = useState([] as Array<string>);
const [languages, setLanguages] = useState([] as string[]);

const handleSave = useCallback(() => {
patchSettings({
Expand All @@ -94,7 +94,7 @@ function LanguagesModal({ onClose, type }: Props) {
if (type !== null) setLanguages(LanguagePreference);
}, [type, LanguagePreference]);

const handleInputChange = (event: any) => {
const handleInputChange = (event) => {
const { checked: value, id } = event.target;

const newLanguages = languages.slice();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dialogs/QueueModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const QueueModal = ({ onClose, show: showModal }: Props) => {
}, 500), [getQuery]);

const tabs = useMemo(() =>
map(Object.keys(names) as Array<QueueName>, (key, index, { length }) => (
map(Object.keys(names) as QueueName[], (key, index, { length }) => (
index !== length - 1
? (
<React.Fragment key={key}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DnDList/DnDList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PortalAwareItem from './PortalAwareItem';

type Props = {
onDragEnd: (result: DropResult) => void;
children: Array<{ key: string, item: React.ReactNode }>;
children: { key: string, item: React.ReactNode }[];
};

function DnDList(props: Props) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Input/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import cx from 'classnames';
type Props = {
buttonType?: string;
className?: string;
children: any;
children: React.ReactNode;
disabled?: boolean;
loading?: boolean;
loadingSize?: number;
onClick?: (...args: any) => void;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
submit?: boolean;
tooltip?: string;
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Input/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Props = {
className?: string;
labelRight?: boolean;
justify?: boolean;
onChange: (event: any) => void;
onChange: React.ChangeEventHandler<HTMLInputElement>;
};

function Checkbox({ className, id, intermediate, isChecked, justify, label, labelRight, onChange }: Props) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ type Props = {
type: string;
placeholder?: string;
value: string | number;
onChange: (event: any) => void;
onKeyUp?: (event: any) => void;
onChange: React.ChangeEventHandler<HTMLInputElement>;
onKeyUp?: React.KeyboardEventHandler<HTMLInputElement>;
className?: string;
inputClassName?: string;
autoFocus?: boolean;
disabled?: boolean;
center?: boolean;
endIcon?: string;
endIconClick?: (event: any) => void;
endIconClick?: React.MouseEventHandler<HTMLDivElement>;
startIcon?: string;
inline?: boolean;
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/Input/InputSmall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ type Props = {
type: string;
placeholder?: string;
value: string | number;
onChange: (event: any) => void;
onKeyUp?: (event: any) => void;
onChange: React.ChangeEventHandler<HTMLInputElement>;
onKeyUp?: React.KeyboardEventHandler<HTMLInputElement>;
className?: string;
autoFocus?: boolean;
disabled?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Input/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Icon } from '@mdi/react';
type Props = {
id: string;
value: string | number;
onChange: (event: any) => void;
onChange: React.ChangeEventHandler<HTMLSelectElement>;
className?: string;
children: any;
children: React.ReactNode;
label?: string;
};

Expand Down
6 changes: 3 additions & 3 deletions src/components/Input/SelectEpisodeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Option = {
};

type Props = {
options: Array<Option>;
options: Option[];
value: number;
onChange: (optionValue: number, label: string) => void;
className?: string;
Expand Down Expand Up @@ -98,8 +98,8 @@ const SelectEpisodeList = (
) => {
const [epFilter, setEpFilter] = useState(0);
const [selected, setSelected] = useState(options[0]);
const [portalEl, setPortalEl] = useState(null as any);
const [displayNode, setDisplayNode] = React.useState(null as any);
const [portalEl, setPortalEl] = useState<HTMLDivElement | null>(null);
const [displayNode, setDisplayNode] = React.useState<HTMLDivElement | null>(null);
const displayRef = useRef(null);
const buttonRef = useRef(null);

Expand Down
4 changes: 2 additions & 2 deletions src/components/Input/SelectSmall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Icon } from '@mdi/react';
type Props = {
id: string;
value: string | number;
onChange: (event: any) => void;
onChange: React.ChangeEventHandler<HTMLSelectElement>;
className?: string;
children: any;
children: React.ReactNode;
label?: string;
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/Layout/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type MenuItemProps = {
icon: IconType;
label: string;
className?: string;
onClick: (event: any) => void;
onClick: React.MouseEventHandler<HTMLDivElement>;
};

function MenuItem(props: MenuItemProps) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Panels/ModalPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Modal from 'react-modal';
import cx from 'classnames';

type Props = {
children: any;
children: React.ReactNode;
show: boolean;
title: React.ReactNode;
size?: 'sm' | 'md' | 'lg';
Expand Down
4 changes: 2 additions & 2 deletions src/components/Panels/ShokoPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import cx from 'classnames';

type Props = {
title: ReactNode;
children: any;
options?: any;
children: React.ReactNode;
options?: React.ReactNode;
className?: string;
isFetching?: boolean;
editMode?: boolean;
Expand Down
3 changes: 2 additions & 1 deletion src/components/Settings/AvatarEditorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const AvatarEditorModal = (props: Props) => {
}, [show]);

const handleSave = () => {
const canvas: HTMLCanvasElement = imageEditor.current?.getImage();
if (!imageEditor.current) return;
const canvas: HTMLCanvasElement = imageEditor.current.getImage();

if (canvas.width > 512) {
const resizedCanvas = document.createElement('canvas');
Expand Down
2 changes: 1 addition & 1 deletion src/components/TransitionDiv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Transition } from '@headlessui/react';

type Props = {
children: any;
children: React.ReactNode;
className?: string;
enter?: string;
enterFrom?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/TreeView/TreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function TreeNode(props: Props) {
event.stopPropagation();
};

const children: Array<React.ReactNode> = [];
const children: React.ReactNode[] = [];
const data = nodeId === 0 ? drives.data! : folders.data!;
if (expanded) {
forEach(data, (node: DriveType | FolderType) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function ManuallyLinkedFilesRow(props: Props) {
id={`checkbox-${seriesId}-all`}
isChecked={table.getIsAllRowsSelected()}
onChange={() => {
const selectedIds: Array<number> = [];
const selectedIds: number[] = [];
table.getRowModel().flatRows.reduce((result, row) => {
result.push(row.original.ID);
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Utilities/Unrecognized/MenuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Button from '@/components/Input/Button';

const MenuButton = (
{ disabled, highlight = false, icon, name, onClick }: {
onClick: (...args: any) => void;
onClick: React.MouseEventHandler<HTMLButtonElement>;
icon: string;
name: string;
highlight?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Utilities/UtilitiesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function UtilitiesTable(props: Props) {
const lrIndex = lastRowSelected?.current?.index ?? row.index;
const fromIndex = Math.min(lrIndex, row.index);
const toIndex = Math.max(lrIndex, row.index);
const rowSelection: any = {};
const rowSelection = {};
for (let i = fromIndex; i <= toIndex; i += 1) {
rowSelection[i] = lastRowSelected.current?.getIsSelected() ?? true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ export const loadState = (): RootState => {
const serializedState = JSON.parse(globalThis.sessionStorage.getItem('state') ?? '{}');
const apiSessionString = globalThis.localStorage.getItem('apiSession');
if (apiSessionString === null) {
return checkVersion(get(serializedState, 'apiSession.version', '')) ? serializedState : {} as any;
return checkVersion(get(serializedState, 'apiSession.version', '')) ? serializedState : {} as RootState;
}
const apiSession = JSON.parse(apiSessionString);
if (!checkVersion(get(apiSession, 'version', ''))) {
globalThis.localStorage.clear();
return {} as any;
return {} as RootState;
}
return { ...serializedState, apiSession };
} catch (err) {
return ({} as any);
return ({} as RootState);
}
};

Expand Down
Loading