Skip to content

feat(analyser): add NetEvolve.Arguments.Analyser project#724

Merged
samtrion merged 7 commits into
mainfrom
feature/analyser
Jul 23, 2026
Merged

feat(analyser): add NetEvolve.Arguments.Analyser project#724
samtrion merged 7 commits into
mainfrom
feature/analyser

Conversation

@samtrion

Copy link
Copy Markdown
Contributor

Summary

  • Add a new Roslyn analyzer + code-fix package, NetEvolve.Arguments.Analyser, with 9 rules (NEA0001-NEA0009) that promote NetEvolve.Arguments throw-helper usage across every supported target framework.
  • Rules NEA0001/NEA0002/NEA0003/NEA0005 mirror the built-in CA1510/CA1511/CA1512/CA1513 analyzers, but stay active on frameworks that predate the real BCL members (.NET Standard 2.0, .NET Framework 4.7.2+), and automatically go silent once the compilation already exposes the real member, so there's no duplicate diagnostics on modern TFMs.
  • Rules NEA0004, NEA0006-NEA0009 cover NetEvolve.Arguments-only throw-helpers that have no CA equivalent (ThrowIfDefault, string-length/collection-count comparisons, ThrowIfContainsWhiteSpace, ThrowIfEmptyGuid).
  • Added per-rule documentation under docs/analysers/NEA0001.md-NEA0009.md.
  • Wired the analyzer into NetEvolve.Arguments.csproj itself (as an Analyzer-only ProjectReference) for dogfooding.
  • New test project NetEvolve.Arguments.Analyser.Tests.Unit with a hand-rolled CompilationWithAnalyzers/AdhocWorkspace harness (no official TUnit-based Roslyn testing package exists), covering all 9 rules plus the built-in-analyzer suppression gate.

Not covered (documented in the README)

A few throw-helpers don't have a rule because their manual equivalents can be written in too many syntactically different ways to detect reliably:

  • ArgumentException.ThrowIfNullOrEmpty for collections
  • ArgumentException.ThrowIfContainsDuplicates
  • ArgumentOutOfRangeException.ThrowIfInPast/ThrowIfInFuture

Test plan

  • dotnet build Arguments.slnx — 0 errors, 0 warnings
  • dotnet test --solution Arguments.slnx — 1673/1673 passing across all target frameworks (net472/net48/net481/net6.0-net10.0/netstandard2.0 for the library, net10.0 for the analyzer tests)

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • state:ready for merge

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fc2ebc38-4fa4-4535-9d37-88112f79047d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.81524% with 135 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.42%. Comparing base (0177ae6) to head (c02c9db).

Files with missing lines Patch % Lines
src/NetEvolve.Arguments.Analyser/SyntaxHelpers.cs 76.08% 16 Missing and 17 partials ⚠️
...alyser/ThrowIfContainsWhiteSpaceCodeFixProvider.cs 82.60% 5 Missing and 3 partials ⚠️
....Arguments.Analyser/ThrowIfCountCodeFixProvider.cs 85.18% 5 Missing and 3 partials ⚠️
...rguments.Analyser/ThrowIfDefaultCodeFixProvider.cs 81.39% 5 Missing and 3 partials ⚠️
...guments.Analyser/ThrowIfDisposedCodeFixProvider.cs 82.22% 5 Missing and 3 partials ⚠️
...uments.Analyser/ThrowIfEmptyGuidCodeFixProvider.cs 81.39% 5 Missing and 3 partials ⚠️
...Arguments.Analyser/ThrowIfLengthCodeFixProvider.cs 85.18% 5 Missing and 3 partials ⚠️
...e.Arguments.Analyser/ThrowIfNullCodeFixProvider.cs 88.40% 5 Missing and 3 partials ⚠️
...ents.Analyser/ThrowIfNullOrEmptyCodeFixProvider.cs 83.33% 5 Missing and 3 partials ⚠️
...ments.Analyser/ThrowIfOutOfRangeCodeFixProvider.cs 85.71% 5 Missing and 3 partials ⚠️
... and 9 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #724      +/-   ##
==========================================
+ Coverage   77.94%   86.42%   +8.48%     
==========================================
  Files          13       34      +21     
  Lines         340     1547    +1207     
  Branches       92      255     +163     
==========================================
+ Hits          265     1337    +1072     
- Misses         57      133      +76     
- Partials       18       77      +59     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

samtrion added 6 commits July 23, 2026 17:10
Add a Roslyn analyzer and code-fix package (NEA0001-NEA0009) that
promotes NetEvolve.Arguments throw-helper usage on every supported
target framework, including those that predate the built-in
CA1510/CA1511/CA1512/CA1513 analyzers.

- NEA0001: ArgumentNullException.ThrowIfNull (mirrors CA1510)
- NEA0002: ArgumentException.ThrowIfNullOrEmpty/ThrowIfNullOrWhiteSpace (mirrors CA1511)
- NEA0003: ArgumentOutOfRangeException throw helpers, incl. combined-range ThrowIfOutOfRange (mirrors CA1512)
- NEA0004: ArgumentException.ThrowIfDefault
- NEA0005: ObjectDisposedException.ThrowIf (mirrors CA1513)
- NEA0006: ArgumentException string-length throw helpers
- NEA0007: ArgumentException collection-count throw helpers
- NEA0008: ArgumentException.ThrowIfContainsWhiteSpace
- NEA0009: ArgumentException.ThrowIfEmptyGuid

Rules mirroring a built-in CA rule stay silent once the compilation
already exposes the real BCL member, avoiding duplicate diagnostics.
Wired the analyzer into NetEvolve.Arguments itself for dogfooding, and
added per-rule documentation under docs/analysers.
Fix the Release-configuration build failures surfaced by CI:
- Restore the exact unpadded pipe-table format AnalyzerReleases.*.md
  needs for RS2007 (SonarAnalyzer/editor auto-formatting had reflowed
  the tables into padded Markdown, which the release-tracking parser
  rejects).
- Reword a comment that SonarAnalyzer's S125 misidentified as
  commented-out code.
- Replace two nested ternaries flagged by S3358 with explicit
  if/else chains.
Add summary documentation (public and private members alike) across
the analyser package's source files: descriptors, syntax helpers, and
every analyzer/code-fix pair.

test(analyser): broaden negative-path coverage

Add negative-path tests for each rule (else clause present, wrong
exception type, custom-message constructor, unrecognized condition
shapes, combined-range mismatches) plus a positive case for the
literal-paramName branch. Consolidated related negative cases into
parametrized [Arguments] tests instead of one method per case.

Raises analyser-project coverage from 84.3%/59.7% to 89.1%/73.3%
(line/branch).
Add tests for parenthesized conditions, qualified ReferenceEquals,
null != argument (both polarities), zero-argument/mismatched-nameof
exception constructors, rejected coalesce shapes (wrong exception
type, custom message), and a non-literal ArgumentOutOfRangeException
bound.
ArgumentException(string? message, string? paramName) takes the
message first and the parameter name second (the reverse of
ArgumentNullException). Two tests had the arguments swapped.
Every rule's Analyze method repeated the same else-check /
single-throw / exception-type guard chain. Extract it into
SyntaxHelpers.TryGetThrownException and reuse it across all 9
analyzers, and split ThrowIfOutOfRangeAnalyzer's combined-range
detection into its own method.

Addresses CodeFactor's cyclomatic-complexity findings on
ThrowIfOutOfRangeAnalyzer.Analyze/TryGetComparison,
ThrowIfEmptyGuidAnalyzer.Analyze, ThrowIfNullAnalyzer.Analyze, and
ThrowIfDefaultAnalyzer.Analyze, while also removing duplicated logic
across the other analyzers.
@samtrion
samtrion merged commit 0b37f41 into main Jul 23, 2026
13 of 14 checks passed
@samtrion
samtrion deleted the feature/analyser branch July 23, 2026 17:59
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.

1 participant