Update ExplicitNumberDeclarationAnalyzer to handle out var and foreach#385
Update ExplicitNumberDeclarationAnalyzer to handle out var and foreach#385google-labs-jules[bot] wants to merge 1 commit into
Conversation
- Register SyntaxNodeAction for DeclarationExpression and ForEachStatement. - Handle SingleVariableDesignation and ParenthesizedVariableDesignation (for deconstruction) in DeclarationExpressions. - Refactor reporting logic into a common helper method. - Add comprehensive test cases covering out var, foreach, and tuple deconstruction.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Walkthrough
ChangesSMA8001 Analyzer Extension for Additional var Patterns
Estimated code review effort3 (Moderate) | ~20 minutes Finishing TouchesGenerate unit tests (beta)
Simplify code
|
There was a problem hiding this comment.
Nitpick comments (1)
test/AnalyzerTests/SMA8001_ExplicitNumberDeclarationAnalyzerTests.cs (1)
159-196: 💤 Low valueConsider adding test coverage for edge cases.
The test comprehensively covers the main scenarios. Consider adding optional test cases for:
- Deeply nested tuple deconstruction:
var ((a, b), c) = ((1, 2), 3);- Discards in tuple deconstruction:
var (_, b) = (1, 2);(should only flagbif it's a primitive number)These edge cases would verify that the recursive tuple handling and null symbol checks work correctly in all scenarios.
Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/AnalyzerTests/SMA8001_ExplicitNumberDeclarationAnalyzerTests.cs` around lines 159 - 196, The test method SMA8001_Violation_OtherVarDeclarationsWithPrimitiveNumbers lacks coverage for edge cases involving deeply nested tuple deconstruction and discard patterns. Add test cases within the test string variable that include deeply nested tuple deconstruction syntax (such as var ((a, b), c) = ((1, 2), 3);) and discard patterns in tuple deconstruction (such as var (_, b) = (1, 2);), then add the corresponding expected diagnostic assertions to verify that the analyzer correctly handles recursive tuple handling and only flags non-discard variables when they involve primitive numbers.
Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@test/AnalyzerTests/SMA8001_ExplicitNumberDeclarationAnalyzerTests.cs`:
- Around line 159-196: The test method
SMA8001_Violation_OtherVarDeclarationsWithPrimitiveNumbers lacks coverage for
edge cases involving deeply nested tuple deconstruction and discard patterns.
Add test cases within the test string variable that include deeply nested tuple
deconstruction syntax (such as var ((a, b), c) = ((1, 2), 3);) and discard
patterns in tuple deconstruction (such as var (_, b) = (1, 2);), then add the
corresponding expected diagnostic assertions to verify that the analyzer
correctly handles recursive tuple handling and only flags non-discard variables
when they involve primitive numbers.
Review details
Additional comments (7)
src/analysis/Analyzers/ExplicitNumberDeclarationAnalyzer.cs (6)
34-35: LGTM!
38-55: LGTM!
80-93: LGTM!
111-120: LGTM!
57-78: No issues found. The project targets C# 9.0 (as configured in the project file), which fully supports theis notpattern used on line 65. The code is compatible and requires no changes.
95-109: No issues found. Foreach with tuple deconstruction is correctly handled through the DeclarationExpression handler. When encounteringforeach (var (x, y) in ...), the syntax tree contains a ForEachVariableStatementSyntax with a Variable property that is a DeclarationExpressionSyntax. This DeclarationExpressionSyntax triggers the AnalyzeDeclarationExpression handler, which detects the ParenthesizedVariableDesignationSyntax and delegates to ReportRecursive to recursively report all tuple variables. The test expectations at line 181 align with this behavior and will pass correctly.test/AnalyzerTests/SMA8001_ExplicitNumberDeclarationAnalyzerTests.cs (1)
159-196: LGTM!
c96f7e2 to
7acf9b7
Compare
This PR updates the
ExplicitNumberDeclarationAnalyzer(SMA8001) to correctly identify and warn against the use ofvarfor numeric primitive types in additional contexts. Specifically, it now handles:out vardeclarations (e.g.,TryGetValue(out var value)).foreachloops withvar(e.g.,foreach (var x in collection)).var(e.g.,var (a, b) = ...).foreachloops.The implementation was refactored to share common reporting logic and recursively handle tuple deconstructions. Unit tests have been expanded to verify these new scenarios.
PR created automatically by Jules for task 1733819396258710820 started by @sator-imaging