Fix new high-severity SonarCloud issues - #86
Conversation
- Reduce cognitive complexity of DiskCollector.Collect, decodeHistory, and Engine.evalMetric below the 15 threshold by extracting the per-mountpoint, per-series, and state-transition logic into focused helper functions (go:S3776). Behavior is unchanged and covered by existing tests. - Prefer element.dataset over setAttribute/removeAttribute for the data-theme toggle (javascript:S7761). - Replace var with const in theme-init.js (javascript:S3504). - Make the Memory & Swap card's accessible name include its visible label text, matching the other metric cards (Web:S7927).
sonar.projectKey pointed at networlddev_PiMonitor, which does not exist on SonarCloud (confirmed 404 via the components API). The real project lives under the same networlddev organization as LarsLaskowski_PiMonitor. With the wrong key, CI analysis was landing on a non-existent/ghost project instead of the one actually tracked on the dashboard.
|
Added a fix for the SonarCloud project key mismatch you flagged: |
|
|
Added the remaining 25 open MEDIUM/LOW-severity SonarCloud issues in commit d378425 (33 total minus the 2 accessibility rules that only fully resolve via the same HTML restructure, counted together below):
This is the most behaviorally-sensitive part of the two PRs, so I ran it in a real browser (Playwright/Chromium) rather than relying on the Go test suite alone (which doesn't cover the JS/HTML): card header buttons open the detail modal via click and Enter, all three dialogs open/close via trigger, Escape, and backdrop click (except the API key prompt, which correctly ignores both), focus returns to the triggering element on close, native focus trapping keeps Tab inside the open dialog, and the whole card — not just the header button — is still clickable. No visual regressions in light or dark theme. One real bug came out of that verification and is already fixed in the same commit:
Generated by Claude Code |



📖 Description
Fixes the 8 currently-open SonarCloud issues at HIGH severity (MAINTAINABILITY impact) on
LarsLaskowski_PiMonitor. Lower-severity issues (MEDIUM/LOW) are intentionally left for a follow-up, as requested.go:S3776— Cognitive Complexity (internal/alert/alert.go:232,internal/collector/persist.go:208,internal/collector/disk.go:185):Engine.evalMetric,decodeHistory, andDiskCollector.Collecteach exceeded the 15-point limit (20–21). Extracted the per-mountpoint statfs logic (collectDisk,dedupeMounts,markBad), the per-series binary decode logic (decodeSeries,decodeHistoryPoints), and the debounce state machine (updateThresholdState,nextLevel) into focused helper functions. Pure refactor — behavior is unchanged.javascript:S7761— Prefer.datasetoversetAttribute/removeAttribute(internal/web/assets/theme-init.js:12,internal/web/assets/app.js:80,82): switched thedata-themetoggle toelement.dataset.theme = …/delete element.dataset.theme.javascript:S3504— Preferlet/constovervar(internal/web/assets/theme-init.js:10):var stored→const stored.Web:S7927— Accessible name should include the visible label (internal/web/assets/index.html:87): the Memory & Swap card'saria-label("Open memory usage detail") didn't contain its visible label text, unlike the other three metric cards. Changed to "Open Memory & Swap detail".🎫 Issues
N/A (SonarCloud housekeeping, no linked GitHub issue).
👩💻 Reviewer Notes
All changes are behavior-preserving refactors or trivial JS/HTML style fixes — no functional/API change. Worth a close read of the extracted
disk.go/persist.go/alert.gohelpers to confirm the control flow still matches the original exactly (I cross-checked each branch against the existing tests, which already exercise the affected paths: timeout/cooldown, zero-size mount, dedup, truncated/corrupt history, debounce escalation/flapping).📑 Test Plan
go build ./...,go vet ./...,go test ./... -race -cover— all pass, no test changes needed since existing tests already cover every branch touched by the refactor.golangci-lint run— 0 issues..dataset/constchanges are behaviorally identical (verified by readingstyle.css's[data-theme]selectors, which are unaffected by the attribute being set viasetAttributevs.dataset).✅ Checklist
General
go test ./... -race -coverpasses locally). (No new tests needed — behavior-preserving refactor, already covered.)go vet ./...andgolangci-lint runare clean.ARCHITECTURE.mdif this changes a documented design decision. (N/A — no design decision changed.)⏭ Next Steps
The remaining 37 open SonarCloud issues (17 MAJOR/MEDIUM, 20 MINOR/LOW as of this PR) were left untouched per the request to focus on high severity first.