diff --git a/api-gateway/eslint.config.mjs b/api-gateway/eslint.config.mjs new file mode 100644 index 0000000..d8e4eb8 --- /dev/null +++ b/api-gateway/eslint.config.mjs @@ -0,0 +1,79 @@ +// SPDX-FileCopyrightText: 2017-2024 City of Espoo +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +import eslint from '@eslint/js' +import tsParser from '@typescript-eslint/parser' +import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended' +import globals from 'globals' +import typescriptEslint from 'typescript-eslint' + +export default [ + { ignores: ['.yarn', 'dist', 'eslint.config.mjs'] }, + eslint.configs.recommended, + ...typescriptEslint.configs.recommended, + ...typescriptEslint.configs.stylisticTypeChecked, + { + languageOptions: { + parser: tsParser, + ecmaVersion: 2018, + sourceType: 'module', + parserOptions: { + projectService: true, + project: './tsconfig.json', + tsconfigRootDir: import.meta.dirname, + globals: globals.node, + ecmaFeatures: { + modules: true + } + } + } + }, + { + files: ['**/*.ts'], + rules: { + '@typescript-eslint/no-unused-vars': [ + 'warn', + { + args: 'all', + argsIgnorePattern: '^_', + caughtErrors: 'all', + caughtErrorsIgnorePattern: '^.*', + destructuredArrayIgnorePattern: '^_', + varsIgnorePattern: '^_', + ignoreRestSiblings: true + } + ] + } + }, + { + files: ['**/*.{ts,js,mjs}'], + rules: { + '@typescript-eslint/consistent-type-definitions': 'off', + '@typescript-eslint/no-empty-object-type': [ + 'error', + { allowInterfaces: 'always' } + ], + '@typescript-eslint/no-misused-promises': [ + 'error', + { checksVoidReturn: false } + ], + '@typescript-eslint/prefer-nullish-coalescing': 'off', + '@typescript-eslint/prefer-optional-chain': 'off', + '@typescript-eslint/prefer-promise-reject-errors': 'off' + } + }, + { + files: ['**/*.{js,mjs}'], + rules: { + '@typescript-eslint/no-var-requires': 'off' + } + }, + { + files: ['**/*.js'], + rules: { + '@typescript-eslint/no-require-imports': 'off' + } + }, + eslintPluginPrettierRecommended +] diff --git a/api-gateway/package.json b/api-gateway/package.json index d4cbde2..8fe9a5a 100644 --- a/api-gateway/package.json +++ b/api-gateway/package.json @@ -7,7 +7,7 @@ "scripts": { "clean": "rm -rf ./build ./dist", "build": "yarn clean && yarn install && tsc --build .", - "lint": "eslint --ext .ts,.tsx --max-warnings 0 .", + "lint": "eslint --max-warnings 0 .", "dev": "tsc --build . && concurrently --prefix '[{name}]' --names 'tsc,nodemon' 'tsc --build --preserveWatchOutput -w .' 'NODE_ENV=local nodemon dist/index.js'" }, "dependencies": { @@ -57,7 +57,8 @@ "nodemon": "^3.1.7", "prettier": "^3.3.3", "ts-node": "^10.9.2", - "typescript": "^5.7.2" + "typescript": "^5.7.2", + "typescript-eslint": "^8.16.0" }, "resolutions": { "@types/mime": "3.0.4" @@ -69,35 +70,6 @@ "singleQuote": true, "trailingComma": "none" }, - "eslintConfig": { - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:@typescript-eslint/stylistic", - "plugin:prettier/recommended" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "module", - "project": "./tsconfig.json", - "ecmaFeatures": { - "modules": true - } - }, - "plugins": [ - "@typescript-eslint" - ], - "rules": { - "@typescript-eslint/no-unused-vars": [ - "warn", - { - "argsIgnorePattern": "^_", - "varsIgnorePattern": "^_" - } - ] - } - }, "engines": { "node": ">= 20.11.0" }, diff --git a/api-gateway/src/auth/saml/index.ts b/api-gateway/src/auth/saml/index.ts index 051ddf7..eef8e5e 100644 --- a/api-gateway/src/auth/saml/index.ts +++ b/api-gateway/src/auth/saml/index.ts @@ -108,7 +108,7 @@ export function createAdSamlStrategy( } } - const loginVerify: VerifyWithRequest = (req, profile, done) => { + const loginVerify: VerifyWithRequest = (_req, profile, done) => { if (!profile) return done(null, undefined) const parseResult = Profile.safeParse(profile) if (!parseResult.success) { diff --git a/api-gateway/src/clients/service-client.ts b/api-gateway/src/clients/service-client.ts index bb4156e..5d2a33d 100644 --- a/api-gateway/src/clients/service-client.ts +++ b/api-gateway/src/clients/service-client.ts @@ -2,9 +2,10 @@ // // SPDX-License-Identifier: LGPL-2.1-or-later -import express from 'express' import axios from 'axios' -import { createAuthHeader, AppSessionUser } from '../auth/index.js' +import express from 'express' + +import { AppSessionUser, createAuthHeader } from '../auth/index.js' import { serviceUrl } from '../config.js' export const client = axios.create({ @@ -17,7 +18,9 @@ const systemUser: AppSessionUser = { export type ServiceRequestHeader = 'Authorization' | 'X-Request-ID' -export type ServiceRequestHeaders = { [H in ServiceRequestHeader]?: string } +export type ServiceRequestHeaders = Partial< + Record +> export function createServiceRequestHeaders( req: express.Request | undefined, diff --git a/api-gateway/src/logging/index.ts b/api-gateway/src/logging/index.ts index fcc5282..cf575db 100644 --- a/api-gateway/src/logging/index.ts +++ b/api-gateway/src/logging/index.ts @@ -76,7 +76,7 @@ export const logDebug: LogFn = (msg, req?, meta?) => function log( level: LogLevel, msg: string, - req?: Request, + _req?: Request, meta?: LogMeta, err?: Error ): void { diff --git a/api-gateway/src/utils/express.ts b/api-gateway/src/utils/express.ts index b1d2c26..87631b7 100644 --- a/api-gateway/src/utils/express.ts +++ b/api-gateway/src/utils/express.ts @@ -65,7 +65,6 @@ declare global { spanId?: string samlLogoutRequest: passportSaml.Profile } - // eslint-disable-next-line @typescript-eslint/no-empty-interface interface User extends AppSessionUser {} } } @@ -80,7 +79,7 @@ declare global { // * `req.secure`: is original request https (true) export function trustReverseProxy(app: express.Application) { app.set('trust proxy', 3) // private ALB, proxy nginx, public ALB - app.use((req, res, next) => { + app.use((req, _res, next) => { if ('x-original-forwarded-proto' in req.headers) { req.headers['x-forwarded-proto'] = req.headers['x-original-forwarded-proto'] diff --git a/api-gateway/src/utils/promise-utils.ts b/api-gateway/src/utils/promise-utils.ts index 34f8919..9a1d867 100644 --- a/api-gateway/src/utils/promise-utils.ts +++ b/api-gateway/src/utils/promise-utils.ts @@ -8,7 +8,6 @@ export function fromCallback( f: (cb: (err: any, result?: T) => void) => void ): Promise { return new Promise((resolve, reject) => - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion f((err, result) => (err ? reject(err) : resolve(result!))) ) } diff --git a/api-gateway/yarn.lock b/api-gateway/yarn.lock index 4f56e46..7972e02 100644 --- a/api-gateway/yarn.lock +++ b/api-gateway/yarn.lock @@ -653,6 +653,29 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/eslint-plugin@npm:8.16.0": + version: 8.16.0 + resolution: "@typescript-eslint/eslint-plugin@npm:8.16.0" + dependencies: + "@eslint-community/regexpp": "npm:^4.10.0" + "@typescript-eslint/scope-manager": "npm:8.16.0" + "@typescript-eslint/type-utils": "npm:8.16.0" + "@typescript-eslint/utils": "npm:8.16.0" + "@typescript-eslint/visitor-keys": "npm:8.16.0" + graphemer: "npm:^1.4.0" + ignore: "npm:^5.3.1" + natural-compare: "npm:^1.4.0" + ts-api-utils: "npm:^1.3.0" + peerDependencies: + "@typescript-eslint/parser": ^8.0.0 || ^8.0.0-alpha.0 + eslint: ^8.57.0 || ^9.0.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: aa3d551d4f09940eee0c08328cb0db3a2391a8bba6d044f6bb38c51ac864896519c647d4b8fd99f7c094cc677bcf22454b27322014a08b2f2fb25695a43820db + languageName: node + linkType: hard + "@typescript-eslint/eslint-plugin@npm:^8.15.0": version: 8.15.0 resolution: "@typescript-eslint/eslint-plugin@npm:8.15.0" @@ -676,6 +699,24 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/parser@npm:8.16.0": + version: 8.16.0 + resolution: "@typescript-eslint/parser@npm:8.16.0" + dependencies: + "@typescript-eslint/scope-manager": "npm:8.16.0" + "@typescript-eslint/types": "npm:8.16.0" + "@typescript-eslint/typescript-estree": "npm:8.16.0" + "@typescript-eslint/visitor-keys": "npm:8.16.0" + debug: "npm:^4.3.4" + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: ac1e2bfdbfe212da470bb17915b5228f7a6b027332b05eb8bcbbad440a81b2476c649e54e232084838e1edc005e6d7dc7a44899587d73672dd3d5484d9dbf9f8 + languageName: node + linkType: hard + "@typescript-eslint/parser@npm:^8.15.0": version: 8.15.0 resolution: "@typescript-eslint/parser@npm:8.15.0" @@ -704,6 +745,16 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/scope-manager@npm:8.16.0": + version: 8.16.0 + resolution: "@typescript-eslint/scope-manager@npm:8.16.0" + dependencies: + "@typescript-eslint/types": "npm:8.16.0" + "@typescript-eslint/visitor-keys": "npm:8.16.0" + checksum: e0aea61f248b39049d4ce21c19f9c8af1a8024f4f92abc8c1d5b79ea65b013c6c4ff41efb92995050036aa95b6a705601917b56809d9ec1fbbab387054aeb269 + languageName: node + linkType: hard + "@typescript-eslint/type-utils@npm:8.15.0": version: 8.15.0 resolution: "@typescript-eslint/type-utils@npm:8.15.0" @@ -721,6 +772,23 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/type-utils@npm:8.16.0": + version: 8.16.0 + resolution: "@typescript-eslint/type-utils@npm:8.16.0" + dependencies: + "@typescript-eslint/typescript-estree": "npm:8.16.0" + "@typescript-eslint/utils": "npm:8.16.0" + debug: "npm:^4.3.4" + ts-api-utils: "npm:^1.3.0" + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: b91f6cef6af7e4f82a1dba9622d5ec9f46d1983eecfb88a1adbd310c7f980fedf5c8a198bfe968aae59fc386e4c437f55a7533988252eb9cbb0bdac8321e3dba + languageName: node + linkType: hard + "@typescript-eslint/types@npm:8.15.0": version: 8.15.0 resolution: "@typescript-eslint/types@npm:8.15.0" @@ -728,6 +796,13 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/types@npm:8.16.0": + version: 8.16.0 + resolution: "@typescript-eslint/types@npm:8.16.0" + checksum: b37b26cd0e45b0cd6f7d492a07af583e4877d798495ab5fc1cfacb3c561b6d7981e3166f0475bb997e6c6d56ef903e160895174c7e63c08322dbb42d026cf7dc + languageName: node + linkType: hard + "@typescript-eslint/typescript-estree@npm:8.15.0": version: 8.15.0 resolution: "@typescript-eslint/typescript-estree@npm:8.15.0" @@ -747,6 +822,25 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/typescript-estree@npm:8.16.0": + version: 8.16.0 + resolution: "@typescript-eslint/typescript-estree@npm:8.16.0" + dependencies: + "@typescript-eslint/types": "npm:8.16.0" + "@typescript-eslint/visitor-keys": "npm:8.16.0" + debug: "npm:^4.3.4" + fast-glob: "npm:^3.3.2" + is-glob: "npm:^4.0.3" + minimatch: "npm:^9.0.4" + semver: "npm:^7.6.0" + ts-api-utils: "npm:^1.3.0" + peerDependenciesMeta: + typescript: + optional: true + checksum: 823cf55d331cf7283547a2860a5d7bfd7dbd497be6e87b226dd7456b36db214de1504855afbbaef8d89932c11a1e589d4cb2a4093b6f1c542a4ce8319d988006 + languageName: node + linkType: hard + "@typescript-eslint/utils@npm:8.15.0": version: 8.15.0 resolution: "@typescript-eslint/utils@npm:8.15.0" @@ -764,6 +858,23 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/utils@npm:8.16.0": + version: 8.16.0 + resolution: "@typescript-eslint/utils@npm:8.16.0" + dependencies: + "@eslint-community/eslint-utils": "npm:^4.4.0" + "@typescript-eslint/scope-manager": "npm:8.16.0" + "@typescript-eslint/types": "npm:8.16.0" + "@typescript-eslint/typescript-estree": "npm:8.16.0" + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: 80ba35b97a8e80ac2b54a56ac041b4f4583328d764e1693e7d3750de383cbcefcb7e838b75e550e8aa4df446f4b41460da6dc83543517280a4e3a61546c1a8dc + languageName: node + linkType: hard + "@typescript-eslint/visitor-keys@npm:8.15.0": version: 8.15.0 resolution: "@typescript-eslint/visitor-keys@npm:8.15.0" @@ -774,6 +885,16 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/visitor-keys@npm:8.16.0": + version: 8.16.0 + resolution: "@typescript-eslint/visitor-keys@npm:8.16.0" + dependencies: + "@typescript-eslint/types": "npm:8.16.0" + eslint-visitor-keys: "npm:^4.2.0" + checksum: e3f231a3e8ca2f7a3dc0e9ebdc3ea1f51a377b1285727413b4c89c44dbfaf342f2574b1b4e7f478f295963045a6058e27b4827816fe2a5a2d09f565eb68522c7 + languageName: node + linkType: hard + "@xmldom/is-dom-node@npm:^1.0.1": version: 1.0.1 resolution: "@xmldom/is-dom-node@npm:1.0.1" @@ -3038,6 +3159,7 @@ __metadata: source-map-support: "npm:^0.5.21" ts-node: "npm:^10.9.2" typescript: "npm:^5.7.2" + typescript-eslint: "npm:^8.16.0" zod: "npm:^3.23.8" languageName: unknown linkType: soft @@ -4043,6 +4165,22 @@ __metadata: languageName: node linkType: hard +"typescript-eslint@npm:^8.16.0": + version: 8.16.0 + resolution: "typescript-eslint@npm:8.16.0" + dependencies: + "@typescript-eslint/eslint-plugin": "npm:8.16.0" + "@typescript-eslint/parser": "npm:8.16.0" + "@typescript-eslint/utils": "npm:8.16.0" + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: bbcb31482210aeb715c0f41f659d642491828c0779426e5cceef70fa0ad96f3eeaf0cd3faaed1cc50965855a5324cf0b03790abc284f5364b2be458b0380337a + languageName: node + linkType: hard + "typescript@npm:^5.7.2": version: 5.7.2 resolution: "typescript@npm:5.7.2"