Skip to content

Take the assertions SonarCloud's analyzer asked for - #149

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/schema-issue-128-gr9is7
Sep 8, 2026
Merged

Take the assertions SonarCloud's analyzer asked for#149
matt-edmondson merged 1 commit into
mainfrom
claude/schema-issue-128-gr9is7

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Follow-up to #148, which merged before this landed on it. The analysis of that PR passed its quality gate but raised nineteen issues; this clears seventeen of them, and one of the remaining two.

The assertions

Seventeen are MSTest suggesting a more specific assertion than the one written, all in the suites #148 added:

Was Now
Assert.AreEqual(0, x.Count) Assert.IsEmpty(x)
Assert.AreEqual(1, x.Length) Assert.HasCount(1, x)
Assert.AreEqual(1, x.Count(pred)) Assert.ContainsSingle(pred, x)
Assert.IsTrue(x.Any(pred)) Assert.Contains(pred, x)
Assert.IsFalse(x.Any(pred)) Assert.DoesNotContain(pred, x)
Assert.IsTrue(x.Count > 0) Assert.IsNotEmpty(x)
Assert.IsTrue(a < b) Assert.IsLessThan(b, a)

Each says on failure what was actually in the collection, where the general form only says that a bool was false.

The one equivalence check keeps its meaning rather than taking the suggested form as offered: Assert.AreSequenceEqual compares in order by default, and the order the diagnostics panel draws its rows in is exactly what the next test is about — so it is asked for SequenceOrder.InAnyOrder, which is what CollectionAssert.AreEquivalent meant. Taking the swap literally would have made EveryIssueGetsARow duplicate ErrorsAreListedBeforeWarnings and fail.

The other two

  • S1192, the duplicated "<none>" literal — fixed. It crossed the analyzer's threshold when the class and array-key pickers had their options marked in Cover the editor's menus, panels and diagnostics list #148, so it is that change's to clean up; it is a constant now.
  • S3776, ButtonTree.ShowTreeItem's cognitive complexity (30 vs. 15) — deliberately left alone. The complexity predates Cover the editor's menus, panels and diagnostics list #148, which only threaded the editor through the signature; Sonar counts the method as new code because that line changed. Reducing it means restructuring the drawing of every tree row, which is not this change's to do — worth its own issue if it is wanted.

Verification

dotnet build clean under the repo's warnings-as-errors analyzers, and the editor suite passes 182/182 on this base. ErrorsAreListedBeforeWarnings passing is what confirms IsLessThan's argument order is the intended direction — had the bound and the value been swapped, that test would fail rather than silently assert the opposite.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pw1CwfGXb6yK6gLdnZYYZK


Generated by Claude Code

Seventeen of the nineteen issues the analysis raised are MSTest suggesting a
more specific assertion than the one written: IsEmpty and HasCount for a
count compared against a literal, Contains and DoesNotContain for an Any
over a predicate, ContainsSingle for a Count of one, IsLessThan for a
comparison inside IsTrue. Each says on failure what was actually in the
collection, where the general form only says that a bool was false.

The equivalence check keeps its meaning rather than taking the suggested
form as offered: AreSequenceEqual defaults to comparing in order, and the
order rows are drawn in is what the next test is about, so it is asked for
InAnyOrder - which is what CollectionAssert.AreEquivalent meant.

The remaining two are a duplicated "<none>" literal, which crossed the
analyzer's threshold when the pickers' options were marked, now a constant;
and the cognitive complexity of ButtonTree.ShowTreeItem, which is left
alone: it is counted as new only because threading the editor through
touched the signature, and it is not this change's to refactor.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pw1CwfGXb6yK6gLdnZYYZK
@sonarqubecloud

sonarqubecloud Bot commented Sep 8, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 9a2f0d6 into main Sep 8, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the claude/schema-issue-128-gr9is7 branch September 8, 2026 10:33
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.

2 participants