fix: resolve CodeQL warnings across Core and test projects#329
fix: resolve CodeQL warnings across Core and test projects#329piotrzajac merged 4 commits intomasterfrom
Conversation
- Combine nested if statements in IgnoreVirtualMembersSpecimenBuilder - Add ToString() override to AbstractTestClass in AutoDataAdapterAttributeTests - Use object instead of var to fix incomparable-types Equals in ValuesRequestTests - Remove redundant GetHashCode() call on int in ValuesRequestTests - Refactor CustomizeFixture foreach to use Select projection in AutoDataAdapterAttribute - Replace as+Assert.NotNull with Assert.IsType<T> in Assert section in CustomizeWithAttributeTests and AutoDataAttributeProviderTests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 33 minutes and 53 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR addresses CodeQL warnings by applying seven specific code-quality fixes: refactoring collapsible conditional statements into single expressions, adding a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Qodana Community for .NETAnalyzed project: It seems all right 👌 No new problems were found according to the checks applied View the detailed Qodana reportTo be able to view the detailed Qodana report, you can either:
To get - name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2025.3.2
with:
upload-result: trueContact Qodana teamContact us at qodana-support@jetbrains.com
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #329 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 39 39
Lines 421 419 -2
Branches 55 53 -2
=========================================
- Hits 421 419 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/Objectivity.AutoFixture.XUnit2.Core.Tests/Providers/AutoDataAttributeProviderTests.cs (1)
22-26: Redundantascast — passGetAttribute(...)directly toAssert.IsType<T>.With the new
Assert.IsType<AutoDataAdapterAttribute>assertion, the precedingascast no longer serves a purpose. Removing it also improves the failure message: on a type mismatch,Assert.IsType<T>would report the actual runtime type instead ofnull(which is what theascast would produce on mismatch today).♻️ Proposed cleanup
// Act - var dataAttribute = provider.GetAttribute(fixture) as AutoDataAdapterAttribute; + var dataAttribute = provider.GetAttribute(fixture); // Assert var typed = Assert.IsType<AutoDataAdapterAttribute>(dataAttribute); Assert.Equal(fixture, typed.AdaptedFixture);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Objectivity.AutoFixture.XUnit2.Core.Tests/Providers/AutoDataAttributeProviderTests.cs` around lines 22 - 26, Remove the redundant "as" cast when calling GetAttribute in AutoDataAttributeProviderTests: call Assert.IsType<AutoDataAdapterAttribute>(provider.GetAttribute(fixture)) directly so Assert.IsType can report the actual runtime type on failure; update the test around GetAttribute, AutoDataAdapterAttribute and the typed variable accordingly (no prior "as" cast).src/Objectivity.AutoFixture.XUnit2.Core.Tests/Attributes/CustomizeWithAttributeTests.cs (1)
132-138: Redundantascast in both refactored assertions.Same observation as in
AutoDataAttributeProviderTests:Assert.IsType<ArgumentsDiscoveryCustomization>(...)already enforces the type, so theas ArgumentsDiscoveryCustomizationin the Act sections is now dead narrowing. Removing it yields a more informative failure message (actual runtime type vs.null).♻️ Proposed cleanup (apply to both tests)
// Act - var customization = customizeAttribute.GetCustomization(parameter) as ArgumentsDiscoveryCustomization; + var customization = customizeAttribute.GetCustomization(parameter); // Assert var typed = Assert.IsType<ArgumentsDiscoveryCustomization>(customization);Also applies to: 153-158
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Objectivity.AutoFixture.XUnit2.Core.Tests/Attributes/CustomizeWithAttributeTests.cs` around lines 132 - 138, Remove the redundant "as ArgumentsDiscoveryCustomization" cast when calling customizeAttribute.GetCustomization(parameter) in CustomizeWithAttributeTests; instead capture the raw result (var customization = customizeAttribute.GetCustomization(parameter)) and let Assert.IsType<ArgumentsDiscoveryCustomization>(customization) return and assign the typed value (var typed = Assert.IsType<ArgumentsDiscoveryCustomization>(customization)); apply the same removal/fix for the second occurrence referenced around the later assertions (the block at 153-158).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@src/Objectivity.AutoFixture.XUnit2.Core.Tests/Attributes/CustomizeWithAttributeTests.cs`:
- Around line 132-138: Remove the redundant "as ArgumentsDiscoveryCustomization"
cast when calling customizeAttribute.GetCustomization(parameter) in
CustomizeWithAttributeTests; instead capture the raw result (var customization =
customizeAttribute.GetCustomization(parameter)) and let
Assert.IsType<ArgumentsDiscoveryCustomization>(customization) return and assign
the typed value (var typed =
Assert.IsType<ArgumentsDiscoveryCustomization>(customization)); apply the same
removal/fix for the second occurrence referenced around the later assertions
(the block at 153-158).
In
`@src/Objectivity.AutoFixture.XUnit2.Core.Tests/Providers/AutoDataAttributeProviderTests.cs`:
- Around line 22-26: Remove the redundant "as" cast when calling GetAttribute in
AutoDataAttributeProviderTests: call
Assert.IsType<AutoDataAdapterAttribute>(provider.GetAttribute(fixture)) directly
so Assert.IsType can report the actual runtime type on failure; update the test
around GetAttribute, AutoDataAdapterAttribute and the typed variable accordingly
(no prior "as" cast).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 96152a61-f0ea-4aa8-9524-a8db6584fb7d
📒 Files selected for processing (7)
.backlog/tasks/task-16 - Fix-CodeQL-warnings.mdsrc/Objectivity.AutoFixture.XUnit2.Core.Tests/Attributes/AutoDataAdapterAttributeTests.cssrc/Objectivity.AutoFixture.XUnit2.Core.Tests/Attributes/CustomizeWithAttributeTests.cssrc/Objectivity.AutoFixture.XUnit2.Core.Tests/Providers/AutoDataAttributeProviderTests.cssrc/Objectivity.AutoFixture.XUnit2.Core.Tests/Requests/ValuesRequestTests.cssrc/Objectivity.AutoFixture.XUnit2.Core/Attributes/AutoDataAdapterAttribute.cssrc/Objectivity.AutoFixture.XUnit2.Core/SpecimenBuilders/IgnoreVirtualMembersSpecimenBuilder.cs
…line 203 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
ifstatements inIgnoreVirtualMembersSpecimenBuilderToString()override toAbstractTestClassto fix defaultObject.ToString()warningobjectinstead ofvarinValuesRequestTeststo resolve incomparable-typesEqualswarningGetHashCode()call onintinValuesRequestTestsCustomizeFixtureforeachto use.Select()projection inAutoDataAdapterAttributeas+Assert.NotNullwithAssert.IsType<T>in Assert section inCustomizeWithAttributeTestsandAutoDataAttributeProviderTestsSummary by CodeRabbit
Bug Fixes
Chores
Test plan
🤖 Generated with Claude Code