Skip to content

Commit 5c6c82b

Browse files
Merge pull request #26 from alexleboucher/chore/upgrade-packages-20230930
Upgraded packages and improved TS and ESLint config
2 parents 50844bf + c66bcba commit 5c6c82b

File tree

21 files changed

+254
-244
lines changed

21 files changed

+254
-244
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.json

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,66 @@
11
{
2-
"env": {
3-
"browser": true,
4-
"es2021": true
5-
},
6-
"parser": "@typescript-eslint/parser",
7-
"parserOptions": {
8-
"project": ["./tsconfig.json"],
9-
"ecmaVersion": "latest",
10-
"sourceType": "module"
11-
},
12-
"extends": [
13-
"eslint:recommended",
14-
"plugin:import/recommended",
15-
"plugin:import/typescript",
16-
"plugin:@typescript-eslint/recommended",
17-
"plugin:eslint-comments/recommended"
18-
],
19-
"plugins": ["@typescript-eslint"],
20-
"rules": {
21-
"no-console": ["warn", { "allow": ["warn", "error", "info"] }],
22-
"no-duplicate-imports": "error",
23-
"no-multiple-empty-lines": ["error", { "max": 1 }],
24-
"camelcase": "warn",
25-
"object-curly-spacing": ["error", "always"],
26-
"spaced-comment": "warn",
27-
"eslint-comments/no-unused-disable": "error",
28-
"eslint-comments/disable-enable-pair": ["error", {"allowWholeFile": true}],
29-
"@typescript-eslint/await-thenable": "error",
30-
"require-await": "off",
31-
"@typescript-eslint/require-await": "error",
32-
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "req|res|next|err" }],
33-
"@typescript-eslint/no-unnecessary-condition": "warn",
34-
"import/order": [
35-
"error",
36-
{
37-
"groups": [
38-
["builtin", "external"],
39-
["internal", "index", "sibling", "parent", "object", "type"]
40-
],
41-
"newlines-between": "always-and-inside-groups"
42-
}
43-
]
44-
}
2+
"root": true,
3+
"env": { "node": true, "es2020": true },
4+
"parser": "@typescript-eslint/parser",
5+
"parserOptions": {
6+
"project": ["./tsconfig.json"],
7+
"ecmaVersion": "latest",
8+
"sourceType": "module"
9+
},
10+
"extends": [
11+
"eslint:recommended",
12+
"plugin:@typescript-eslint/recommended",
13+
"plugin:eslint-comments/recommended",
14+
"plugin:import/recommended",
15+
"plugin:import/typescript"
16+
],
17+
"plugins": ["@typescript-eslint"],
18+
"ignorePatterns": ["build", "src/migrations", "jest.config.ts"],
19+
"rules": {
20+
"spaced-comment": "warn",
21+
"no-console": ["warn", { "allow": ["warn", "error", "info"] }],
22+
"no-duplicate-imports": "off",
23+
"no-multiple-empty-lines": ["error", { "max": 1 }],
24+
"camelcase": "warn",
25+
"object-curly-spacing": ["error", "always"],
26+
"require-await": "off",
27+
"arrow-body-style": ["error", "as-needed"],
28+
"eqeqeq": "error",
29+
"quotes": ["warn", "single"],
30+
31+
"@typescript-eslint/await-thenable": "error",
32+
"@typescript-eslint/require-await": "error",
33+
"@typescript-eslint/no-unnecessary-condition": "warn",
34+
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "req|res|next|err" }],
35+
"@typescript-eslint/consistent-type-imports": ["error", { "prefer": "type-imports" }],
36+
"@typescript-eslint/no-floating-promises": "error",
37+
"@typescript-eslint/semi": ["warn"],
38+
"@typescript-eslint/member-delimiter-style": ["error", {
39+
"multiline": {
40+
"delimiter": "semi",
41+
"requireLast": true
42+
},
43+
"singleline": {
44+
"delimiter": "semi",
45+
"requireLast": false
46+
}
47+
}],
48+
49+
"eslint-comments/no-unused-disable": "error",
50+
"eslint-comments/disable-enable-pair": ["error", { "allowWholeFile": true }],
51+
52+
"import/default": "off",
53+
"import/no-duplicates": ["error"],
54+
"import/no-named-as-default-member": "off",
55+
"import/order": [
56+
"error",
57+
{
58+
"groups": [
59+
["builtin", "external"],
60+
["internal", "index", "sibling", "parent", "object"]
61+
],
62+
"newlines-between": "always-and-inside-groups"
63+
}
64+
]
65+
}
4566
}

.github/workflows/pull-request.yml

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,8 @@ env:
1414
TEST_DB_NAME: test_db
1515

1616
jobs:
17-
lint:
18-
name: Lint
19-
runs-on: ubuntu-latest
20-
steps:
21-
- name: Checkout repository code
22-
uses: actions/checkout@v3
23-
24-
- name: Setup node version
25-
uses: actions/setup-node@v3
26-
with:
27-
node-version-file: '.node-version'
28-
cache: 'yarn'
29-
30-
- name: Cache node modules
31-
uses: actions/cache@v3
32-
env:
33-
cache-name: cache-node-modules
34-
with:
35-
# npm cache files are stored in `~/.npm` on Linux/macOS
36-
path: ~/.npm
37-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
38-
restore-keys: |
39-
${{ runner.os }}-build-${{ env.cache-name }}-
40-
${{ runner.os }}-build-
41-
${{ runner.os }}-
42-
43-
- name: Install dependencies
44-
run: yarn install --frozen-lockfile
45-
46-
- name: Lint
47-
run: yarn lint
48-
49-
type-check-and-build:
50-
name: Type-check & build
17+
type-check-lint-and-build:
18+
name: Type-check, lint & build
5119
runs-on: ubuntu-latest
5220
steps:
5321
- name: Checkout repository code
@@ -78,6 +46,9 @@ jobs:
7846
- name: Type check
7947
run: yarn type-check
8048

49+
- name: Lint
50+
run: yarn lint
51+
8152
- name: Build app
8253
run: yarn build
8354

__tests__/e2e/api.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import request from 'supertest';
2-
import { Server } from 'http';
2+
import type { Server } from 'http';
33

44
import * as AuthValidators from '../../src/controllers/auth/validators';
55
import { closeDatabase, createTestServer } from '../utils/testsHelpers';
@@ -32,7 +32,7 @@ describe('API', () => {
3232

3333
test('Handle unexpected errors', async () => {
3434
// eslint-disable-next-line @typescript-eslint/no-unused-vars
35-
jest.spyOn(AuthValidators, 'validateLoginBody').mockImplementationOnce((body) => { throw 'User error' });
35+
jest.spyOn(AuthValidators, 'validateLoginBody').mockImplementationOnce(_ => { throw 'User error'; });
3636
const res = await request(server).post('/api/auth/login');
3737

3838
expect(res.statusCode).toEqual(500);

__tests__/e2e/auth.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Server } from 'http';
1+
import type { Server } from 'http';
22
import request from 'supertest';
33

44
import { AppDataSource } from '../../src/data-source';
@@ -15,7 +15,7 @@ beforeAll(async() => {
1515
afterAll(async () => {
1616
await closeDatabase();
1717
server.close();
18-
})
18+
});
1919

2020
describe('Auth routes', () => {
2121
afterEach(async () => {
@@ -100,7 +100,7 @@ describe('Auth routes', () => {
100100
const username = 'fakeUser';
101101
const password = 'fakeUserPwd';
102102
// eslint-disable-next-line @typescript-eslint/no-unused-vars
103-
jest.spyOn(AppDataSource, 'getRepository').mockImplementationOnce((entity) => { throw 'Repo error' });
103+
jest.spyOn(AppDataSource, 'getRepository').mockImplementationOnce(_ => { throw 'Repo error'; });
104104

105105
const res = await request(server).post('/api/auth/login').send({ login: username, password });
106106

@@ -110,7 +110,7 @@ describe('Auth routes', () => {
110110

111111
test('Throw an error if an error occurs during Express login', async () => {
112112
const serverFailingLogIn = await createTestServer(7778, true, {
113-
logIn: (user, cb) => { cb('Error') },
113+
logIn: (_, cb) => { cb('Error'); },
114114
});
115115

116116
const username = 'fakeUser';
@@ -174,7 +174,7 @@ describe('Auth routes', () => {
174174

175175
test('Throw an error if an error occurs during Express logout', async () => {
176176
const serverFailingLogout = await createTestServer(7778, true, {
177-
logout: (cb) => { cb('Error') },
177+
logout: (cb) => { cb('Error'); },
178178
});
179179
const agent = await createAuthenticatedAgent(serverFailingLogout);
180180
const res = await agent.post('/api/auth/logout');

__tests__/e2e/users.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Server } from 'http';
1+
import type { Server } from 'http';
22
import request from 'supertest';
33

44
import { AppDataSource } from '../../src/data-source';
@@ -15,7 +15,7 @@ beforeAll(async() => {
1515
afterAll(async () => {
1616
await closeDatabase();
1717
server.close();
18-
})
18+
});
1919

2020
describe('Users routes', () => {
2121
afterEach(async () => {

__tests__/utils/testsHelpers.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { Server } from "http";
2+
import type { Server } from 'http';
33
import request from 'supertest';
4-
import { Express } from 'express';
4+
import type { Express } from 'express';
55

6-
import createServer from "../../src/config/server";
7-
import { AppDataSource } from "../../src/data-source";
8-
import { createTestUser, TestUserProps } from "./userHelpers";
6+
import createServer from '../../src/config/server';
7+
import { AppDataSource } from '../../src/data-source';
8+
import type { TestUserProps } from './userHelpers';
9+
import { createTestUser } from './userHelpers';
910

1011
interface OverrideExpressOptions {
1112
logout?: (cb: any) => unknown;
@@ -20,7 +21,7 @@ const overrideExpressServer = (server: Express, overrideExpressOptions: Override
2021
server.request.logIn = overrideExpressOptions.logIn;
2122
}
2223
return server;
23-
}
24+
};
2425

2526
/**
2627
* Create a test server.
@@ -40,22 +41,22 @@ export const createTestServer = async (port = 7777, preventDatabaseConnection =
4041
}
4142

4243
return server.listen(port);
43-
}
44+
};
4445

4546
/**
4647
* Close the database connection.
4748
*/
4849
export const closeDatabase = async () => {
4950
await AppDataSource.destroy();
50-
}
51+
};
5152

5253
/**
5354
* Clear the database data.
5455
*/
5556
export const clearDatabase = async () => {
56-
const entities = AppDataSource.entityMetadatas.map((entity) => `"${entity.tableName}"`).join(", ");
57+
const entities = AppDataSource.entityMetadatas.map((entity) => `"${entity.tableName}"`).join(', ');
5758
await AppDataSource.query(`TRUNCATE ${entities} CASCADE;`);
58-
}
59+
};
5960

6061
/**
6162
* Create an authenticated test agent. A test agent allows to maintain session between multiple requests.
@@ -68,4 +69,4 @@ export const createAuthenticatedAgent = async (server: Server, testUser?: TestUs
6869
const user = await createTestUser(testUser);
6970
await agent.post('/api/auth/login').send({ login: user.username, password: testUser?.password || 'password' });
7071
return agent;
71-
}
72+
};

__tests__/utils/userHelpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { AppDataSource } from "../../src/data-source";
2-
import { User } from "../../src/entities/user";
1+
import { AppDataSource } from '../../src/data-source';
2+
import { User } from '../../src/entities/user';
33

44
export interface TestUserProps {
55
username?: string;
@@ -22,4 +22,4 @@ export const createTestUser = async (testUser?: TestUserProps) => {
2222

2323
await userRepo.save(user);
2424
return user;
25-
}
25+
};

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@
2828
"@types/bcryptjs": "^2.4.4",
2929
"@types/connect-pg-simple": "^7.0.1",
3030
"@types/cors": "^2.8.14",
31-
"@types/express": "^4.17.17",
32-
"@types/express-session": "^1.17.7",
31+
"@types/express": "^4.17.18",
32+
"@types/express-session": "^1.17.8",
3333
"@types/http-errors": "^2.0.2",
3434
"@types/jest": "^29.5.5",
35-
"@types/morgan": "^1.9.5",
36-
"@types/node": "^20.6.3",
37-
"@types/passport": "^1.0.12",
38-
"@types/passport-local": "^1.0.35",
39-
"@types/supertest": "^2.0.12",
40-
"@types/validator": "^13.11.1",
41-
"@typescript-eslint/eslint-plugin": "^6.7.2",
42-
"@typescript-eslint/parser": "^6.7.2",
43-
"eslint": "^8.49.0",
44-
"eslint-import-resolver-typescript": "^3.6.0",
35+
"@types/morgan": "^1.9.6",
36+
"@types/node": "^20.8.0",
37+
"@types/passport": "^1.0.13",
38+
"@types/passport-local": "^1.0.36",
39+
"@types/supertest": "^2.0.13",
40+
"@types/validator": "^13.11.2",
41+
"@typescript-eslint/eslint-plugin": "^6.7.3",
42+
"@typescript-eslint/parser": "^6.7.3",
43+
"eslint": "^8.50.0",
44+
"eslint-import-resolver-typescript": "^3.6.1",
4545
"eslint-plugin-eslint-comments": "^3.2.0",
4646
"eslint-plugin-import": "^2.28.1",
4747
"jest": "^29.7.0",
@@ -56,8 +56,8 @@
5656
"dev": "yarn && nodemon -L src/index.ts --watch \"src/**/*.{ts,js}\"",
5757
"build": "tsc -p tsconfig-build.json",
5858
"type-check": "tsc --noEmit",
59-
"lint:fix": "eslint --fix \"src/**/*.{ts,js}\"",
60-
"lint": "eslint \"src/**/*.{ts,js}\"",
59+
"lint:fix": "eslint --fix \"{src,__tests__}/**/*.{ts,js}\"",
60+
"lint": "eslint \"{src,__tests__}/**/*.{ts,js}\"",
6161
"test": "jest --runInBand",
6262
"test:coverage": "jest --runInBand --collectCoverage",
6363
"docker:up": "docker-compose up -d && yarn docker:shell",

src/config/passport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Request } from 'express';
21
import passport from 'passport';
32
import { Strategy as LocalStrategy } from 'passport-local';
3+
import type { Request } from 'express';
44

55
import { AppDataSource } from '../data-source';
66
import { User } from '../entities/user';

0 commit comments

Comments
 (0)