Skip to content

Commit 705104e

Browse files
authored
Applied new eslint rules from @dooboo/eslint-config (hyochan#337)
To unify our coding styles with the `client`, I've managed to install [our eslint rule](https://www.npmjs.com/package/@dooboo/eslint-config) as well in `server-side`
1 parent ab30f3b commit 705104e

60 files changed

Lines changed: 1132 additions & 1333 deletions

Some content is hidden

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

‎.circleci/config.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
name: Jest test
4747
working_directory: server
4848
command: |
49-
yarn test --coverage --silent --detectOpenHandles
49+
yarn test --coverage --silent
5050
5151
- codecov/upload:
5252
file: ./server/coverage/lcov.info

‎client/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- [react-native](https://github.com/facebook/react-native)
88
- [react-navigation](https://github.com/react-navigation/react-navigation)
99
- [typescript](https://github.com/Microsoft/TypeScript)
10-
- [localization](https://github.com/stefalda/ReactNativeLocalization)
10+
- [fbt](https://github.com/facebook/fbt)
1111
- [styled-components](https://github.com/styled-components/styled-components)
1212
- [ts-jest](https://github.com/kulshekhar/ts-jest)
1313
- [expo](https://expo.io)
@@ -22,10 +22,10 @@
2222
1. Sample of context-api with `react-hook` (`useContext`).
2323
2. Know how to structure react native app with typescript.
2424
3. Know how to navigate between screens with `react-navigation`.
25-
4. Know how to write `react-native` app with bare work flow from `expo` with `unimodules`.
25+
4. Know how to write `react-native` app with managed flow from `expo` with `unimodules`.
2626
5. Know how to write test code with `@testing-library/react-native`.
2727
6. Know how to `lint` your project with `eslint`.
28-
7. Know how to localize your project.
28+
7. Know how to localize your project with [facebook fbt](https://medium.com/dooboolab/localizing-react-app-with-fbt-instead-of-i18n-90822e0cb373).
2929
```
3030

3131
### INSTALL

‎server/.eslintrc.js‎

Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,8 @@
11
module.exports = {
2-
extends: [
3-
'standard',
4-
'plugin:@typescript-eslint/recommended',
5-
],
6-
parser: '@typescript-eslint/parser',
7-
env: {
8-
browser: true,
9-
jest: true,
10-
},
11-
plugins: ['@typescript-eslint'],
12-
parserOptions: {
13-
ecmaVersion: 2017,
14-
sourceType: 'module',
15-
},
2+
root: true,
3+
extends: '@dooboo/eslint-config',
164
rules: {
17-
'no-unused-vars': 0,
18-
// '@typescript-eslint/no-unused-vars': 'warn',
19-
'@typescript-eslint/ban-ts-comment': 0,
20-
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
21-
'no-console': 'error',
22-
'max-len': ['error', { code: 120 }],
23-
'comma-dangle': ['error', 'always-multiline'],
24-
semi: [2, 'always'],
25-
'arrow-parens': ['error', 'always'],
26-
'no-new-object': 'error',
27-
'no-array-constructor': 'error',
28-
'sort-imports': [
29-
2,
30-
{
31-
ignoreCase: false,
32-
ignoreMemberSort: false,
33-
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
34-
},
35-
],
36-
'space-before-function-paren': [
37-
'error',
38-
{
39-
anonymous: 'never',
40-
named: 'never',
41-
asyncArrow: 'always',
42-
},
43-
],
44-
'padding-line-between-statements': [
45-
'warn',
46-
{ blankLine: 'always', prev: '*', next: 'return' },
47-
// Always require blank lines after directive (like 'use-strict'), except between directives
48-
{ blankLine: 'always', prev: 'directive', next: '*' },
49-
{ blankLine: 'any', prev: 'directive', next: 'directive' },
50-
// Always require blank lines after import, except between imports
51-
{ blankLine: 'always', prev: 'import', next: '*' },
52-
{ blankLine: 'any', prev: 'import', next: 'import' },
53-
// Always require blank lines before and after every sequence of variable declarations and export
54-
{
55-
blankLine: 'always',
56-
prev: '*',
57-
next: ['const', 'let', 'var', 'export'],
58-
},
59-
{
60-
blankLine: 'always',
61-
prev: ['const', 'let', 'var', 'export'],
62-
next: '*',
63-
},
64-
{
65-
blankLine: 'any',
66-
prev: ['const', 'let', 'var', 'export'],
67-
next: ['const', 'let', 'var', 'export'],
68-
},
69-
{
70-
blankLine: 'always',
71-
prev: ['multiline-const', 'multiline-expression', 'multiline-let'],
72-
next: '*',
73-
},
74-
{
75-
blankLine: 'always',
76-
prev: '*',
77-
next: ['multiline-const', 'multiline-expression', 'multiline-let'],
78-
},
79-
// Always require blank lines before and after class declaration, if, do/while, switch, try
80-
{
81-
blankLine: 'always',
82-
prev: '*',
83-
next: ['if', 'class', 'for', 'do', 'while', 'switch', 'try'],
84-
},
85-
{
86-
blankLine: 'always',
87-
prev: ['if', 'class', 'for', 'do', 'while', 'switch', 'try'],
88-
next: '*',
89-
},
90-
],
5+
'eslint-comments/no-unlimited-disable': 0,
6+
'eslint-comments/no-unused-disable': 0,
917
},
928
};

‎server/jest.config.js‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@ module.exports = {
1010
fetch: require('node-fetch'),
1111
},
1212
preset: 'ts-jest',
13-
moduleFileExtensions: [
14-
'ts',
15-
'js',
16-
'json',
17-
],
13+
moduleFileExtensions: ['ts', 'js', 'json'],
1814
transform: {
1915
'^.+\\.(ts|tsx)$': 'ts-jest',
2016
...tsjPreset.transform,
2117
},
22-
testMatch: [
23-
'**/tests/**/*.test.(ts|js)',
24-
],
25-
setupFilesAfterEnv: ['./tests/e2e/testSetup.ts'],
18+
testMatch: ['**/tests/**/*.test.(ts|js)'],
19+
setupFilesAfterEnv: ['./tests/testSetup.ts'],
2620
testEnvironment: 'node',
2721
};

‎server/package.json‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"verify-apple-id-token": "^2.0.1"
5858
},
5959
"devDependencies": {
60+
"@dooboo/eslint-config": "^0.6.5",
6061
"@prisma/cli": "~2.13.1",
6162
"@types/bcrypt": "^3.0.0",
6263
"@types/ejs": "^3.0.5",
@@ -70,8 +71,6 @@
7071
"@types/node-rsa": "^1.0.0",
7172
"@types/ramda": "^0.27.34",
7273
"@types/ws": "7.4.0",
73-
"@typescript-eslint/eslint-plugin": "^4.11.1",
74-
"@typescript-eslint/parser": "^4.11.1",
7574
"apollo-cache-inmemory": "^1.6.6",
7675
"apollo-client": "^2.6.10",
7776
"apollo-datasource-rest": "^0.9.6",
@@ -81,11 +80,6 @@
8180
"dotenv": "^8.2.0",
8281
"dotenv-cli": "^4.0.0",
8382
"eslint": "^7.16.0",
84-
"eslint-config-standard": "^16.0.2",
85-
"eslint-plugin-import": "^2.22.1",
86-
"eslint-plugin-node": "^11.1.0",
87-
"eslint-plugin-promise": "^4.2.1",
88-
"eslint-plugin-standard": "^4.1.0",
8983
"graphql-import": "^1.0.2",
9084
"graphql-request": "^3.4.0",
9185
"graphql-tag": "^2.11.0",
@@ -95,7 +89,7 @@
9589
"ts-jest": "^26.4.4",
9690
"ts-node": "9.1.1",
9791
"ts-node-dev": "^1.1.1",
98-
"typescript": "^4.1.3"
92+
"typescript": "4.0.5"
9993
},
10094
"engines": {
10195
"node": ">=10.0.0"

‎server/src/apis/root.ts‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
encryptCredential,
3-
getToken,
4-
} from '../utils/auth';
1+
import { encryptCredential, getToken } from '../utils/auth';
52
import { resetPassword, verifyEmail } from '../models/User';
63

74
import { MulterAzureStorage } from 'multer-azure-blob-storage';
@@ -62,11 +59,12 @@ const upload = multer({
6259

6360
const router = Router();
6461

65-
const verifyEmailToken = (token: string, appSecretEtc: string)
66-
: VerificationToken =>
67-
verify(token, appSecretEtc) as VerificationToken;
62+
const verifyEmailToken = (
63+
token: string,
64+
appSecretEtc: string,
65+
): VerificationToken => verify(token, appSecretEtc) as VerificationToken;
6866

69-
const onResetPassword = async (req: ReqI18n, res) => {
67+
const onResetPassword = async (req: ReqI18n, res): Promise<void> => {
7068
const token = req.params.token;
7169
const randomPassword = qs.unescape(req.params.password);
7270

@@ -92,7 +90,7 @@ const onResetPassword = async (req: ReqI18n, res) => {
9290
}
9391
};
9492

95-
const onVerifyEmail = async (req: ReqI18n, res) => {
93+
const onVerifyEmail = async (req: ReqI18n, res): Promise<void> => {
9694
const token = req.params.token;
9795

9896
try {
@@ -130,7 +128,7 @@ const onVerifyEmail = async (req: ReqI18n, res) => {
130128
}
131129
};
132130

133-
const onUploadSingle = async (req: ReqI18n, res) => {
131+
const onUploadSingle = async (req: ReqI18n, res): Promise<void> => {
134132
interface Result {
135133
message: string | unknown;
136134
status: number;
@@ -165,7 +163,13 @@ const onUploadSingle = async (req: ReqI18n, res) => {
165163
return res.json(result);
166164
}
167165

168-
const actualURL = getURL('hackatalk', req.file.blobName, req.file.sasToken, true, req.file.snapshotId);
166+
const actualURL = getURL(
167+
'hackatalk',
168+
req.file.blobName,
169+
req.file.sasToken,
170+
true,
171+
req.file.snapshotId,
172+
);
169173

170174
req.file.url = actualURL;
171175

‎server/src/app.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ export const createApp = (): express.Application => {
3636
app.use(express.static(filePath));
3737

3838
app.use((req: ReqI18n, res, next) => {
39-
const {
40-
JWT_SECRET_ETC,
41-
} = process.env;
39+
const { JWT_SECRET_ETC } = process.env;
4240

4341
req.appSecretEtc = JWT_SECRET_ETC;
4442
next();

‎server/src/models/Scalar.ts‎

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-shadow */
12
import { asNexusMethod, scalarType } from 'nexus';
23

34
import { GraphQLDate } from 'graphql-iso-date';
@@ -14,9 +15,7 @@ export const Auth = scalarType({
1415
name: 'Auth',
1516
asNexusMethod: 'auth',
1617
parseValue(value: AuthType): AuthType | undefined {
17-
if (AuthType[value]) {
18-
return value;
19-
}
18+
if (AuthType[value]) return value;
2019
},
2120
serialize(value) {
2221
return value;
@@ -32,9 +31,7 @@ export const gender = scalarType({
3231
name: 'Gender',
3332
asNexusMethod: 'gender',
3433
parseValue(value: Gender): Gender | undefined {
35-
if (Gender[value]) {
36-
return value;
37-
}
34+
if (Gender[value]) return value;
3835
},
3936
serialize(value) {
4037
return value;
@@ -44,16 +41,14 @@ export const gender = scalarType({
4441
export enum MembershipType {
4542
owner = 'owner',
4643
admin = 'admin',
47-
member = 'member'
44+
member = 'member',
4845
}
4946

5047
export const membershipType = scalarType({
5148
name: 'MembershipType',
5249
asNexusMethod: 'membershipType',
5350
parseValue(value: MembershipType): MembershipType | undefined {
54-
if (MembershipType[value]) {
55-
return value;
56-
}
51+
if (MembershipType[value]) return value;
5752
},
5853
serialize(value) {
5954
return value;
@@ -63,16 +58,14 @@ export const membershipType = scalarType({
6358
export enum AlertMode {
6459
sound = 'sound',
6560
vibrate = 'vibrate',
66-
silent = 'silent'
61+
silent = 'silent',
6762
}
6863

6964
export const alertMode = scalarType({
7065
name: 'AlertMode',
7166
asNexusMethod: 'alertMode',
7267
parseValue(value: AlertMode): AlertMode | undefined {
73-
if (AlertMode[value]) {
74-
return value;
75-
}
68+
if (AlertMode[value]) return value;
7669
},
7770
serialize(value) {
7871
return value;
@@ -88,9 +81,7 @@ export const channelType = scalarType({
8881
name: 'ChannelType',
8982
asNexusMethod: 'channelType',
9083
parseValue(value: ChannelType): ChannelType | undefined {
91-
if (ChannelType[value]) {
92-
return value;
93-
}
84+
if (ChannelType[value]) return value;
9485
},
9586
serialize(value) {
9687
return value;
@@ -107,9 +98,7 @@ export const messageType = scalarType({
10798
name: 'MessageType',
10899
asNexusMethod: 'messageType',
109100
parseValue(value: MessageType): MessageType | undefined {
110-
if (MessageType[value]) {
111-
return value;
112-
}
101+
if (MessageType[value]) return value;
113102
},
114103
serialize(value) {
115104
return value;

‎server/src/models/User.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ export const User = objectType({
3434
t.list.field('notifications', { type: 'Notification' });
3535

3636
t.boolean('hasBlocked', {
37-
description: 'Check if the user is blocked by the user who have signed in.',
37+
description:
38+
'Check if the user is blocked by the user who have signed in.',
3839

39-
resolve: async ({ id }, args, { prisma, userId }) => {
40+
resolve: async ({ id }, args, { userId }) => {
4041
assert(userId, 'Not authorized.');
4142

4243
const blockedUser = await prisma.blockedUser.findFirst({
@@ -49,16 +50,19 @@ export const User = objectType({
4950
},
5051
});
5152

52-
export const resetPassword = (email: string, password: string)
53-
: Promise<NexusGenRootTypes['User']> => {
53+
export const resetPassword = (
54+
email: string,
55+
password: string,
56+
): Promise<NexusGenRootTypes['User']> => {
5457
return prisma.user.update({
5558
where: { email },
5659
data: { password },
5760
});
5861
};
5962

60-
export const verifyEmail = (email: string)
61-
: Promise<NexusGenRootTypes['User']> => {
63+
export const verifyEmail = (
64+
email: string,
65+
): Promise<NexusGenRootTypes['User']> => {
6266
return prisma.user.update({
6367
where: { email },
6468
data: {

0 commit comments

Comments
 (0)