-
-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/RCS1031, RCS1208 and RCS1061 #1062
Fix/RCS1031, RCS1208 and RCS1061 #1062
Conversation
src/Common/CSharp/Analysis/ReduceIfNesting/IfLocalVariableAnalysis.cs
Outdated
Show resolved
Hide resolved
src/Common/CSharp/Analysis/ReduceIfNesting/IfLocalVariableAnalysis.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/CSharp/Analysis/RemoveUnnecessaryBracesInSwitchSectionAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/CSharp/Analysis/RemoveUnnecessaryBracesInSwitchSectionAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/Common/CSharp/Analysis/ReduceIfNesting/IfLocalVariableAnalysis.cs
Outdated
Show resolved
Hide resolved
@jamesHargreaves12 I noticed that there multiple small fixes like formatting, trailing whitespace, implicit/explicit type etc. I suggest to run script |
@jamesHargreaves12 I would like to release new version in about one week and I would like to include this PR in the new version. Could you let me know if you will have time to address my comments so the PR can me merged? Thanks. |
src/Common/CSharp/Analysis/ReduceIfNesting/IfLocalVariableAnalysis.cs
Outdated
Show resolved
Hide resolved
src/Common/CSharp/Analysis/ReduceIfNesting/IfLocalVariableAnalysis.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/CSharp/Analysis/PattenMatchingAnalysis/PattenMatchingVariableDeclarationHelper.cs
Outdated
Show resolved
Hide resolved
src/Common/CSharp/Analysis/ReduceIfNesting/IfLocalVariableAnalysis.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/CSharp/Analysis/RemoveUnnecessaryBracesInSwitchSectionAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/Common/CSharp/Analysis/ReduceIfNesting/IfLocalVariableAnalysis.cs
Outdated
Show resolved
Hide resolved
src/Common/CSharp/Analysis/ReduceIfNesting/IfLocalVariableAnalysis.cs
Outdated
Show resolved
Hide resolved
610dc14
to
94323c7
Compare
Co-authored-by: Josef Pihrt <josef@pihrt.net>
This PR extends the local variable check from #1039 to RCS1061 and also checks variables assigned during pattern matching in the case of RCS1031.
Slightly embarrassingly, I didn't check all the ReduceIfNestingAnalysis code paths in #1039 and so I didn't realise that the AnalyzeDataFlow can only handle an argument of type ExpressionSyntax or StatementSyntax. If you pass anything else, it will throw a run time error. This PR solves this issue through the new helper function
IfStatementLocalVariableAnalysis.TryGetOuterScope
which handles the intricacies of this. I have also added a number of new tests at the level of RCS1208 to enforce this behaviour.It is currently not trivial to test the Loop / Switch sections of ReduceIfNestingAnalysis.AnalyzeCore via the analyzer as it passes through ReduceIfNestingOptions.None. However, I manually removed the guard clause on lines 63 and 90 and confirmed that it was working correctly.