Repository navigation
ci: lint with ESLint, typescript-eslint and sonarjs rules - #12
Conversation
Runs the SonarQube JS/TS rules (eslint-plugin-sonarjs recommended) on every push and pull request, without a SonarQube server. The self-hosted instance is Community Edition and cannot analyze pull requests. The first run reported 16 errors. Fixed: - normalizeUsage and aggregate were over the cognitive complexity limit (19 vs 15): split out toLimit and addToBucket. - planLabel used a nested ternary. - projectLabel used String.match instead of RegExp.exec. - scanProjects initialized `files` with a value it never read. Turned off @typescript-eslint/no-explicit-any: the 11 hits all read untyped JSON behind typeof guards, on purpose. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟡 Changes recommended
The change introduces lint devDependencies whose package-lock engines require newer Node versions, but package.json lacks an explicit engines.node constraint, which can cause unclear install failures for users on older Node.
1 open issue
What changed in this PR
This pull request adds ESLint-based linting (including type-aware typescript-eslint and eslint-plugin-sonarjs recommended rules) and integrates it into CI so PRs get consistent JS/TS static analysis without relying on SonarQube PR support.
Changes:
- Add a flat ESLint configuration for
src/**/*.tsusing@eslint/js,typescript-eslint, andsonarjsrecommended rules (with type information enabled). - Introduce
npm run lintand run linting in CI before tests (Node 22/24). - Apply small refactors/cleanups in TS sources to satisfy initial lint findings (no intended behavior changes).
Approval Readiness
This pull request requires changes.
| File | Summary |
|---|---|
src/transcripts.ts |
Removes an unnecessary initialization flagged by linting (keeps behavior the same). |
src/live.ts |
Refactors normalizeUsage by extracting defensive limit parsing into a helper to reduce complexity. |
src/index.ts |
Replaces a nested ternary in planLabel with clearer conditional logic. |
src/history.ts |
Refactors aggregation bucket updates into a helper and adjusts related logic to reduce complexity/duplication. |
README.md |
Documents the new npm run lint command in the Development section. |
package.json |
Adds the lint script and ESLint-related devDependencies. |
package-lock.json |
Locks the newly added ESLint / TypeScript-ESLint / SonarJS dependency tree. |
eslint.config.js |
Introduces ESLint flat config enabling JS/TS/SonarJS recommended rules with type-aware linting. |
.github/workflows/ci.yml |
Adds a CI lint step before running tests on the Node matrix. |
Review effort: Balanced
| "@eslint/js": "^10.0.1", | ||
| "@types/node": "^20.0.0", | ||
| "eslint": "^10.14.0", | ||
| "eslint-plugin-sonarjs": "^4.2.2", |
There was a problem hiding this comment.
npm only warns on engine mismatches (engine-strict is off by default), so installs on older Node still succeed, and ESLint never runs on a user's machine: the CloudCLI build is just tsc. A root engines field wouldn't remove the EBADENGINE warnings from eslint's packages either; it would add one more. The plugin itself runs on Node 18+ (built-in fetch), so declaring eslint's range would overstate the runtime requirement. Leaving as is.

Why
The self-hosted SonarQube is Community Edition, so it can't analyze pull requests, only
mainafter merge. This PR runs the same JS/TS rules (eslint-plugin-sonarjsrecommended) in the existing CI job instead, so they apply to every PR with no server or secrets.Changes
eslint.config.js:@eslint/jsrecommended,typescript-eslintrecommended andsonarjsrecommended, all onsrc/**/*.ts. Type information is on (projectService) so the sonarjs rules that need it can run.npm run lintscript, plus a lint step in CI beforenpm test(Node 22 and 24). The README's Development section lists the new command.normalizeUsageandaggregatehad cognitive complexity 19, over the limit of 15. Split outtoLimitandaddToBucket.planLabelused a nested ternary. It's now anif.projectLabelusedString.match. It now usesRegExp.exec.scanProjectsinitializedfiles = []but never read that value.@typescript-eslint/no-explicit-anyis off. All 11 hits read untyped JSON (credentials file, unofficial endpoints, transcripts) behindtypeofguards, on purpose. sonarjs's ownanyrule (no-return-type-any) is also off in its recommended config.Trade-offs
npm install, which pulls in devDependencies becausetscis needed to build.node_modulesgrows from 26 MB to 68 MB (83 more packages).npm auditreports a moderate ReDoS inminimatch(GHSA-g3hv-75wg-m249), pulled in byeslintandtypescript-eslint. It's dev-only and only matches the repo's own glob patterns. The only fix npm offers is downgradingeslint-plugin-sonarjsto 2.x.Test plan
npm run lint: clean (16 errors before the fixes)npm test: 53/53 pass on Node 26🤖 Generated with Claude Code