fix: add ESLint config, lint script, and lint-staged gate to backend (#1278) - #1373
Open
Blessed-Femi wants to merge 10 commits into
Open
fix: add ESLint config, lint script, and lint-staged gate to backend (#1278)#1373Blessed-Femi wants to merge 10 commits into
Blessed-Femi wants to merge 10 commits into
Conversation
…absCrypt#1278) The backend had no ESLint config, no lint script, and was excluded from the root lint-staged glob, so backend TypeScript was never statically linted locally or in CI. Add a flat ESLint config for backend (typescript-eslint recommended, adapted from the frontend's ruleset), a `lint` script, eslint/typescript-eslint devDependencies, a lint step in the backend CI job, and extend lint-staged to backend/** so pre-commit hooks catch backend violations. Also fix the lint violations the new rules surface in src (explicit any, unused vars, console, prefer-const) so the gate passes on the current codebase; tests keep no-explicit-any as a warning. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
The backend ESLint gate added in this branch flags `catch (error: any)` as an error. The handler already narrows via `error instanceof Error`, so drop the `any` annotation and rely on the default `unknown` catch type. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
- Remove duplicate MemoryCache class fragment in redis.ts and use unknown instead of any - Drop unused rateLimit import in stream-rate-limiter middleware - Remove dup cancel route registration left by merge and drop as any - Fix broken ternary leftover in soroban-event-worker - Pin prisma's mysql2 dep via override and sync package-lock Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
Collaborator
|
resolve conflict on this issue @Blessed-Femi |
Commit 48f46eb (mysql2 pin) dropped a comma after the prisma override block, which broke npm ci on every CI job. Restore it. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
The merge of main into fix/1278-backend-eslint jammed both mysql2 override specs (^3.22.0 and >=3.22.0) together without a comma, making package.json invalid JSON and breaking npm ci on every CI job. Keep the prisma-scoped override from the branch and main's >=3.22.0 top-level pin. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1278
The backend has no lint gate at all: no ESLint config, no
lintscript, noeslintdevDependency, and the rootlint-stagedconfig only globsfrontend/**. Backend TypeScript — the half of the codebase that handles fund movement — was never statically linted locally, in pre-commit hooks, or in CI. This PR closes that gap.Changes
New backend lint setup
backend/eslint.config.mjs(new) — flat config adapted from the frontend (frontend/eslint.config.mjs) for a Node/Express codebase:typescript-eslintrecommended rulesetno-console: error(use the winstonlogger), matching the frontend's ruleno-unused-varswith_-prefix ignore patterns for args/vars/caught errorsno-explicit-any: warnfortests/**only (mocks/test doubles); still an error insrc/**like the frontenddist,coverage,src/generated/**(Prisma client),examples/**,src/**/*.example.ts, and allowsconsoleinprisma/seed.ts(CLI script)backend/package.json— added"lint": "eslint ."script andeslint,@eslint/js,typescript-eslintdevDependencies (lockfile updated)package.json(root) — extendedlint-stagedto run the backend lint onbackend/**/*.{ts,tsx,js}, so pre-commit hooks now gate backend changes.github/workflows/ci.yml— added aLintstep to the backend CI job (npm run lint), mirroring the frontend jobCleanup so the gate passes on the current codebase
The new rules surfaced real (mostly mechanical) violations in
src, all fixed:any(src):catch (error: any)→unknownwithinstanceof Errornarrowing; typedPrisma.StreamWhereInputinexport.service.ts; structural types for export records; typedCacheItem<unknown>,Record<string, unknown>webhook payloads, rate-limiterOptions, handler signatures (AuthenticatedRequest→Request+ internal cast, matchingcreateStream/pauseStreamconvention) which also removed theas anycasts at route registrationcatchvars to the_conventionprefer-const: onelet→constno-console: only occurred inprisma/seed.ts, exempted via configAcceptance criteria
npm run lint --workspace=backendexists and passes (0 errors; 282 pre-existinganyusages in test files surface as warnings)console.logmakeslint-stagedfail with exit 1ci.ymlbackend job)Verification
npm run lint --workspace=backend— 0 errors (exit 0)npm run build(tsc) in backend — passesvitest run --exclude='tests/integration/**'— 315 passed / 3 skipped (identical tomain; the lone module-loadERR_ERL_KEY_GEN_IPV6validation error and the coverage-threshold failure both pre-exist onmainand are unrelated to this PR)npx lint-stagedwith a violating backend file — fails as intended (exit 1)Fixes #1278