chore: clear sonarcloud code smells failing the quality gate - #232
Merged
Merged
Conversation
Signed-off-by: Nacho Vazquez <nacho@naxo.dev>
|
View your CI Pipeline Execution ↗ for commit 86df674
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
|
NachoVazquez
added a commit
that referenced
this pull request
Jul 25, 2026
## TL;DR The SonarCloud job passes the moment the report finishes uploading, so the GitHub check said green while the quality gate sat at `ERROR` on `main` — undetected since 2020. Setting `sonar.qualitygate.wait=true` makes the scanner poll for the verdict and exit non-zero when the gate fails. Follow-up to #232, which cleared the 22 code smells that had the gate red. Gate on `main` is now `OK` with 0 failing conditions, so this flag lands green. ## Why `sonarqube-scan-action` uploads the analysis and returns. Computing the gate happens server-side afterwards, and nothing was reading the result — the check reported on the upload, not the verdict. Any gate regression was invisible in CI and only discoverable by opening the SonarCloud dashboard. | | Before | After | |---|---|---| | Job passes when | Report uploads | Gate returns `OK` | | Gate `ERROR` on `main` | Check stays green | Job fails | | Gate `ERROR` on a PR | Check stays green | Check blocks merge | ## Reviewer notes - **Placed in `sonar-project.properties`, not the workflow.** It applies to every analysis — pull request and `main` — rather than only the one CI step, and it lives beside the exclusions it interacts with. - **PR analyses are judged on new code only.** SonarCloud evaluates just the `new_*` conditions on pull requests, so this blocks a PR that *introduces* smells without holding it responsible for pre-existing ones. - **This makes the gate load-bearing, which raises the stakes on its conditions.** `Ngworkers Quality Gate` (id 40275) still judges overall code via `code_smells > 0` and `sqale_index > 0`. Those are satisfiable today at 0, but three of the five smells fixed in #232 appeared purely from analyzer upgrades, with no code change. The next such release turns a red gate into a red `main`. Dropping both conditions — `new_code_smells > 0` already covers what matters — needs org-admin access in the SonarCloud UI and is the recommended companion to this PR. - **Adds roughly 30 seconds to the job.** The scanner polls the compute-engine task; default timeout is 300s. ## Tests Config-only. Verified `configure-sonar-report-paths.mjs` still rewrites both placeholders with the new property present, and `nx format:check` is clean. The real proof is this PR's own SonarCloud check, which now reflects the gate rather than the upload. ## Links - [#232](#232) — cleared the code smells this depends on - [SonarCloud project dashboard](https://sonarcloud.io/project/overview?id=ngworker_lumberjack) Signed-off-by: Nacho Vazquez <nacho@naxo.dev>
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.



TL;DR
SonarCloud's quality gate has been
ERRORonmainwhile the GitHub check stayed green — 22 code smells and 122 minutes of debt fail the gate's overall-code conditions, and the scan job never waits for the verdict. This PR fixes the 5 actionable smells and excludes the rule behind the other 17, which are deliberate.Files to review (6, +24 / −16):
sonar-project.properties(start here)packages/internal/test-util/src/lib/spy-driver/spy.driver.tsdriverIdentifierwas the lone mutable one across six drivers.e2e/examples/lumberjack-app-e2e/src/e2e/console-driver.cy.tsvisithoisted out of thedescribecallback.packages/ngworker/lumberjack/src/lib/logging/lumberjack-log-factory.spec.tstools/scripts/configure-sonar-report-paths.mjstools/scripts/delete-path-alias.mjsfs→node:fs.Why
The gate fails on two conditions, both scoped to overall code:
code_smells > 0(actual: 22) andsqale_index > 0(actual: 122 min). Every new-code condition passes — 0 new smells, 0 new debt — as do coverage (99.7%), duplication (0.7%), and all six ratings. Nothing recent caused this; the oldest findings date to 2020-12.Three of the five fixed smells appeared without anyone touching the code.
S7772,S7785, andS7721ship in newer analyzer versions and started flagging files that had been stable for years.How
17 of the 22 are a single rule,
typescript:S5914("assertion always succeeds"), and every one sits in a*-api.spec.tspublic-API-surface test:Sonar is right that the runtime assertion can't fail, and wrong that it matters. The test is the type annotation — drop the export and this file stops compiling. Rewriting the assertion to satisfy the rule would delete the thing being tested, so the rule is excluded for that file pattern instead. The remaining 5 are genuine and fixed in place.
Reviewer notes
sonar.issue.ignore.multicriteriatargetstypescript:S5914on**/*-api.spec.tsonly. S5914 elsewhere still reports, and the API specs still get every other rule.readonlyonSpyDriveris consistency, not rule-appeasement.LumberjackHttpDriver,LumberjackConsoleDriver,NoopDriver,ObjectDriver, andErrorThrowingDriverall already declarestatic readonly driverIdentifier.SpyDriverwas the only holdout.configure-sonar-report-paths.mjsis ESM andpackage.jsonpinsengines.node >= 22.Tests
No new tests — every change is a lint-level fix or config. Full verification run locally:
nx run-many --target=lint --max-warnings=0— 7 projects, cleannx run-many --target=test— 4 projects;ngworker-lumberjackalone is 32 suites / 193 testsnx build ngworker-lumberjack— succeedsnx format:check— cleanconfigure-sonar-report-paths.mjsrun against a scratch copy of the properties file: exits 0, both placeholders replaced, all three exclusion lines survive the rewriteWhether the exclusion actually suppresses all 17 findings can only be confirmed by the post-merge analysis on
main— SonarCloud evaluates only new-code conditions on pull requests, so this PR's own check will not prove it.Follow-up
code_smells > 0andsqale_index > 0from Ngworkers Quality Gate (id 40275). Overall-code conditions guaranteemaingoes red again on the next analyzer release, andnew_code_smells > 0already covers what matters. Requires org-admin access in the SonarCloud UI.sonar.qualitygate.wait=trueto the scan step so the GitHub check reflects the gate instead of passing on upload. Worth doing only after (1) lands — otherwise a red gate silently becomes a redmain.Links