Skip to content

Commit 957d47a

Browse files
committed
Add return statement expression to the list
1 parent 156168c commit 957d47a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Creedengo.Core/Analyzers/GCI95.UseIsOperatorInsteadOfAsOperator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public override void Initialize(AnalysisContext context)
2828
SyntaxKind.ConditionalExpression,
2929
SyntaxKind.WhileStatement,
3030
SyntaxKind.DoStatement,
31-
SyntaxKind.ForStatement
31+
SyntaxKind.ForStatement,
32+
SyntaxKind.ReturnStatement
3233
];
3334

3435
foreach (var item in supportSyntaxKinds)
@@ -46,6 +47,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
4647
WhileStatementSyntax whileStatement => whileStatement.Condition,
4748
DoStatementSyntax dowhileStatement => dowhileStatement.Condition,
4849
ConditionalExpressionSyntax conditionalExpression => conditionalExpression.Condition,
50+
ReturnStatementSyntax returnStatement => returnStatement.Expression,
4951
_ => null
5052
};
5153

src/Creedengo.Tests/Tests/GCI95.UseIsOperatorInsteadOfAsOperator.Tests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,27 @@ void TestMethod()
9797
}
9898
""");
9999

100+
101+
[TestMethod]
102+
public Task DoNotUseAsOperatorInsteadOfIsReturnAsync() => VerifyAndFixAsync("""
103+
class TestClass
104+
{
105+
bool TestMethod(string x)
106+
{
107+
return [|x as string|] != null;
108+
}
109+
}
110+
""",
111+
"""
112+
class TestClass
113+
{
114+
bool TestMethod(string x)
115+
{
116+
return x is string;
117+
}
118+
}
119+
""");
120+
100121
[TestMethod]
101122
public Task DoNotUseAsOperatorInsteadOfIsDoWhileLoopAsync() => VerifyAndFixAsync("""
102123
class TestClass

0 commit comments

Comments
 (0)