Skip to content

Commit 820cd8f

Browse files
committed
refactor: apply eslint suggestions
1 parent 0b3f0c7 commit 820cd8f

40 files changed

+240
-229
lines changed

client/.eslintrc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,26 @@
1414
},
1515
"plugins": ["react", "@typescript-eslint"],
1616
"rules": {
17-
"react/prop-types": 0,
18-
"quotes": ["error", "single"]
17+
"quotes": ["error", "single"],
18+
"max-len": ["warn", { "code": 150 }],
19+
"import/extensions": "off",
20+
"import/prefer-default-export": "off",
21+
"no-unused-vars": "off",
22+
"@typescript-eslint/no-unused-vars": "error",
23+
"no-shadow": "off",
24+
"@typescript-eslint/no-shadow": ["error"],
25+
"no-restricted-globals": "warn",
26+
"import/no-unresolved": "error"
27+
},
28+
"settings": {
29+
"import/parsers": {
30+
"@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"]
31+
},
32+
"import/resolver": {
33+
"node": {
34+
"extensions": [".ts", ".tsx", ".d.ts"],
35+
"moduleDirectory": ["node_modules"]
36+
}
37+
}
1938
}
2039
}

client/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "1.0.0",
44
"scripts": {
55
"start": "ts-node tools/esbuild.serve.ts",
6-
"build": "npm run check && mkdir -p dist && cp -R public/* dist && ts-node tools/esbuild.build.ts",
7-
"check": "tsc -p tsconfig.json --noEmit"
6+
"build": "npm run lint && npm run check && mkdir -p dist && cp -R public/* dist && ts-node tools/esbuild.build.ts",
7+
"check": "tsc -p tsconfig.json --noEmit",
8+
"lint": "eslint src --ext .ts --ext .tsx"
89
},
910
"engines": {
1011
"node": ">=14",

client/src/api/auth.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-unresolved */
12
import SHA3 from 'crypto-js/sha3';
23

34
import Http from '../utils/http';
@@ -25,8 +26,10 @@ async function fetchActiveUserSessions(accessToken: string): Promise<ActiveUserS
2526
const url = `${serverBaseUrl}/auth/token`;
2627

2728
try {
28-
return await Http.get<ActiveUserSession[]>(url, accessToken);
29-
} catch (e) { /**/ }
29+
return Http.get<ActiveUserSession[]>(url, accessToken);
30+
} catch (e) {
31+
// do nothing
32+
}
3033

3134
return [];
3235
}
@@ -35,8 +38,10 @@ async function fetchAccessToken(): Promise<string | null> {
3538
const url = `${serverBaseUrl}/auth/token/access`;
3639

3740
try {
38-
return await Http.postWithoutBody<string>(url);
39-
} catch (e) { /**/ }
41+
return Http.post<string, string | null>(url);
42+
} catch (e) {
43+
// do nothing
44+
}
4045

4146
return null;
4247
}
@@ -51,7 +56,7 @@ async function login(email: string, password: string): Promise<string | null> {
5156
};
5257

5358
try {
54-
return await Http.post<LoginBody, string>(url, body);
59+
return Http.post<LoginBody, string>(url, body);
5560
} catch (e) {
5661
const i18n = getI18n({
5762
error404: {
@@ -87,7 +92,7 @@ async function logout(): Promise<boolean | null> {
8792
},
8893
});
8994

90-
alert(i18n.text('error'))
95+
alert(i18n.text('error'));
9196
}
9297

9398
return null;
@@ -105,7 +110,7 @@ async function setSignUpToken(name: string, email: string, password: string, ava
105110
};
106111

107112
try {
108-
return await Http.post<SetSignUpTokenBody, string>(url, body);
113+
return Http.post<SetSignUpTokenBody, string>(url, body);
109114
} catch (e) {
110115
const i18n = getI18n({
111116
error: {
@@ -127,7 +132,7 @@ async function setPasswordToken(email: string): Promise<boolean | null> {
127132
};
128133

129134
try {
130-
return await Http.post<SetPasswordTokenBody, boolean>(url, body);
135+
return Http.post<SetPasswordTokenBody, boolean>(url, body);
131136
} catch (e) {
132137
const i18n = getI18n({
133138
error404: {
@@ -150,4 +155,6 @@ async function setPasswordToken(email: string): Promise<boolean | null> {
150155
return null;
151156
}
152157

153-
export { login, logout, setSignUpToken, setPasswordToken, fetchAccessToken, fetchActiveUserSessions };
158+
export {
159+
login, logout, setSignUpToken, setPasswordToken, fetchAccessToken, fetchActiveUserSessions,
160+
};

client/src/api/post.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ async function fetchPosts(publicKey: string, accessToken: string): Promise<Summa
4949

5050
return null;
5151
}).filter((post) => post !== null) as SummarizedPost[];
52-
} else {
53-
return [];
5452
}
53+
return [];
5554
} catch (e) {
5655
return [];
5756
}
@@ -71,18 +70,19 @@ async function fetchPost(id: number, publicKey: string, accessToken: string): Pr
7170
const privateKey = Secret.decryptAES(encryptedPrivateKey, publicKey);
7271

7372
if (privateKey) {
74-
const { id, title, content, date, created_at, updated_at } = post;
73+
const {
74+
title, content, date, created_at: createdAt, updated_at: updatedAt,
75+
} = post;
7576
return {
7677
id,
7778
title: Secret.decryptAES(title, privateKey),
7879
content: Secret.decryptAES(content, privateKey),
7980
date,
80-
created_at,
81-
updated_at,
81+
created_at: createdAt,
82+
updated_at: updatedAt,
8283
};
83-
} else {
84-
return null;
8584
}
85+
return null;
8686
} catch (e) {
8787
return null;
8888
}
@@ -171,7 +171,7 @@ async function deletePost(id: number, accessToken: string): Promise<boolean> {
171171
const url = `${serverBaseUrl}/posts/${id}`;
172172
return await Http.delete<boolean>(url, accessToken);
173173
} catch (e) {
174-
const i18n = getI18n({
174+
const i18n = getI18n({
175175
error: {
176176
ko: '삭제에 실패했습니다',
177177
en: 'Failed to delete',
@@ -184,4 +184,6 @@ async function deletePost(id: number, accessToken: string): Promise<boolean> {
184184
return false;
185185
}
186186

187-
export { fetchPosts, createPost, updatePost, fetchPost, deletePost };
187+
export {
188+
fetchPosts, createPost, updatePost, fetchPost, deletePost,
189+
};

client/src/api/user.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-unresolved */
12
import SHA3 from 'crypto-js/sha3';
23

34
import Http from '../utils/http';
@@ -75,7 +76,7 @@ async function updateUser(userId: string, accessToken: string, password?: string
7576

7677
const body: UpdateUserBody = {
7778
password: password ? SHA3(password, { outputLength: 512 }).toString() : undefined,
78-
name: name,
79+
name,
7980
avatar_url: avatar,
8081
};
8182

@@ -121,4 +122,6 @@ async function resetPassword(email: string, tokenId: string, temporaryPassword:
121122
return null;
122123
}
123124

124-
export { fetchUser, createUser, updateUser, resetPassword };
125+
export {
126+
fetchUser, createUser, updateUser, resetPassword,
127+
};

client/src/components/Button.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {ButtonHTMLAttributes} from 'react';
1+
import React, { ButtonHTMLAttributes } from 'react';
22
import styled from 'styled-components';
33

44
interface Props extends ButtonHTMLAttributes<HTMLButtonElement>{
@@ -9,17 +9,15 @@ const StyledButton = styled.button`
99
font-size: 14px;
1010
border: 1px solid #000000;
1111
padding: 5px 10px;
12-
background-color: ${props => props.disabled ? '#e9e9e9' : '#ffffff'};
13-
color: ${props => props.disabled ? '#808080' : '#000000'};
14-
cursor: ${props => props.disabled ? 'arrow' : 'pointer'};
12+
background-color: ${(props) => (props.disabled ? '#e9e9e9' : '#ffffff')};
13+
color: ${(props) => (props.disabled ? '#808080' : '#000000')};
14+
cursor: ${(props) => (props.disabled ? 'arrow' : 'pointer')};
1515
1616
&:hover {
17-
background-color: ${props => props.disabled ? '#e9e9e9' : '#ffce05'};
17+
background-color: ${(props) => (props.disabled ? '#e9e9e9' : '#ffce05')};
1818
}
1919
`;
2020

21-
const Button: React.FC<Props> = ({ children, disabled, ...props }) => {
22-
return <StyledButton disabled={disabled} {...props}>{children}</StyledButton>
23-
};
21+
const Button: React.FC<Props> = ({ children, disabled, ...props }) => <StyledButton disabled={disabled} {...props}>{children}</StyledButton>;
2422

2523
export default Button;

client/src/components/Checkbox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const Checkbox: React.FC<Props> = ({ text, valueState }) => {
2222
return <label>
2323
<Input type='checkbox' checked={value} onChange={change} />
2424
{text}
25-
</label>
25+
</label>;
2626
};
2727

2828
export default Checkbox;

client/src/components/Container.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import styled from 'styled-components'
1+
import styled from 'styled-components';
22

3-
import { Section, SectionProps } from '../components';
3+
import { Section, SectionProps } from './Section';
44

55
export interface ContainerProps extends SectionProps {
66
fullWidth?: boolean;
@@ -9,12 +9,11 @@ export interface ContainerProps extends SectionProps {
99
export const Container = styled(Section)<ContainerProps>`
1010
display: flex;
1111
width: 100%;
12-
flex: ${props => !props.row && props.fullHeight && 1};
13-
height: ${props => props.fullHeight ? '100%' : 'auto'};
14-
max-width: ${props => props.fullWidth ? 'none' : '800px'};
15-
margin-top: ${props => props.top ? `${props.top}px` : 0};
16-
margin-bottom: ${props => props.bottom ? `${props.bottom}px` : 0};
12+
flex: ${(props) => !props.row && props.fullHeight && 1};
13+
height: ${(props) => (props.fullHeight ? '100%' : 'auto')};
14+
max-width: ${(props) => (props.fullWidth ? 'none' : '800px')};
15+
margin-top: ${(props) => (props.top ? `${props.top}px` : 0)};
16+
margin-bottom: ${(props) => (props.bottom ? `${props.bottom}px` : 0)};
1717
margin-right: auto;
1818
margin-left: auto;
1919
`;
20-

client/src/components/Footer.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ const ListItem = styled.li`
3939
font-size: 12px;
4040
`;
4141

42-
const Footer: React.FC = () => {
43-
return <FooterContainer>
42+
const Footer: React.FC = () => <FooterContainer>
4443
<List>
4544
<ListItem>© 2020 Darim.</ListItem>
4645
<ListItem><StyledLink to='/static/terms'>Terms</StyledLink></ListItem>
4746
<ListItem><StyledLink to='/static/privacy'>Privacy</StyledLink></ListItem>
4847
<ListItem><StyledAnchor href='https://github.com/parksb/darim'>GitHub</StyledAnchor></ListItem>
4948
</List>
50-
</FooterContainer>
51-
};
49+
</FooterContainer>;
5250

5351
export default Footer;

client/src/components/Header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const UserAvatar = styled.div<{ src: string }>`
3737
height: 35px;
3838
background-color: #c0c0c0;
3939
border-radius: 50%;
40-
background-image: url(${props => props.src || ''});
40+
background-image: url(${(props) => props.src || ''});
4141
background-position: center;
4242
background-size: cover;
4343
background-repeat: no-repeat;
@@ -60,7 +60,7 @@ const Header: React.FC<Props> = ({ session }) => {
6060
<UserAvatar src={session?.user?.avatar_url} />
6161
</Link>
6262
)}
63-
</HeaderContainer>
63+
</HeaderContainer>;
6464
};
6565

6666
export default Header;

0 commit comments

Comments
 (0)