Add a local SonarCloud check; simplify AdjustForContrast; cover PatternValidationRule - #162
Merged
Merged
Conversation
…t PatternValidationRule Local Sonar reproduction (ported from KtsuBuild): dotnet build -p:CustomBeforeMicrosoftCommonProps=$PWD/.sonarlint/sonar-local.props CI injects the Sonar analyzers via the scanner, so a plain build never runs them and findings only surface after a push - a ~10 minute round trip per attempt, which this session spent a lot of time on. Documented in CLAUDE.md including the limitation that it currently only reaches Semantics.SourceGenerators: that project declares its SDK with the <Project Sdk="..."> attribute form, and CustomBeforeMicrosoftCommonProps does not reach the ktsu.Sdk projects that use <Sdk Name="..." /> elements. S3776 - AdjustForContrast was at complexity 19: - The WCAG thresholds were spelled out twice, as a switch here and as a pair of ternaries in AccessibilityLevelAgainst. Both now call RequiredContrast. - The binary search had a four-way branch. The interval always shrinks toward the end satisfying the requirement, and when darkening the roles simply swap, so it collapses to "did the midpoint land on the goLighter side". PatternValidationRule had no tests at all, which is what failed the coverage gate on #161 and matters more now that it carries a match timeout. Added six, including one proving the catastrophic-backtracking case ("^(a+)+$" against a non-matching run of 40 a s) raises RegexMatchTimeoutException instead of hanging - so the S6444 fix from #161 is now actually verified rather than assumed. Build clean on all TFMs, 1095/1095 tests pass.
|
This was referenced Aug 14, 2026
Damon3000s
pushed a commit
to Damon3000s/Semantics
that referenced
this pull request
Aug 16, 2026
All 16 S1192 findings in Semantics.SourceGenerators, verified cleared with the local Sonar check added in ktsu-dev#162 - the whole rule is now clean in that project. The generators built C# by repeating bare string literals: "public" 45 times, "static" 28, "/// <summary>" and "/// </summary>" 26 each, plus the "value" and "right" parameter names, the diagnostic category, and a 150 character CA2225 SuppressMessage attribute spelled out four times. Collected into an internal Emit class, so a typo in a keyword or a documentation delimiter is now a compile error rather than malformed generated source. 141 literal replacements across 8 generator files. Generated output is byte-identical - the constants carry the same values - verified by zero drift under Semantics.Quantities/Generated. Build clean on all TFMs, 1095/1095 tests pass.
Damon3000s
pushed a commit
to Damon3000s/Semantics
that referenced
this pull request
Aug 16, 2026
Added S1172 to .sonarlint/sonar-local.globalconfig first - the analyzer package ships it disabled, so the local check added in ktsu-dev#162 was not seeing it even though CI reports it. It now surfaces locally like the rest. Removed, with their call sites updated: - EmitOverloadType(typeFormMap) - EmitVectorOverloadType(dim) - EmitVectorCrossDimOperators(ownerFullType, components) EmitVectorOverloadType computes its own components array from dims, which is why the caller-supplied one was redundant. Verified with the local check: S1172 in Semantics.SourceGenerators is now clean. Generated output byte-identical, no drift. Build clean on all TFMs, 1095/1095 tests pass.
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.



Three things: a workflow fix, one
S3776refactor, and closing the coverage gap that failed #161's gate.A local SonarCloud check
CI injects the Sonar analyzers via the scanner, so a plain
dotnet buildnever runs them — findings only surface after a push, a ~10 minute round trip per attempt. This session spent a lot of time on exactly that loop. Ported the opt-in from KtsuBuild:dotnet build -p:CustomBeforeMicrosoftCommonProps=$PWD/.sonarlint/sonar-local.props.sonarlint/sonar-local.globalconfigraises the rules CI reports that the analyzer package ships disabled, and silences the ones CI's profile does not report, so a clean local run means a clean CI run. Nothing imports it automatically — normal builds, CI and packaging are unaffected. Documented inCLAUDE.md.Even limited to one project it is useful:
Semantics.SourceGeneratorsholds 7 of the 9 remainingS3776findings and most of the remainingS1192.S3776 —
AdjustForContrast(complexity 19)Two changes, both of which also remove duplication:
switchhere and a pair of ternaries inAccessibilityLevelAgainst. Both now call a sharedRequiredContrast(level, largeText).Coverage —
PatternValidationRuleThis is what failed #161's
new_coveragecondition: the class had no tests at all, which matters more now that it carries a regex match timeout. Added six, including one that proves the hardening works rather than assuming it:Without the timeout added in #161 that call does not finish in any practical time. So the
S6444fix is now verified, not asserted.Verification
dotnet build— 0 errors, 0 warnings, all target frameworksdotnet test— 1095/1095 passRemaining — ~48
S3776×7 (all inSemantics.SourceGenerators, now locally checkable —QuantitiesGeneratorhas two at complexity 42 and 43,DimensionsMetadataone at 41),S1133×10,S1192×15,S4136×8 inSemanticString.cs,S1172×4,S3267×4,S2342×2,S4144×1.