Skip to content

ci: lint with ESLint, typescript-eslint and sonarjs rules - #12

Merged
HandyS11 merged 1 commit into
mainfrom
ci/eslint-sonarjs
Nov 6, 2026
Merged

HandyS11 merged 1 commit into
mainfrom
ci/eslint-sonarjs

Conversation

@HandyS11

@HandyS11 HandyS11 commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Why

The self-hosted SonarQube is Community Edition, so it can't analyze pull requests, only main after merge. This PR runs the same JS/TS rules (eslint-plugin-sonarjs recommended) in the existing CI job instead, so they apply to every PR with no server or secrets.

Changes

  • eslint.config.js: @eslint/js recommended, typescript-eslint recommended and sonarjs recommended, all on src/**/*.ts. Type information is on (projectService) so the sonarjs rules that need it can run.
  • npm run lint script, plus a lint step in CI before npm test (Node 22 and 24). The README's Development section lists the new command.
  • Fixes for what the first run reported (16 errors). None of them change behavior:
    • normalizeUsage and aggregate had cognitive complexity 19, over the limit of 15. Split out toLimit and addToBucket.
    • planLabel used a nested ternary. It's now an if.
    • projectLabel used String.match. It now uses RegExp.exec.
    • scanProjects initialized files = [] but never read that value.
  • @typescript-eslint/no-explicit-any is off. All 11 hits read untyped JSON (credentials file, unofficial endpoints, transcripts) behind typeof guards, on purpose. sonarjs's own any rule (no-return-type-any) is also off in its recommended config.

Trade-offs

  • Bigger install for end users. CloudCLI installs plugins with npm install, which pulls in devDependencies because tsc is needed to build. node_modules grows from 26 MB to 68 MB (83 more packages).
  • npm audit warning. npm audit reports a moderate ReDoS in minimatch (GHSA-g3hv-75wg-m249), pulled in by eslint and typescript-eslint. It's dev-only and only matches the repo's own glob patterns. The only fix npm offers is downgrading eslint-plugin-sonarjs to 2.x.

Test plan

  • npm run lint: clean (16 errors before the fixes)
  • npm test: 53/53 pass on Node 26
  • CI green on Node 22 and 24

🤖 Generated with Claude Code

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>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 18:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/**/*.ts using @eslint/js, typescript-eslint, and sonarjs recommended rules (with type information enabled).
  • Introduce npm run lint and 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

Comment thread package.json
Comment on lines +13 to +16
"@eslint/js": "^10.0.1",
"@types/node": "^20.0.0",
"eslint": "^10.14.0",
"eslint-plugin-sonarjs": "^4.2.2",

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@HandyS11
HandyS11 merged commit 87ca9d3 into main Nov 6, 2026
6 checks passed
@HandyS11
HandyS11 deleted the ci/eslint-sonarjs branch November 6, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants