Repository navigation
chore(sonar): resolve maintainability findings (74 → 1) - #251
Merged
Merged
Conversation
Replace `expect(x.length).toBe(n)` with `expect(x).toHaveLength(n)` in the 64 places Sonar reports as typescript:S5906. Same semantics; a failing assertion now reports the collection instead of a bare number. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Address the remaining Sonar test findings where the change is also an improvement: - font-scale-utils: the increase and decrease transitions are plain data tables; use it.each with the original titles (typescript:S5976). - arduino-output-parser: the four uniform "ignore protocol fragment" cases become one it.each (typescript:S5976). - logger sanitization: two tables, one with input / marker / leaked plaintext (secret must be replaced and not logged), one with input / marker; every case keeps its title (typescript:S5976). - arduino-simulator-codechange: drop the redundant act() around waitFor, which already flushes its own updates (typescript:S8980). parser-output-pinmode: Sonar's S5976 groups were not worth parametrizing. The tests exercised a local copy of the legacy operations -> mode logic, a local counting loop and a regex literal, none of which reaches production code. The legacy fallback in IoRegistryRow (usedAt "pinMode:N" when pinModeModes is absent) is still live, so replace them with tests that render ParserOutput with legacy records and assert the displayed modes, the conflict marker and the pinModeModes precedence. Confirmed they fail when the fallback regex is broken. serial-monitor.ui is intentionally left as is: its three tests share only the setup and assert different things. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The set of PWM-capable Arduino UNO pins (3, 5, 6, 9, 10, 11) was defined three times, as an array in the pin polling engine and as a Set in parser-output and in the hardware-compatibility parser, and spelled out a fourth time in the analogWrite warning text. Sonar flagged the array (typescript:S7776); changing it locally would have kept the duplication. Define UNO_PWM_PINS and isUnoPwmPin() once in shared/utils/arduino-utils.ts (types-only imports, so no cycles) and use them in all three places. The warning text is derived from the same list and stays identical. Iteration order and behaviour are unchanged. Tests: the shared list and predicate for every UNO pin number, and the registry shows the "~" marker only for PWM-capable pins. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Summary
Clears the Sonar maintainability findings that are worth fixing, without forcing the count to zero: 74 → 1. No Sonar rule is disabled and nothing is marked as a false positive. 73 of the 74 findings were in test code; one was in production code.
typescript:S5906(expect(x.length).toBe(n))expect(x).toHaveLength(n)on exactly the reported lines; same semanticstypescript:S5976(similar tests)typescript:S8980(redundantact)act()aroundwaitFortypescript:S7776(PWM_PINSas array)No new findings were introduced (Sonar re-analysis of this head: 74 → 1, 0 new issue keys; quality gate OK; coverage and duplication unchanged).
Commits
test: use specific length assertions– 64 mechanical replacements in 25 test files.test: simplify maintainability findings–S8980and theS5976cases below.refactor: share canonical Uno PWM pins– the only production change.Decisions worth reviewing
S5976parametrized (5 groups). Only where each case stays a plain data row with its original title:font-scale-utilsincrease and decrease (6 cases each),arduino-output-parserfragment cases (4), and the logger sanitizer tests. The logger tests are two tables: input / marker / leaked plaintext (the secret must be replaced and must not be logged) and input / marker. TheNOSONAR S2068comments stay on the credential literals. I confirmed with a targeted mutation (changing the email marker) that exactly the email case fails.serial-monitor.ui.test.tsxis intentionally left alone (the one remaining finding). The three tests share only their setup and assert different things (return value, line text,incompleteflag, ANSI stripping); a table would need union columns and read worse.parser-output-pinmode.test.tsxwas not parametrized; it was replaced. The two reported groups did not test production code: the file defined its own copy ofextractPinModeData("extracted from parser-output.tsx"), a local counting loop, and tests of a regex literal against strings. The behaviour they imitate is still live, though:IoRegistryRowderives pin modes from legacyusedAtoperations ("pinMode:N") whenpinModeModesis absent. The 16 tests on local copies are replaced by 10 tests that renderParserOutputwith legacy records and assert the displayed mode,UNKNOWNfor invalid/malformed operations, the conflict marker, that onlypinModeoperations count, and thatpinModeModestakes precedence. Breaking the fallback regex inparser-output.tsxfails 8 tests; the file is restored.S7776: not a localArray→Set. The UNO PWM pin list was defined three times (usePinPollingEngine.tsas an array,parser-output.tsxandshared/parsers/hardware-compatibility-parser.tsas sets) and written out a fourth time in theanalogWritewarning text.UNO_PWM_PINSandisUnoPwmPin()now live inshared/utils/arduino-utils.ts(it imports types only, no cycles). Iteration order is unchanged and the warning text is derived from the same list and stays byte-identical (existing tests assert it). New tests cover every UNO pin number and the registry's~marker.Verification
use-pin-polling-engine,parser-output,static-io-parser-messages,code-parser).tests/core/sandbox-stress.test.ts(integration-toolchain,RUN_HEAVY_TESTS=1, the two tests with changed assertions),tests/server/services/serial-backpressure.test.ts(integration-docker, 4 tests),tests/server/load-suite.test.ts(load, the scalability test). All passed.npm run check,npm run check:docs, ESLint over the whole tree,npm run build, and the full./run-tests.sh(static analysis, knip, unit, toolchain integration, Docker, Playwright E2E, production build, security audit, Sonar gate with 0 violations); pre-push hook.Left as is
typescript:S5976intests/client/serial-monitor.ui.test.tsx:363(see above).expect(startHeartbeatLogs.length).toBe(intests/server/telemetry-heartbeat-integration.test.tshas the same pattern but is not reported by Sonar; not touched.npm run lintfails on this machine only because of git-ignored files in.tutor-quality-output/(unrelated to the repository content); with that folder ignored, ESLint is clean.Based on current
main; independent of #250 (it touches no shared files).🤖 Generated with Claude Code