Take the assertions SonarCloud's analyzer asked for - #149
Merged
Conversation
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
|
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.



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:
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.AreSequenceEqualcompares 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 forSequenceOrder.InAnyOrder, which is whatCollectionAssert.AreEquivalentmeant. Taking the swap literally would have madeEveryIssueGetsARowduplicateErrorsAreListedBeforeWarningsand 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 buildclean under the repo's warnings-as-errors analyzers, and the editor suite passes 182/182 on this base.ErrorsAreListedBeforeWarningspassing is what confirmsIsLessThan'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