Skip to content

fix: resolve 40 SonarCloud critical issues#420

Merged
RobertLD merged 1 commit intomainfrom
fix/sonar-critical-419
Mar 18, 2026
Merged

fix: resolve 40 SonarCloud critical issues#420
RobertLD merged 1 commit intomainfrom
fix/sonar-critical-419

Conversation

@RobertLD
Copy link
Copy Markdown
Owner

Summary

Resolves 40 of 75 SonarCloud critical/blocker issues from the quality gate scan. Fixes span TypeScript source, Go SDK, and Python SDK.

Closes #419

S2871 — String sort without comparator (12 fixes)

Bare .sort() on string arrays replaced with .sort((a, b) => a.localeCompare(b)) for locale-aware sorting.

  • src/registry/checksum.ts, src/core/parsers/index.ts, src/cli/index.ts
  • 9 test files across unit and integration suites

S1186 — Empty methods in SilentReporter (6 fixes)

Added // intentionally empty — silent reporter to each no-op method in src/cli/reporter.ts.

S2004 — Nested function depth (1 fix)

Extracted closeHttpServer() helper from src/api/server.ts to reduce nesting below 4 levels.

S1192 — Duplicate string literals (10 fixes)

  • Go SDK: Extracted errUnexpectedPath, headerContentType, mimeJSON, errUnexpected, testGoDevDocURL constants in test files
  • Python SDK: Extracted _PATH_DOCUMENTS, _PATH_TOPICS module-level constants in client.py

S3776 — Cognitive complexity reduction (11 fixes)

Functions barely over threshold (16-19) reduced via helper extraction and early returns:

  • src/registry/git.ts, src/registry/search.ts, src/registry/publish.ts
  • src/cli/commands/registry.ts, src/cli/index.ts
  • src/core/spider.ts, src/core/search.ts, src/core/packs.ts
  • src/api/middleware.ts, src/config.ts

Not addressed (35 remaining S3776 issues)

Functions with complexity 20-306 require larger refactoring efforts (e.g., routes.ts at 306, slack.ts at 88). These are tracked but deferred to avoid an unreviewable PR.

Test plan

  • All 1351 tests pass (73 files)
  • Prettier format check passes
  • No new lint errors
  • Go SDK: go test ./... and go vet ./... pass

🤖 Generated with Claude Code

S2871 — String sort without comparator (12 fixes):
- Replace bare .sort() with .sort((a, b) => a.localeCompare(b)) in
  src/registry/checksum.ts, src/core/parsers/index.ts, src/cli/index.ts,
  and 9 test files

S1186 — Empty methods (6 fixes):
- Add intentional-no-op comments to SilentReporter methods in
  src/cli/reporter.ts

S2004 — Nested functions too deep (1 fix):
- Extract closeHttpServer() helper from src/api/server.ts

S1192 — Duplicate string literals (10 fixes):
- Extract constants in sdk/go/documents_test.go, sdk/go/search_test.go
- Extract _PATH_DOCUMENTS/_PATH_TOPICS in sdk/python/src/pylibscope/client.py

S3776 — Cognitive complexity reduction (11 fixes):
- src/registry/git.ts: extract extractEntryName()
- src/registry/search.ts: extract resolveRegistries(), readRegistryPacks()
- src/cli/commands/registry.ts: extract syncSingleRegistry(), syncAllRegistriesAction()
- src/core/spider.ts: extract scanPastTag(), processRobotsLine()
- src/registry/publish.ts: extract removeEntirePack(), updateManifestAndIndex()
- src/core/search.ts: extract addRankedList(), computeRrfScores()
- src/api/middleware.ts: extract evictRateLimitEntries()
- src/config.ts: extract validateProviderConfig(), validateDatabasePath()
- src/core/packs.ts: flatten nested conditionals with early continue
- src/cli/index.ts: extract onenoteDeviceAuth(), onenoteRefreshAuth()

Closes #419

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
libscope Ignored Ignored Mar 18, 2026 9:42pm

@sonarqubecloud
Copy link
Copy Markdown

@RobertLD RobertLD merged commit bf6e1be into main Mar 18, 2026
20 checks passed
@RobertLD RobertLD deleted the fix/sonar-critical-419 branch March 18, 2026 21:53
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.

Implement suggested sonarqube code improvements

1 participant