Repository navigation
MA0002: treat the xunit assertions that take an IEqualityComparer<T> as ordinal with report_only_non_ordinal - #1625
Merged
Conversation
…al in MA0002's report_only_non_ordinal mode With MA0002.report_only_non_ordinal = true, a call to a method of Xunit.Assert is no longer reported when the overload it lacks takes an IEqualityComparer<string>: Equal, NotEqual, Contains, DoesNotContain and Distinct. xunit compares strings ordinally, in its own string overloads and, for items and collections, through IEquatable<string>, so passing StringComparer.Ordinal to those assertions changes nothing. A method whose missing overload takes an IComparer<string> (InRange, NotInRange) stays reported, as Comparer<string>.Default is culture-sensitive. The tests reference the real xunit v3 and v2 assemblies for the equality assertions. The ordering test uses a stub Xunit.Assert because the overload finder does not detect the real InRange<T> overload today, which is independent of this change. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The implementation and tests cover the requested behavior; only a non-blocking documentation nit remains.
1 open finding
What changed in this PR
Updates MA0002 to treat xUnit equality-comparer assertions as ordinal when report_only_non_ordinal is enabled.
Changes:
- Added xUnit v2/v3 comparer handling.
- Added equality and ordering tests.
- Updated MA0002 documentation.
| File | Summary |
|---|---|
tests/Meziantou.Analyzer.Test/Rules/UseStringComparerAnalyzerTests.cs |
Adds xUnit behavior coverage. |
src/Meziantou.Analyzer/Rules/UseStringComparerAnalyzer.cs |
Handles xUnit assertion comparer overloads. |
docs/Rules/MA0002.md |
Documents the new behavior; includes a minor punctuation nit. |
🧠 Review effort: Lite
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Oct 8, 2026
Closed
Closed
Closed
Closed
Closed
Closed
This was referenced Oct 9, 2026
Merged
IhateTrains
pushed a commit
to ParadoxGameConverters/ImperatorToCK3
that referenced
this pull request
Oct 10, 2026
Updated [Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer) from 3.0.291 to 3.0.296. <details> <summary>Release notes</summary> _Sourced from [Meziantou.Analyzer's releases](https://github.com/meziantou/Meziantou.Analyzer/releases)._ ## 3.0.296 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.296> ## What's Changed * Add tests for non-culture-sensitive string methods by @meziantou in meziantou/Meziantou.Analyzer#1626 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.295...3.0.296 ## 3.0.295 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.295> ## What's Changed * MA0002: treat the xunit assertions that take an IEqualityComparer<T> as ordinal with report_only_non_ordinal by @vencyk in meziantou/Meziantou.Analyzer#1625 ## New Contributors * @vencyk made their first contribution in meziantou/Meziantou.Analyzer#1625 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.294...3.0.295 ## 3.0.294 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.294> ## What's Changed * Do not suggest instance members in static contexts in MA0166/MA0167 by @meziantou in meziantou/Meziantou.Analyzer#1623 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.293...3.0.294 ## 3.0.293 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.293> ## What's Changed * Check for a set instance only before an MA0002 report by @alexander-efremov in meziantou/Meziantou.Analyzer#1622 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.292...3.0.293 ## 3.0.292 NuGet package: <https://www.nuget.org/packages/Meziantou.Analyzer/3.0.292> ## What's Changed * Cache LookupSymbols results in OverloadFinder by @alexander-efremov in meziantou/Meziantou.Analyzer#1621 * chore(deps): update all dependencies to 1.0.179 by @renovate[bot] in meziantou/Meziantou.Analyzer#1618 ## New Contributors * @alexander-efremov made their first contribution in meziantou/Meziantou.Analyzer#1621 **Full Changelog**: meziantou/Meziantou.Analyzer@3.0.291...3.0.292 Commits viewable in [compare view](meziantou/Meziantou.Analyzer@3.0.291...3.0.296). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Oct 10, 2026
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.

With
MA0002.report_only_non_ordinal = true, a call to aXunit.Assertmethod is no longer reported when the overload it lacks takes anIEqualityComparer<string>:Equal,NotEqual,Contains,DoesNotContainandDistinct. This mirrors the existing special case forMeziantou.Framework.Assertions.Assert.Why: xunit compares strings ordinally, in its own
Assert.Equal(string, string)overloads and, for items and collections, throughIEquatable<string>. In a test project with the option on,Assert.Equal(expectedStrings, actualStrings)andAssert.Contains("a", strings)were the only calls left reported, and passingStringComparer.Ordinalto them changes nothing.What stays reported: a method whose missing overload takes an
IComparer<string>(InRange,NotInRange), sinceComparer<string>.Defaultis culture-sensitive. The check is on the comparer kind of the overload, not on method names.Tests: four added to
UseStringComparerAnalyzerTests. The equality assertions are tested against the real xunit v3 and v2 packages (AddXunitV3()/AddXunitV2()). The ordering test uses a stubXunit.Assert, because the overload finder does not detect the real genericInRange<T>overload today; that gap is independent of this change.UseStringComparerAnalyzerTestspasses on Roslyn 5.9 (91 tests) and Roslyn 4.8 (67 tests).dotnet run --project src/DocumentationGeneratorwas run; the only documentation change is the note indocs/Rules/MA0002.md.🤖 Generated with Claude Code