From 69a093e7e193f087a2a47b6e25a089bf815e6fd5 Mon Sep 17 00:00:00 2001 From: Kari Lintulaakso Date: Thu, 20 Nov 2025 15:19:21 +0200 Subject: [PATCH] Align lint and type-check configuration --- backend/src/utils/db.ts | 19 +++++++++++++++++-- backend/tsconfig.json | 9 ++++++++- eslint.config.mjs | 33 ++++++++++++++++++++++++++------- frontend/tsconfig.json | 6 +++--- package.json | 14 ++++++++++---- 5 files changed, 64 insertions(+), 17 deletions(-) diff --git a/backend/src/utils/db.ts b/backend/src/utils/db.ts index 737cc3b1..603c97ee 100644 --- a/backend/src/utils/db.ts +++ b/backend/src/utils/db.ts @@ -1,14 +1,29 @@ import { sleep } from './common' import { logger } from './logger' import { PrismaClient as NowClient } from '../../prisma/generated/now_test_client' -import { PrismaClient as LogClient } from '../../prisma/generated/now_log_test_client' +import { PrismaClient as LogClient } from '../../prisma/generated/now_log_test_client/default' import mariadb from 'mariadb' import { MARIADB_HOST, MARIADB_PASSWORD, DB_CONNECTION_LIMIT, MARIADB_USER, RUNNING_ENV } from './config' import { readFile } from 'fs/promises' import { PathLike } from 'fs' -export const logDb = new LogClient() +type LogRecord = Record & { + luid?: number + suid?: number + buid?: number + tuid?: number +} + +type LogModel = { + findMany: (...args: unknown[]) => Promise + findFirst: (...args: unknown[]) => Promise + fields: Record +} + +type LogPrismaClient = LogClient & { log: LogModel } + +export const logDb = new LogClient() as unknown as LogPrismaClient export const nowDb = new NowClient() export const getCrossSearchFields = () => { diff --git a/backend/tsconfig.json b/backend/tsconfig.json index b3552ac6..710654dc 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -4,13 +4,20 @@ "outDir": "./build/", "module": "CommonJS", "moduleResolution": "node", + "baseUrl": ".", "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, "esModuleInterop": true, - "noImplicitAny": true + "noImplicitAny": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "types": ["node"], + "paths": { + "../../prisma/generated/now_log_test_client": ["./prisma/generated/now_log_test_client/default.ts"] + } }, "include": ["src"] } diff --git a/eslint.config.mjs b/eslint.config.mjs index 709ed11f..31a236f0 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,28 +1,47 @@ import globals from 'globals' -import jsPlugin from '@eslint/js' import cypressPlugin from 'eslint-plugin-cypress/flat' import prettierPlugin from 'eslint-plugin-prettier/recommended' import mochaPlugin from 'eslint-plugin-mocha' // NOTE: This config is only used for running ESLint on the Cypress tests. Frontend and backend use their own configs. +const mochaRecommended = mochaPlugin.configs.flat.recommended +const cypressRecommended = cypressPlugin.configs.recommended +const mochaLanguageOptions = mochaRecommended.languageOptions ?? {} +const cypressLanguageOptions = cypressRecommended.languageOptions ?? {} +const mochaRules = mochaRecommended.rules ?? {} +const cypressRules = cypressRecommended.rules ?? {} + /** @type {import('eslint').Linter.Config[]} */ export default [ - mochaPlugin.configs.flat.recommended, - cypressPlugin.configs.recommended, - { + files: ['cypress/**/*.{cy,spec}.{js,ts,tsx}'], + ...mochaRecommended, + ...cypressRecommended, rules: { - ...jsPlugin.configs.recommended.rules, + ...mochaRules, + ...cypressRules, 'mocha/no-mocha-arrows': 'off', 'mocha/no-skipped-tests': 'off', 'mocha/max-top-level-suites': 'off', 'mocha/no-top-level-hooks': 'off', 'mocha/no-sibling-hooks': 'off', }, - languageOptions: { - globals: globals.browser, + ...mochaLanguageOptions, + ...cypressLanguageOptions, + globals: { + ...globals.browser, + ...globals.node, + }, + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + }, + plugins: { + mocha: mochaPlugin, + cypress: cypressPlugin, }, }, diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 661b09ba..67a9a40b 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -22,7 +22,7 @@ "noFallthroughCasesInSwitch": true, "noImplicitAny": true, "baseUrl": ".", - "types": ["node", "jest"], + "types": ["vite/client", "jest", "node"], "paths": { "@/*": ["./src/*"], "@components/*": ["./src/components/*"], @@ -30,8 +30,8 @@ "@shared/*": ["../shared/*"] } }, - "include": ["src", "tests"], - "exclude": ["../backend/**/*", "./src/country_data/**"], + "include": ["src", "tests", "vite.config.ts", "jest.config.ts"], + "exclude": ["../backend/**/*", "./src/country_data/**", "node_modules", "dist"], "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/package.json b/package.json index 36e38dc9..166c1b8d 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,17 @@ "dev": "docker compose -f docker-compose.dev.yml up", "dev:down": "docker compose -f docker-compose.dev.yml down -v", "anon:down": "docker compose -f docker-compose.anon.yml down -v", - "check": "echo \"Running checks for both services and cypress tests...\" && npm run check:frontend && npm run check:backend && npm run check:cypress && echo \"All good! :)\"", - "check:backend": "echo \"Running backend tsc ...\" && cd backend && npx tsc --noEmit && echo \"Running backend eslint ...\"&& npm run lint", - "check:frontend": "echo \"Running frontend tsc ...\" && cd frontend && npx tsc --noEmit && echo \"Running frontend eslint ...\" && npm run lint", - "check:cypress": "echo \"Running cypress eslint ...\" && npm run lint:cypress", + "check": "echo \"Running checks for both services and cypress tests...\" && npm run tsc && npm run lint && echo \"All good! :)\"", + "check:backend": "npm run tsc:backend && npm run lint:backend", + "check:frontend": "npm run tsc:frontend && npm run lint:frontend", + "check:cypress": "npm run lint:cypress", + "lint": "npm run lint:backend && npm run lint:frontend && npm run lint:cypress", + "lint:backend": "cd backend && npm run lint", + "lint:frontend": "cd frontend && npm run lint", "lint:cypress": "eslint --report-unused-disable-directives --max-warnings 0 cypress/e2e/**.cy.js", + "tsc": "npm run tsc:backend && npm run tsc:frontend", + "tsc:backend": "cd backend && npx tsc --noEmit", + "tsc:frontend": "cd frontend && npx tsc --noEmit", "test:backend": "npm run test:unit:backend && npm run test:api", "test:api": "npm run test:api:build && npm run test:api:run", "test:api:build": "docker build -t nowdb-api-tests . -f backend/dev.Dockerfile --target api-tests",