Skip to content

Commit dc84af9

Browse files
committed
Apply new eslint rules; default to prettier for styling
1 parent f22cce8 commit dc84af9

File tree

218 files changed

+3877
-3565
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

218 files changed

+3877
-3565
lines changed

.eslintrc.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const prettier = {
2+
singleQuote: true,
3+
jsxSingleQuote: true,
4+
printWidth: 120,
5+
};
6+
7+
/** @type {import('eslint').Linter.Config} */
8+
module.exports = {
9+
parser: '@typescript-eslint/parser',
10+
parserOptions: {
11+
ecmaVersion: 6,
12+
ecmaFeatures: {
13+
jsx: true,
14+
},
15+
project: './tsconfig.json',
16+
tsconfigRootDir: './',
17+
},
18+
settings: {
19+
react: {
20+
pragma: 'React',
21+
version: 'detect',
22+
},
23+
linkComponents: [
24+
{name: 'Link', linkAttribute: 'to'},
25+
{name: 'NavLink', linkAttribute: 'to'},
26+
],
27+
},
28+
env: {
29+
browser: true,
30+
es6: true,
31+
},
32+
plugins: [
33+
'react',
34+
'react-hooks',
35+
'prettier',
36+
'@typescript-eslint',
37+
],
38+
extends: [
39+
// 'standard',
40+
'eslint:recommended',
41+
'plugin:react/recommended',
42+
'plugin:@typescript-eslint/recommended',
43+
'plugin:jest-dom/recommended',
44+
],
45+
rules: {
46+
eqeqeq: 'error',
47+
'prettier/prettier': ['error', prettier],
48+
// This setup is required to avoid a spam of errors when running eslint about React being
49+
// used before it is defined.
50+
//
51+
// @see https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md#how-to-use
52+
'no-use-before-define': 0,
53+
'@typescript-eslint/no-use-before-define': 'warn',
54+
'@typescript-eslint/no-unused-vars': ['warn', {argsIgnorePattern: '^_', varsIgnorePattern: '^_'}],
55+
'@typescript-eslint/ban-ts-comment': ['error', {'ts-expect-error': 'allow-with-description'}],
56+
}
57+
};

.eslintrc.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ rules:
5353
multiline-ternary: 0
5454
"react-hooks/rules-of-hooks":
5555
- error
56-
"react-hooks/exhaustive-deps": 0
57-
"@typescript-eslint/explicit-function-return-type": 0
5856
"@typescript-eslint/explicit-member-accessibility": 0
5957
"@typescript-eslint/ban-ts-ignore": 0
6058
"@typescript-eslint/no-explicit-any": 0

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,17 @@
9999
"babel-plugin-styled-components": "^2.0.7",
100100
"cross-env": "^7.0.2",
101101
"css-loader": "^5.2.7",
102-
"eslint": "^7.27.0",
103-
"eslint-config-standard": "^16.0.3",
104-
"eslint-plugin-import": "^2.23.3",
102+
"eslint": "^8.18.0",
103+
"eslint-config-prettier": "^8.5.0",
104+
"eslint-config-standard": "^17.0.0",
105+
"eslint-plugin-import": "^2.26.0",
105106
"eslint-plugin-jest-dom": "^4.0.2",
107+
"eslint-plugin-n": "^15.2.3",
106108
"eslint-plugin-node": "^11.1.0",
107-
"eslint-plugin-promise": "^5.1.0",
108-
"eslint-plugin-react": "^7.23.2",
109-
"eslint-plugin-react-hooks": "^4.2.0",
109+
"eslint-plugin-prettier": "^4.0.0",
110+
"eslint-plugin-promise": "^6.0.0",
111+
"eslint-plugin-react": "^7.30.1",
112+
"eslint-plugin-react-hooks": "^4.6.0",
110113
"fork-ts-checker-webpack-plugin": "^6.2.10",
111114
"identity-obj-proxy": "^3.0.0",
112115
"jest": "^28.1.1",
@@ -115,6 +118,7 @@
115118
"postcss-loader": "^4.0.0",
116119
"postcss-nesting": "^10.1.8",
117120
"postcss-preset-env": "^7.7.1",
121+
"prettier": "^2.7.1",
118122
"redux-devtools-extension": "^2.13.8",
119123
"source-map-loader": "^1.1.3",
120124
"style-loader": "^2.0.0",

resources/scripts/TransitionRouter.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import tw from 'twin.macro';
77

88
const StyledSwitchTransition = styled(SwitchTransition)`
99
${tw`relative`};
10-
10+
1111
& section {
1212
${tw`absolute w-full top-0 left-0`};
1313
}
@@ -19,9 +19,7 @@ const TransitionRouter: React.FC = ({ children }) => {
1919
render={({ location }) => (
2020
<StyledSwitchTransition>
2121
<Fade timeout={150} key={location.pathname + location.search} in appear unmountOnExit>
22-
<section>
23-
{children}
24-
</section>
22+
<section>{children}</section>
2523
</Fade>
2624
</StyledSwitchTransition>
2725
)}

resources/scripts/api/account/activity.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,26 @@ import useFilteredObject from '@/plugins/useFilteredObject';
88

99
export type ActivityLogFilters = QueryBuilderParams<'ip' | 'event', 'timestamp'>;
1010

11-
const useActivityLogs = (filters?: ActivityLogFilters, config?: ConfigInterface<PaginatedResult<ActivityLog>, AxiosError>): responseInterface<PaginatedResult<ActivityLog>, AxiosError> => {
12-
const key = useUserSWRContentKey([ 'account', 'activity', JSON.stringify(useFilteredObject(filters || {})) ]);
11+
const useActivityLogs = (
12+
filters?: ActivityLogFilters,
13+
config?: ConfigInterface<PaginatedResult<ActivityLog>, AxiosError>
14+
): responseInterface<PaginatedResult<ActivityLog>, AxiosError> => {
15+
const key = useUserSWRContentKey(['account', 'activity', JSON.stringify(useFilteredObject(filters || {}))]);
1316

14-
return useSWR<PaginatedResult<ActivityLog>>(key, async () => {
15-
const { data } = await http.get('/api/client/account/activity', {
16-
params: {
17-
...withQueryBuilderParams(filters),
18-
include: [ 'actor' ],
19-
},
20-
});
17+
return useSWR<PaginatedResult<ActivityLog>>(
18+
key,
19+
async () => {
20+
const { data } = await http.get('/api/client/account/activity', {
21+
params: {
22+
...withQueryBuilderParams(filters),
23+
include: ['actor'],
24+
},
25+
});
2126

22-
return toPaginatedSet(data, Transformers.toActivityLog);
23-
}, { revalidateOnMount: false, ...(config || {}) });
27+
return toPaginatedSet(data, Transformers.toActivityLog);
28+
},
29+
{ revalidateOnMount: false, ...(config || {}) }
30+
);
2431
};
2532

2633
export { useActivityLogs };

resources/scripts/api/account/createApiKey.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ export default (description: string, allowedIps: string): Promise<ApiKey & { sec
77
description,
88
allowed_ips: allowedIps.length > 0 ? allowedIps.split('\n') : [],
99
})
10-
.then(({ data }) => resolve({
11-
...rawDataToApiKey(data.attributes),
12-
// eslint-disable-next-line camelcase
13-
secretToken: data.meta?.secret_token ?? '',
14-
}))
10+
.then(({ data }) =>
11+
resolve({
12+
...rawDataToApiKey(data.attributes),
13+
// eslint-disable-next-line camelcase
14+
secretToken: data.meta?.secret_token ?? '',
15+
})
16+
)
1517
.catch(reject);
1618
});
1719
};

resources/scripts/api/account/ssh-keys.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ import { SSHKey, Transformers } from '@definitions/user';
55
import { AxiosError } from 'axios';
66

77
const useSSHKeys = (config?: ConfigInterface<SSHKey[], AxiosError>) => {
8-
const key = useUserSWRContentKey([ 'account', 'ssh-keys' ]);
8+
const key = useUserSWRContentKey(['account', 'ssh-keys']);
99

10-
return useSWR(key, async () => {
11-
const { data } = await http.get('/api/client/account/ssh-keys');
10+
return useSWR(
11+
key,
12+
async () => {
13+
const { data } = await http.get('/api/client/account/ssh-keys');
1214

13-
return (data as FractalResponseList).data.map((datum: any) => {
14-
return Transformers.toSSHKey(datum.attributes);
15-
});
16-
}, { revalidateOnMount: false, ...(config || {}) });
15+
return (data as FractalResponseList).data.map((datum: any) => {
16+
return Transformers.toSSHKey(datum.attributes);
17+
});
18+
},
19+
{ revalidateOnMount: false, ...(config || {}) }
20+
);
1721
};
1822

1923
const createSSHKey = async (name: string, publicKey: string): Promise<SSHKey> => {

resources/scripts/api/auth/login.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ export interface LoginData {
1515
export default ({ username, password, recaptchaData }: LoginData): Promise<LoginResponse> => {
1616
return new Promise((resolve, reject) => {
1717
http.get('/sanctum/csrf-cookie')
18-
.then(() => http.post('/auth/login', {
19-
user: username,
20-
password,
21-
'g-recaptcha-response': recaptchaData,
22-
}))
23-
.then(response => {
18+
.then(() =>
19+
http.post('/auth/login', {
20+
user: username,
21+
password,
22+
'g-recaptcha-response': recaptchaData,
23+
})
24+
)
25+
.then((response) => {
2426
if (!(response.data instanceof Object)) {
2527
return reject(new Error('An error occurred while processing the login request.'));
2628
}

resources/scripts/api/auth/loginCheckpoint.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ export default (token: string, code: string, recoveryToken?: string): Promise<Lo
66
http.post('/auth/login/checkpoint', {
77
confirmation_token: token,
88
authentication_code: code,
9-
recovery_token: (recoveryToken && recoveryToken.length > 0) ? recoveryToken : undefined,
9+
recovery_token: recoveryToken && recoveryToken.length > 0 ? recoveryToken : undefined,
1010
})
11-
.then(response => resolve({
12-
complete: response.data.data.complete,
13-
intended: response.data.data.intended || undefined,
14-
}))
11+
.then((response) =>
12+
resolve({
13+
complete: response.data.data.complete,
14+
intended: response.data.data.intended || undefined,
15+
})
16+
)
1517
.catch(reject);
1618
});
1719
};

resources/scripts/api/auth/performPasswordReset.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ export default (email: string, data: Data): Promise<PasswordResetResponse> => {
1919
password: data.password,
2020
password_confirmation: data.passwordConfirmation,
2121
})
22-
.then(response => resolve({
23-
redirectTo: response.data.redirect_to,
24-
sendToLogin: response.data.send_to_login,
25-
}))
22+
.then((response) =>
23+
resolve({
24+
redirectTo: response.data.redirect_to,
25+
sendToLogin: response.data.send_to_login,
26+
})
27+
)
2628
.catch(reject);
2729
});
2830
};

0 commit comments

Comments
 (0)