eslint cleanup

This commit is contained in:
Dane Everitt 2020-07-04 18:30:50 -07:00
parent 922383e232
commit c419d15907
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
37 changed files with 42 additions and 47 deletions

View file

@ -115,6 +115,7 @@
}, },
"scripts": { "scripts": {
"clean": "rm -rf public/assets/*.{js,css,map}", "clean": "rm -rf public/assets/*.{js,css,map}",
"lint": "eslint ./resources/scripts/**/*.{ts,tsx} --ext .ts,.tsx",
"watch": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --watch --progress", "watch": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --watch --progress",
"build": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --progress", "build": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --progress",
"build:production": "yarn run clean && cross-env NODE_ENV=production ./node_modules/.bin/webpack --mode production", "build:production": "yarn run clean && cross-env NODE_ENV=production ./node_modules/.bin/webpack --mode production",

View file

@ -49,7 +49,7 @@ rules:
"@typescript-eslint/no-explicit-any": 0 "@typescript-eslint/no-explicit-any": 0
"@typescript-eslint/no-non-null-assertion": 0 "@typescript-eslint/no-non-null-assertion": 0
"@typescript-eslint/ban-ts-comment": 0 "@typescript-eslint/ban-ts-comment": 0
# @todo this would be nice to have, but don't want to deal with the warning spam at the moment. # This would be nice to have, but don't want to deal with the warning spam at the moment.
"@typescript-eslint/explicit-module-boundary-types": 0 "@typescript-eslint/explicit-module-boundary-types": 0
no-restricted-imports: no-restricted-imports:
- error - error
@ -58,6 +58,8 @@ rules:
message: Please import from styled-components/macro. message: Please import from styled-components/macro.
patterns: patterns:
- "!styled-components/macro" - "!styled-components/macro"
# Not sure, this rule just doesn't work right and is protected by our use of Typescript anyways
# so I'm just not going to worry about it.
"react/prop-types": 0 "react/prop-types": 0
"react/display-name": 0 "react/display-name": 0
"react/jsx-indent-props": "react/jsx-indent-props":

View file

@ -3,13 +3,13 @@ import { ApiKey, rawDataToApiKey } from '@/api/account/getApiKeys';
export default (description: string, allowedIps: string): Promise<ApiKey & { secretToken: string }> => { export default (description: string, allowedIps: string): Promise<ApiKey & { secretToken: string }> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
http.post(`/api/client/account/api-keys`, { http.post('/api/client/account/api-keys', {
description, description,
// eslint-disable-next-line @typescript-eslint/camelcase
allowed_ips: allowedIps.length > 0 ? allowedIps.split('\n') : [], allowed_ips: allowedIps.length > 0 ? allowedIps.split('\n') : [],
}) })
.then(({ data }) => resolve({ .then(({ data }) => resolve({
...rawDataToApiKey(data.attributes), ...rawDataToApiKey(data.attributes),
// eslint-disable-next-line camelcase
secretToken: data.meta?.secret_token ?? '', secretToken: data.meta?.secret_token ?? '',
})) }))
.catch(reject); .catch(reject);

View file

@ -9,10 +9,8 @@ interface Data {
export default ({ current, password, confirmPassword }: Data): Promise<void> => { export default ({ current, password, confirmPassword }: Data): Promise<void> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
http.put('/api/client/account/password', { http.put('/api/client/account/password', {
// eslint-disable-next-line @typescript-eslint/camelcase
current_password: current, current_password: current,
password: password, password: password,
// eslint-disable-next-line @typescript-eslint/camelcase
password_confirmation: confirmPassword, password_confirmation: confirmPassword,
}) })
.then(() => resolve()) .then(() => resolve())

View file

@ -4,11 +4,9 @@ import { LoginResponse } from '@/api/auth/login';
export default (token: string, code: string, recoveryToken?: string): Promise<LoginResponse> => { export default (token: string, code: string, recoveryToken?: string): Promise<LoginResponse> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
http.post('/auth/login/checkpoint', { http.post('/auth/login/checkpoint', {
/* eslint-disable @typescript-eslint/camelcase */
confirmation_token: token, confirmation_token: token,
authentication_code: code, authentication_code: code,
recovery_token: (recoveryToken && recoveryToken.length > 0) ? recoveryToken : undefined, recovery_token: (recoveryToken && recoveryToken.length > 0) ? recoveryToken : undefined,
/* eslint-enable @typescript-eslint/camelcase */
}) })
.then(response => resolve({ .then(response => resolve({
complete: response.data.data.complete, complete: response.data.data.complete,

View file

@ -17,7 +17,6 @@ export default (email: string, data: Data): Promise<PasswordResetResponse> => {
email, email,
token: data.token, token: data.token,
password: data.password, password: data.password,
// eslint-disable-next-line @typescript-eslint/camelcase
password_confirmation: data.passwordConfirmation, password_confirmation: data.passwordConfirmation,
}) })
.then(response => resolve({ .then(response => resolve({

View file

@ -3,10 +3,9 @@ import http, { getPaginationSet, PaginatedResult } from '@/api/http';
export default (query?: string, includeAdmin?: boolean): Promise<PaginatedResult<Server>> => { export default (query?: string, includeAdmin?: boolean): Promise<PaginatedResult<Server>> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
http.get(`/api/client`, { http.get('/api/client', {
params: { params: {
include: [ 'allocation' ], include: [ 'allocation' ],
// eslint-disable-next-line @typescript-eslint/camelcase
filter: includeAdmin ? 'all' : undefined, filter: includeAdmin ? 'all' : undefined,
query, query,
}, },

View file

@ -3,7 +3,7 @@ import http from '@/api/http';
export default (): Promise<PanelPermissions> => { export default (): Promise<PanelPermissions> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
http.get(`/api/client/permissions`) http.get('/api/client/permissions')
.then(({ data }) => resolve(data.attributes.permissions)) .then(({ data }) => resolve(data.attributes.permissions))
.catch(reject); .catch(reject);
}); });

View file

@ -5,7 +5,7 @@ const http: AxiosInstance = axios.create({
timeout: 20000, timeout: 20000,
headers: { headers: {
'X-Requested-With': 'XMLHttpRequest', 'X-Requested-With': 'XMLHttpRequest',
'Accept': 'application/json', Accept: 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-CSRF-Token': (window as any).X_CSRF_TOKEN as string || '', 'X-CSRF-Token': (window as any).X_CSRF_TOKEN as string || '',
}, },

View file

@ -8,9 +8,7 @@ interface Data {
export default (uuid: string, { renameFrom, renameTo }: Data): Promise<void> => { export default (uuid: string, { renameFrom, renameTo }: Data): Promise<void> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
http.put(`/api/client/servers/${uuid}/files/rename`, { http.put(`/api/client/servers/${uuid}/files/rename`, {
// eslint-disable-next-line @typescript-eslint/camelcase
rename_from: renameFrom, rename_from: renameFrom,
// eslint-disable-next-line @typescript-eslint/camelcase
rename_to: renameTo, rename_to: renameTo,
}) })
.then(() => resolve()) .then(() => resolve())

View file

@ -62,7 +62,8 @@ export default (uuid: string): Promise<[ Server, string[] ]> => {
http.get(`/api/client/servers/${uuid}`) http.get(`/api/client/servers/${uuid}`)
.then(({ data }) => resolve([ .then(({ data }) => resolve([
rawDataToServerObject(data.attributes), rawDataToServerObject(data.attributes),
data.meta?.is_server_owner ? ['*'] : (data.meta?.user_permissions || []), // eslint-disable-next-line camelcase
data.meta?.is_server_owner ? [ '*' ] : (data.meta?.user_permissions || []),
])) ]))
.catch(reject); .catch(reject);
}); });

View file

@ -18,7 +18,7 @@ export const rawDataToServerDatabase = (data: any): ServerDatabase => ({
password: data.relationships && data.relationships.password ? data.relationships.password.attributes.password : undefined, password: data.relationships && data.relationships.password ? data.relationships.password.attributes.password : undefined,
}); });
export default (uuid: string, includePassword: boolean = true): Promise<ServerDatabase[]> => { export default (uuid: string, includePassword = true): Promise<ServerDatabase[]> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
http.get(`/api/client/servers/${uuid}/databases`, { http.get(`/api/client/servers/${uuid}/databases`, {
params: includePassword ? { include: 'password' } : undefined, params: includePassword ? { include: 'password' } : undefined,

View file

@ -6,4 +6,4 @@ export default (uuid: string): Promise<void> => {
.then(() => resolve()) .then(() => resolve())
.catch(reject); .catch(reject);
}); });
} };

View file

@ -11,7 +11,6 @@ export default (uuid: string, schedule: number, task: number | undefined, { time
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
http.post(`/api/client/servers/${uuid}/schedules/${schedule}/tasks${task ? `/${task}` : ''}`, { http.post(`/api/client/servers/${uuid}/schedules/${schedule}/tasks${task ? `/${task}` : ''}`, {
...data, ...data,
// eslint-disable-next-line @typescript-eslint/camelcase
time_offset: timeOffset, time_offset: timeOffset,
}) })
.then(({ data }) => resolve(rawDataToServerTask(data.attributes))) .then(({ data }) => resolve(rawDataToServerTask(data.attributes)))

View file

@ -5,5 +5,5 @@ export default (uuid: string, scheduleId: number, taskId: number): Promise<void>
http.delete(`/api/client/servers/${uuid}/schedules/${scheduleId}/tasks/${taskId}`) http.delete(`/api/client/servers/${uuid}/schedules/${scheduleId}/tasks/${taskId}`)
.then(() => resolve()) .then(() => resolve())
.catch(reject); .catch(reject);
}) });
}; };

View file

@ -5,7 +5,7 @@ export default (uuid: string, schedule: number): Promise<Schedule> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
http.get(`/api/client/servers/${uuid}/schedules/${schedule}`, { http.get(`/api/client/servers/${uuid}/schedules/${schedule}`, {
params: { params: {
include: ['tasks'], include: [ 'tasks' ],
}, },
}) })
.then(({ data }) => resolve(rawDataToServerSchedule(data.attributes))) .then(({ data }) => resolve(rawDataToServerSchedule(data.attributes)))

View file

@ -64,7 +64,7 @@ export default (uuid: string): Promise<Schedule[]> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
http.get(`/api/client/servers/${uuid}/schedules`, { http.get(`/api/client/servers/${uuid}/schedules`, {
params: { params: {
include: ['tasks'], include: [ 'tasks' ],
}, },
}) })
.then(({ data }) => resolve((data.data || []).map((row: any) => rawDataToServerSchedule(row.attributes)))) .then(({ data }) => resolve((data.data || []).map((row: any) => rawDataToServerSchedule(row.attributes))))

View file

@ -15,4 +15,4 @@ export default (uuid: string, params: Params, subuser?: Subuser): Promise<Subuse
.then(data => resolve(rawDataToServerSubuser(data.data))) .then(data => resolve(rawDataToServerSubuser(data.data)))
.catch(reject); .catch(reject);
}); });
} };

View file

@ -17,7 +17,7 @@ interface Values {
recoveryCode: '', recoveryCode: '',
} }
type OwnProps = RouteComponentProps<{}, StaticContext, { token?: string }> type OwnProps = RouteComponentProps<Record<string, unknown>, StaticContext, { token?: string }>
type Props = OwnProps & { type Props = OwnProps & {
addError: ActionCreator<FlashStore['addError']['payload']>; addError: ActionCreator<FlashStore['addError']['payload']>;

View file

@ -57,7 +57,7 @@ export default ({ match, location }: RouteComponentProps<{ token: string }>) =>
.min(8, 'Your new password should be at least 8 characters in length.'), .min(8, 'Your new password should be at least 8 characters in length.'),
passwordConfirmation: string() passwordConfirmation: string()
.required('Your new password does not match.') .required('Your new password does not match.')
.oneOf([ref('password'), null], 'Your new password does not match.'), .oneOf([ ref('password'), null ], 'Your new password does not match.'),
})} })}
> >
{({ isSubmitting }) => ( {({ isSubmitting }) => (

View file

@ -14,7 +14,7 @@ export default () => {
<div> <div>
{visible && {visible &&
<DisableTwoFactorModal <DisableTwoFactorModal
appear={true} appear
visible={visible} visible={visible}
onDismissed={() => setVisible(false)} onDismissed={() => setVisible(false)}
/> />

View file

@ -62,9 +62,9 @@ export default () => {
<div className={'w-full fixed'} style={{ height: '2px' }}> <div className={'w-full fixed'} style={{ height: '2px' }}>
<CSSTransition <CSSTransition
timeout={250} timeout={250}
appear={true} appear
in={visible} in={visible}
unmountOnExit={true} unmountOnExit
classNames={'fade'} classNames={'fade'}
> >
<BarFill style={{ width: progress === undefined ? '100%' : `${progress}%` }}/> <BarFill style={{ width: progress === undefined ? '100%' : `${progress}%` }}/>

View file

@ -67,7 +67,7 @@ export default () => {
return ( return (
error ? error ?
<CSSTransition timeout={250} in={true} appear={true} classNames={'fade'}> <CSSTransition timeout={250} in appear classNames={'fade'}>
<div css={tw`bg-red-500 py-2`}> <div css={tw`bg-red-500 py-2`}>
<ContentContainer css={tw`flex items-center justify-center`}> <ContentContainer css={tw`flex items-center justify-center`}>
<Spinner size={'small'}/> <Spinner size={'small'}/>

View file

@ -80,7 +80,7 @@ export default ({ backup }: Props) => {
be recovered once deleted. be recovered once deleted.
</ConfirmationModal> </ConfirmationModal>
} }
<SpinnerOverlay visible={loading} fixed={true}/> <SpinnerOverlay visible={loading} fixed/>
<DropdownMenu <DropdownMenu
renderToggle={onClick => ( renderToggle={onClick => (
<button <button

View file

@ -70,7 +70,7 @@ export default () => {
This directory seems to be empty. This directory seems to be empty.
</p> </p>
: :
<CSSTransition classNames={'fade'} timeout={250} appear={true} in={true}> <CSSTransition classNames={'fade'} timeout={250} appear in>
<React.Fragment> <React.Fragment>
<div> <div>
{files.length > 250 ? {files.length > 250 ?

View file

@ -27,7 +27,7 @@ interface State {
schedule?: Schedule; schedule?: Schedule;
} }
export default ({ match, history, location: { state } }: RouteComponentProps<Params, {}, State>) => { export default ({ match, history, location: { state } }: RouteComponentProps<Params, Record<string, unknown>, State>) => {
const { id, uuid } = useServer(); const { id, uuid } = useServer();
const { clearFlashes, addError } = useFlash(); const { clearFlashes, addError } = useFlash();
const [ isLoading, setIsLoading ] = useState(true); const [ isLoading, setIsLoading ] = useState(true);

View file

@ -62,7 +62,7 @@ export default ({ schedule, task }: Props) => {
return ( return (
<div css={tw`flex items-center bg-neutral-700 border border-neutral-600 mb-2 px-6 py-4 rounded`}> <div css={tw`flex items-center bg-neutral-700 border border-neutral-600 mb-2 px-6 py-4 rounded`}>
<SpinnerOverlay visible={isLoading} fixed={true} size={'large'}/> <SpinnerOverlay visible={isLoading} fixed size={'large'}/>
{isEditing && <TaskDetailsModal {isEditing && <TaskDetailsModal
schedule={schedule} schedule={schedule}
task={task} task={task}

View file

@ -31,7 +31,7 @@ export default ({ subuser }: { subuser: Subuser }) => {
addError({ key: 'users', message: httpErrorToHuman(error) }); addError({ key: 'users', message: httpErrorToHuman(error) });
setShowConfirmation(false); setShowConfirmation(false);
}); });
} };
return ( return (
<> <>

View file

@ -17,13 +17,13 @@ i18n
LocalStorageBackend, LocalStorageBackend,
XHR, XHR,
], ],
backendOptions: [{ backendOptions: [ {
prefix: 'pterodactyl_lng__', prefix: 'pterodactyl_lng__',
expirationTime: 7 * 24 * 60 * 60 * 1000, // 7 days, in milliseconds expirationTime: 7 * 24 * 60 * 60 * 1000, // 7 days, in milliseconds
store: window.localStorage, store: window.localStorage,
}, { }, {
loadPath: '/locales/{{lng}}/{{ns}}.json', loadPath: '/locales/{{lng}}/{{ns}}.json',
}], } ],
}, },
}); });

View file

@ -5,7 +5,7 @@ export default (eventName: string, handler: any, element: any = window) => {
useEffect(() => { useEffect(() => {
savedHandler.current = handler; savedHandler.current = handler;
}, [handler]); }, [ handler ]);
useEffect( useEffect(
() => { () => {
@ -18,6 +18,6 @@ export default (eventName: string, handler: any, element: any = window) => {
element.removeEventListener(eventName, eventListener); element.removeEventListener(eventName, eventListener);
}; };
}, },
[eventName, element], [ eventName, element ],
); );
}; };

View file

@ -1,7 +1,7 @@
import { Dispatch, SetStateAction, useEffect, useState } from 'react'; import { Dispatch, SetStateAction, useEffect, useState } from 'react';
export function usePersistedState<S = undefined> (key: string, defaultValue: S): [S | undefined, Dispatch<SetStateAction<S | undefined>>] { export function usePersistedState<S = undefined> (key: string, defaultValue: S): [S | undefined, Dispatch<SetStateAction<S | undefined>>] {
const [state, setState] = useState( const [ state, setState ] = useState(
() => { () => {
try { try {
const item = localStorage.getItem(key); const item = localStorage.getItem(key);
@ -16,8 +16,8 @@ export function usePersistedState<S = undefined> (key: string, defaultValue: S):
); );
useEffect(() => { useEffect(() => {
localStorage.setItem(key, JSON.stringify(state)) localStorage.setItem(key, JSON.stringify(state));
}, [key, state]); }, [ key, state ]);
return [ state, setState ]; return [ state, setState ];
} }

View file

@ -7,7 +7,7 @@ const useWebsocketEvent = (event: string, callback: (data: string) => void) => {
useEffect(() => { useEffect(() => {
savedCallback.current = callback; savedCallback.current = callback;
}, [callback]); }, [ callback ]);
return useEffect(() => { return useEffect(() => {
const eventListener = (event: any) => savedCallback.current(event); const eventListener = (event: any) => savedCallback.current(event);

View file

@ -69,7 +69,7 @@ const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>)
<Spinner size={'large'} centered/> <Spinner size={'large'} centered/>
: :
<> <>
<CSSTransition timeout={250} classNames={'fade'} appear={true} in={true}> <CSSTransition timeout={250} classNames={'fade'} appear in>
<SubNavigation> <SubNavigation>
<div> <div>
<NavLink to={`${match.url}`} exact>Console</NavLink> <NavLink to={`${match.url}`} exact>Console</NavLink>
@ -88,7 +88,7 @@ const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>)
<Can action={'backup.*'}> <Can action={'backup.*'}>
<NavLink to={`${match.url}/backups`}>Backups</NavLink> <NavLink to={`${match.url}/backups`}>Backups</NavLink>
</Can> </Can>
<Can action={[ 'settings.*', 'file.sftp' ]} matchAny={true}> <Can action={[ 'settings.*', 'file.sftp' ]} matchAny>
<NavLink to={`${match.url}/settings`}>Settings</NavLink> <NavLink to={`${match.url}/settings`}>Settings</NavLink>
</Can> </Can>
</div> </div>

View file

@ -11,7 +11,7 @@ export interface PanelPermissions {
export interface GloablPermissionsStore { export interface GloablPermissionsStore {
data: PanelPermissions; data: PanelPermissions;
setPermissions: Action<GloablPermissionsStore, PanelPermissions>; setPermissions: Action<GloablPermissionsStore, PanelPermissions>;
getPermissions: Thunk<GloablPermissionsStore, void, {}, any, Promise<void>>; getPermissions: Thunk<GloablPermissionsStore, void, Record<string, unknown>, any, Promise<void>>;
} }
const permissions: GloablPermissionsStore = { const permissions: GloablPermissionsStore = {

View file

@ -6,7 +6,7 @@ import { cleanDirectoryPath } from '@/helpers';
export interface ServerFileStore { export interface ServerFileStore {
directory: string; directory: string;
contents: FileObject[]; contents: FileObject[];
getDirectoryContents: Thunk<ServerFileStore, string, {}, ServerStore, Promise<void>>; getDirectoryContents: Thunk<ServerFileStore, string, Record<string, unknown>, ServerStore, Promise<void>>;
setContents: Action<ServerFileStore, FileObject[]>; setContents: Action<ServerFileStore, FileObject[]>;
pushFile: Action<ServerFileStore, FileObject>; pushFile: Action<ServerFileStore, FileObject>;
removeFile: Action<ServerFileStore, string>; removeFile: Action<ServerFileStore, string>;

View file

@ -14,7 +14,7 @@ interface ServerDataStore {
data?: Server; data?: Server;
permissions: string[]; permissions: string[];
getServer: Thunk<ServerDataStore, string, {}, ServerStore, Promise<void>>; getServer: Thunk<ServerDataStore, string, Record<string, unknown>, ServerStore, Promise<void>>;
setServer: Action<ServerDataStore, Server>; setServer: Action<ServerDataStore, Server>;
setPermissions: Action<ServerDataStore, string[]>; setPermissions: Action<ServerDataStore, string[]>;
} }

View file

@ -16,7 +16,7 @@ export interface UserStore {
data?: UserData; data?: UserData;
setUserData: Action<UserStore, UserData>; setUserData: Action<UserStore, UserData>;
updateUserData: Action<UserStore, Partial<UserData>>; updateUserData: Action<UserStore, Partial<UserData>>;
updateUserEmail: Thunk<UserStore, { email: string; password: string }, any, {}, Promise<void>>; updateUserEmail: Thunk<UserStore, { email: string; password: string }, any, UserStore, Promise<void>>;
} }
const user: UserStore = { const user: UserStore = {