File tree Expand file tree Collapse file tree 3 files changed +20
-17
lines changed
FluentAssertions.Analyzers.Tests
FluentAssertions.Analyzers Expand file tree Collapse file tree 3 files changed +20
-17
lines changed Original file line number Diff line number Diff line change 7
7
</PropertyGroup >
8
8
9
9
<ItemGroup >
10
- <PackageReference Include =" FluentAssertions" Version =" 5.1.1 " />
11
- <PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" 15.5.0 " />
12
- <PackageReference Include =" MSTest.TestAdapter" Version =" 1.2.0 " />
13
- <PackageReference Include =" MSTest.TestFramework" Version =" 1.2.0 " />
10
+ <PackageReference Include =" FluentAssertions" Version =" 5.3.2 " />
11
+ <PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" 15.7.2 " />
12
+ <PackageReference Include =" MSTest.TestAdapter" Version =" 1.3.1 " />
13
+ <PackageReference Include =" MSTest.TestFramework" Version =" 1.3.1 " />
14
14
</ItemGroup >
15
15
16
16
<ItemGroup >
Original file line number Diff line number Diff line change 1
- <Project Sdk =" Microsoft.NET.Sdk" >
1
+ <Project Sdk =" Microsoft.NET.Sdk" >
2
2
3
3
<PropertyGroup >
4
4
<TargetFramework >netstandard1.3</TargetFramework >
5
5
<RootNamespace >FluentAssertions.Analyzers</RootNamespace >
6
6
</PropertyGroup >
7
7
8
8
<ItemGroup >
9
- <PackageReference Include =" Microsoft.CodeAnalysis.CSharp" Version =" 2.6.1" />
10
- <PackageReference Include =" Microsoft.CodeAnalysis.CSharp.Workspaces" Version =" 2.6.1" />
9
+ <PackageReference Include =" Microsoft.CodeAnalysis.CSharp.Workspaces" Version =" 2.8.2" />
11
10
<PackageReference Include =" Microsoft.Composition" Version =" 1.0.31" />
12
11
</ItemGroup >
13
12
Original file line number Diff line number Diff line change @@ -62,21 +62,25 @@ protected virtual Diagnostic AnalyzeExpression(ExpressionSyntax expression)
62
62
63
63
private class ConditionalAccessExpressionVisitor : CSharpSyntaxWalker
64
64
{
65
- public bool CodeSmells { get ; private set ; }
65
+ private bool _foundConditionalAccess ;
66
+ private bool _foundShouldMethod ;
67
+
68
+ public bool CodeSmells => _foundShouldMethod && _foundConditionalAccess ;
66
69
public Location ConditionalAccess { get ; private set ; }
67
70
68
71
public override void VisitConditionalAccessExpression ( ConditionalAccessExpressionSyntax node )
69
72
{
70
- if ( CodeSmells ) return ;
71
-
72
- CodeSmells = node . WhenNotNull is InvocationExpressionSyntax invocation
73
- && invocation . Expression is MemberAccessExpressionSyntax memberAccess && memberAccess . IsKind ( SyntaxKind . SimpleMemberAccessExpression )
74
- && memberAccess . Expression is InvocationExpressionSyntax shouldInvocation
75
- && shouldInvocation . Expression is MemberBindingExpressionSyntax memberBinding
76
- && memberBinding . Name . Identifier . ValueText == "Should" ;
77
- if ( CodeSmells )
73
+ if ( ! _foundConditionalAccess )
74
+ {
75
+ _foundConditionalAccess = true ;
76
+ }
77
+ base . VisitConditionalAccessExpression ( node ) ;
78
+ }
79
+ public override void VisitIdentifierName ( IdentifierNameSyntax node )
80
+ {
81
+ if ( _foundConditionalAccess && node . Identifier . ValueText == "Should" )
78
82
{
79
- ConditionalAccess = node . GetLocation ( ) ;
83
+ _foundShouldMethod = true ;
80
84
}
81
85
}
82
86
}
You can’t perform that action at this time.
0 commit comments