diff --git a/.changeset/eslint-api-oneoffs.md b/.changeset/eslint-api-oneoffs.md new file mode 100644 index 0000000000..681290c3f2 --- /dev/null +++ b/.changeset/eslint-api-oneoffs.md @@ -0,0 +1,12 @@ +--- +'@hyperdx/api': patch +--- + +Clear the remaining small api ESLint warnings and enforce their rules. Merges +the duplicate Express `declare global` namespace blocks in the auth middleware +(the `namespace` + empty-interface augmentation pattern is required, so it +carries a scoped disable with a comment), and scopes `n/no-process-exit` off for +the process entry points (`src/index.ts`, `src/tasks/index.ts`) where exiting +with a status code is intended. `@typescript-eslint/no-namespace`, +`no-empty-object-type`, and `n/no-process-exit` are promoted to `error` and the +api `--max-warnings` ceiling is lowered. Behavior is unchanged. diff --git a/packages/api/eslint.config.mjs b/packages/api/eslint.config.mjs index 1c7a1f91b9..e5dfaa9697 100644 --- a/packages/api/eslint.config.mjs +++ b/packages/api/eslint.config.mjs @@ -39,11 +39,11 @@ export default [ ...securityPlugin.configs['recommended-legacy'].rules, '@typescript-eslint/ban-ts-comment': 'error', '@typescript-eslint/no-empty-interface': 'off', - '@typescript-eslint/no-empty-object-type': 'warn', + '@typescript-eslint/no-empty-object-type': 'error', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-floating-promises': 'error', '@typescript-eslint/no-unsafe-type-assertion': 'warn', - '@typescript-eslint/no-namespace': 'warn', + '@typescript-eslint/no-namespace': 'error', '@typescript-eslint/no-unused-vars': [ 'error', { @@ -57,7 +57,7 @@ export default [ tryExtensions: ['.js', '.ts', '.json'], }, ], - 'n/no-process-exit': 'warn', + 'n/no-process-exit': 'error', 'n/no-missing-import': 'off', 'n/no-unpublished-import': [ 'error', @@ -114,4 +114,13 @@ export default [ }, }, }, + { + // Process entry points and the CLI task runner: exiting with a status code + // on startup failure, task completion, or a last-resort uncaught-exception + // handler is the intended behavior here. + files: ['src/index.ts', 'src/tasks/index.ts'], + rules: { + 'n/no-process-exit': 'off', + }, + }, ]; diff --git a/packages/api/package.json b/packages/api/package.json index 211af2740c..48b9dd1344 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -100,7 +100,7 @@ "dev-task": "DOTENV_CONFIG_PATH=.env.development nodemon --exec 'ts-node' --transpile-only -r tsconfig-paths/register -r dotenv-expand/config -r '@hyperdx/node-opentelemetry/build/src/tracing' ./src/tasks/index.ts", "build": "rimraf ./build && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && cp -r ./src/opamp/proto ./build/opamp/", "build:vercel": "rimraf ./build && tsc -p tsconfig.vercel.json && tsc-alias -p tsconfig.vercel.json && cp -r ./src/opamp/proto ./build/opamp/", - "lint": "npx eslint . --ext .ts --max-warnings 311", + "lint": "npx eslint . --ext .ts --max-warnings 302", "lint:fix": "npx eslint . --ext .ts --fix", "ci:lint": "yarn lint && yarn tsc --noEmit && yarn lint:openapi", "ci:unit": "jest --ci --coverage", diff --git a/packages/api/src/middleware/auth.ts b/packages/api/src/middleware/auth.ts index c96bea0559..4db9840162 100644 --- a/packages/api/src/middleware/auth.ts +++ b/packages/api/src/middleware/auth.ts @@ -12,10 +12,12 @@ import { import logger from '@/utils/logger'; declare global { + // Express type augmentation requires `namespace` + interface merging; there is + // no non-namespace / non-empty-interface equivalent for extending these types. + // eslint-disable-next-line @typescript-eslint/no-namespace namespace Express { + // eslint-disable-next-line @typescript-eslint/no-empty-object-type interface User extends UserDocument {} - } - namespace Express { interface Request { _hdx_connection?: Connection; } diff --git a/scripts/ci/ratchet-baseline.json b/scripts/ci/ratchet-baseline.json index 2ef206ed52..bf51d83bd0 100644 --- a/scripts/ci/ratchet-baseline.json +++ b/scripts/ci/ratchet-baseline.json @@ -1,12 +1,12 @@ { "api": { - "as-any": 95, - "ts-ignore": 4, - "eslint-disable": 29 + "as-any": 94, + "ts-ignore": 0, + "eslint-disable": 31 }, "app": { "as-any": 215, - "ts-ignore": 11, + "ts-ignore": 0, "eslint-disable": 143 }, "cli": { @@ -16,7 +16,7 @@ }, "common-utils": { "as-any": 116, - "ts-ignore": 5, + "ts-ignore": 0, "eslint-disable": 39 }, "hdx-eval": {