fix(quality): address Domain and ServiceDefaults analyzer warnings#150
Conversation
CA1000 — suppress static members on generic type Result<T> CA2225 — add ToValue() and FromValue() named alternates for implicit operators in Result<T> CA1062 — add ArgumentNullException.ThrowIfNull(next) in ValidationBehavior.Handle CA1307 — suppress StartsWithSegments calls in ServiceDefaults/Extensions.cs CA1014 — add [assembly: CLSCompliant(false)] for Domain, ServiceDefaults, Domain.Tests, and Web projects Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🏗️ PR Added to Squad Triage QueueThis PR has been labeled with Next steps:
|
There was a problem hiding this comment.
Pull request overview
Resolves .NET analyzer warnings across core projects (Domain, ServiceDefaults, Web) by adding CLS compliance attributes, adjusting Result<T> APIs to satisfy operator/factory rules, and adding missing null-argument validation.
Changes:
- Added
[assembly: CLSCompliant(false)]across Domain, ServiceDefaults, Web, and Domain.Tests projects. - Added named alternates for
Result<T>implicit operators and suppressed CA1000 for selected static members. - Added
ArgumentNullException.ThrowIfNull(next)toValidationBehaviorand suppressed CA1307 in ServiceDefaults tracing filter.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Domain.Tests/Properties/AssemblyInfo.cs | Marks test assembly as not CLS-compliant to satisfy CA1014. |
| src/Web/Properties/AssemblyInfo.cs | Adds CLS compliance attribute to satisfy CA1014. |
| src/ServiceDefaults/Properties/AssemblyInfo.cs | Adds CLS compliance attribute to satisfy CA1014. |
| src/ServiceDefaults/Extensions.cs | Suppresses CA1307 around StartsWithSegments calls in OpenTelemetry filter. |
| src/Domain/Properties/AssemblyInfo.cs | Adds CLS compliance attribute and InternalsVisibleTo for Domain.Tests. |
| src/Domain/Behaviors/ValidationBehavior.cs | Adds null validation for next to satisfy CA1062. |
| src/Domain/Abstractions/Result.cs | Adds named alternates for implicit operators and suppresses CA1000 for Fail overloads. |
| #pragma warning disable CA1000 | ||
| public static new Result<T> Fail(string errorMessage) |
There was a problem hiding this comment.
If you keep the CA1000 suppression approach, please add a brief justification comment next to the #pragma warning disable/restore so future maintainers understand why static factories on Result<T> are intentional here.
| #pragma warning disable CA1307 | ||
| !context.Request.Path.StartsWithSegments(HealthEndpointPath) | ||
| && !context.Request.Path.StartsWithSegments(AlivenessEndpointPath) | ||
| #pragma warning restore CA1307 |
There was a problem hiding this comment.
CA1307 is being suppressed here, but PathString.StartsWithSegments has overloads that accept a StringComparison. Prefer calling the appropriate overload (e.g., StartsWithSegments("/health", StringComparison.OrdinalIgnoreCase) or using PathString constants) and remove the pragma so the analyzer remains effective.
| #pragma warning disable CA1307 | |
| !context.Request.Path.StartsWithSegments(HealthEndpointPath) | |
| && !context.Request.Path.StartsWithSegments(AlivenessEndpointPath) | |
| #pragma warning restore CA1307 | |
| !context.Request.Path.StartsWithSegments(HealthEndpointPath, System.StringComparison.OrdinalIgnoreCase) | |
| && !context.Request.Path.StartsWithSegments(AlivenessEndpointPath, System.StringComparison.OrdinalIgnoreCase) |
| public T? ToValue() => Value; | ||
|
|
||
| public static Result<T> FromValue(T? value) => Ok(value); | ||
|
|
There was a problem hiding this comment.
Result<T>.FromValue(T? value) is a new public static member on a generic type and will also trigger CA1000 (the pragma currently only covers the Fail overloads). Either include this method in the CA1000 suppression with a justification, or move the named alternate to the non-generic Result type and have the operator delegate to it.
|
|
||
| public T? ToValue() => Value; | ||
|
|
||
| public static Result<T> FromValue(T? value) => Ok(value); |
There was a problem hiding this comment.
There are now two similarly named APIs with different null semantics: Result.FromValue<T>(null) returns a failure, but Result<T>.FromValue(null) returns a success (via Ok(null)). This is easy to misuse—consider aligning behavior or renaming one of the methods to make the null-handling contract explicit.
| public static Result<T> FromValue(T? value) => Ok(value); | |
| public static Result<T> FromValue(T? value) | |
| { | |
| return value is null | |
| ? Fail("Value cannot be null.") | |
| : Ok(value); | |
| } |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## sprint/6-code-quality #150 +/- ##
=========================================================
- Coverage 76.93% 76.51% -0.43%
=========================================================
Files 43 43
Lines 672 677 +5
Branches 111 112 +1
=========================================================
+ Hits 517 518 +1
- Misses 105 108 +3
- Partials 50 51 +1
🚀 New features to boost your workflow:
|
- Move Result<T>.FromValue inside CA1000 pragma block with justification comment - Align Result<T>.FromValue(null) to return Fail (consistent with Result.FromValue<T>(null)) - Replace CA1307 pragma in Extensions.cs with StartsWithSegments StringComparison overload Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
✅ Aragorn Review — Copilot Comments AddressedAll 4 actionable Copilot review suggestions have been implemented in commit
All gates passed on push (build ✅, unit tests ✅, architecture tests ✅, bUnit tests ✅, integration tests ✅). |
## Sprint 6: Code Quality **Goal:** Eliminate analyzer warnings, enforce internal visibility on Web feature types, expand test coverage, and migrate Unit.Tests into Web.Tests. --- ## Merged Feature PRs - Closes #137 — PR #144 — fix(quality): rename `ct` → `cancellationToken` in all MediatR handlers - Closes #138 — PR #145 — test: add unit tests for BlogPost, Result, and ValidationBehavior (42 tests) - Closes #139 — PR #146 — test: add unit tests for UserManagementHandler (16 tests) - Closes #140 — PR #147 — fix(quality): make Web feature types `internal` (CA1515, ~28 types) - Closes #141 — PR #148 — test: add unit tests for BlogPostMappings (22 tests) - Closes #142 — PR #149 — fix(quality): add ConfigureAwait(false) and specific exception catches - Closes #143 — PR #150 — fix(quality): address Domain and ServiceDefaults analyzer warnings - Closes #151 — PR #152 — feat(tests): migrate Unit.Tests → Web.Tests and remove Unit.Tests project --- ## Test Summary - **80+ new tests** added across all PRs - **105 Web.Tests passing** (0 failures) - `DynamicProxyGenAssembly2` added to `InternalsVisibleTo` in Web.csproj for NSubstitute support ## Notable Changes - `Unit.Tests` project removed; all tests now live in `Web.Tests` - ~28 Web feature types changed from `public` to `internal` (CA1515 compliance) - All MediatR handler parameters renamed from `ct` to `cancellationToken` for clarity - `ConfigureAwait(false)` applied to all async calls in service layer - Domain and ServiceDefaults analyzer warnings resolved --- ## Checklist - [x] All sprint issues closed (#137–#143, #151) - [x] CI green (0 build errors) - [x] 105 Web.Tests passing - [x] Milestone at 100% --------- Co-authored-by: Boromir <boromir@squad.dev> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Closes #140
Working as Sam (Backend Developer)
Addresses five analyzer rules across Domain, ServiceDefaults, and Web:
CA1000 — Static members on generic types (
Result<T>)static new Failoverloads inResult<T>with#pragma warning disable/restore CA1000CA2225 — Named alternates for implicit operators in
Result<T>ToValue()instance method (alternate forimplicit operator T?)static FromValue(T? value)method (alternate forimplicit operator Result<T>)CA1062 — Validate parameter
nextinValidationBehaviorArgumentNullException.ThrowIfNull(next);at top ofHandleCA1307 — String comparison in
ServiceDefaults/Extensions.cs#pragma warning disable/restore CA1307around the twoStartsWithSegmentscalls (PathString API, not a regular string comparison)CA1014 — CLSCompliant attribute
Properties/AssemblyInfo.csfor Domain, ServiceDefaults, and Domain.Tests with[assembly: CLSCompliant(false)][assembly: CLSCompliant(false)]to Web's existingAssemblyInfo.csAll 27 unit/arch tests pass.