Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix: add assertion analyzers for common mistakes (prefer IsNull, IsTrue/IsFalse) - #4944

#4944
Merged
thomhurst merged 1 commit into
mainthomhurst/TUnit:mainfrom
fix/assertion-analyzers-v2thomhurst/TUnit:fix/assertion-analyzers-v2Copy head branch name to clipboard
Feb 19, 2026
Merged

fix: add assertion analyzers for common mistakes (prefer IsNull, IsTrue/IsFalse)#4944
thomhurst merged 1 commit into
mainthomhurst/TUnit:mainfrom
fix/assertion-analyzers-v2thomhurst/TUnit:fix/assertion-analyzers-v2Copy head branch name to clipboard

Conversation

@thomhurst

Copy link
Copy Markdown
Owner

Closes #4874. Adds TUnitAssertions0014 and TUnitAssertions0015. 56/56 tests passing.

@claude

claude Bot commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

The two new Roslyn analyzers (PreferIsNullAnalyzer / TUnitAssertions0014 and PreferIsTrueOrIsFalseAnalyzer / TUnitAssertions0015) are well-implemented:

  • Correct use of Roslyn Operations API — Using IInvocationOperation and related operation types is more robust than syntax-based analysis, correctly handling implicit conversions, default values, and constant folding.
  • Argument lookup by parameter name (a.Parameter?.Name == "expected") correctly handles extension method receivers vs. regular arguments.
  • Null detection covers the important cases: direct null literals, constant values that are null, IConversionOperation wrapping null, and IDefaultValueOperation on reference types.
  • Boolean detection similarly covers literals, constant values, and conversions.
  • Diagnostic message format is consistent — TUnitAssertions0014 has no placeholders, TUnitAssertions0015 correctly passes suggestedMethod and literalText matching the {0}/{1} placeholders in the resource string.
  • Tests cover both positive (diagnostic raised) and negative (no diagnostic) cases for all relevant scenarios.
  • CLAUDE.md rules — All critical rules are either explicitly exempted for analyzer changes (Dual-Mode, Snapshot Testing) or are not implicated (VSTest, AOT, async blocking).

Add two new analyzer rules to TUnit.Assertions.Analyzers:

- TUnitAssertions0014: Prefer IsNull() over IsEqualTo(null) for clearer
  intent and better error messages
- TUnitAssertions0015: Prefer IsTrue()/IsFalse() over IsEqualTo(true/false)
  for clearer intent and better error messages

Both rules are Warning severity and include full test coverage.

Closes #4874
@thomhurst
thomhurst force-pushed the fix/assertion-analyzers-v2 branch from 484573c to 09cb81a Compare February 19, 2026 11:46
@thomhurst
thomhurst merged commit 51dc3a6 into main Feb 19, 2026
13 of 14 checks passed
@thomhurst
thomhurst deleted the fix/assertion-analyzers-v2 branch February 19, 2026 13:49
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.

fix: assertion analyzers missing rules for common mistakes

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.