CodeQL 11: chore(tests): replace Returns((T?)null) casts with ReturnsNull()#197
CodeQL 11: chore(tests): replace Returns((T?)null) casts with ReturnsNull()#197rlorenzo wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Bundle ReportBundle size has no change ✅ |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #197 +/- ##
=======================================
Coverage 42.96% 42.96%
=======================================
Files 877 877
Lines 51468 51468
Branches 4802 4802
=======================================
Hits 22113 22113
Misses 28831 28831
Partials 524 524
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
…051) PR-scoped gate flagged line 183 as a new xUnit1051 warning because '.ReturnsNull()' shifted git blame to this commit. The underlying FindAsync(object?[]?) call lacked a CancellationToken arg. Use the overload that accepts both, matched via Arg.Any<CancellationToken>().
Summary
Closes ~19
cs/useless-upcastalerts intest/**by replacing the NSubstitute pattern.Returns((SomeType?)null)with the dedicated.ReturnsNull()extension fromNSubstitute.ReturnsExtensions.Why
The explicit
(T?)nullcast existed because the bare.Returns(null)call is ambiguous between NSubstitute'sReturns<T>(T)andReturns<T>(Func<CallInfo, T>)overloads, but the cast itself trips thecs/useless-upcastrule (CodeQL sees the receiver's return type, so the cast is "redundant from the type system's POV")..ReturnsNull()is the canonical NSubstitute idiom for this case - it disambiguates without a cast and makes the test intent clearer.Files (18)
Each file got a
using NSubstitute.ReturnsExtensions;added.Context
Eleventh in the
CodeQL N:cleanup series. Earlier task #9 had marked these as wontfix-by-design - that was wrong.ReturnsNull()is the correct fix.Test plan
npm run test:backend- 1946 tests passing