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 77 </PropertyGroup >
88
99 <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 " />
1414 </ItemGroup >
1515
1616 <ItemGroup >
Original file line number Diff line number Diff line change 1- <Project Sdk =" Microsoft.NET.Sdk" >
1+ <Project Sdk =" Microsoft.NET.Sdk" >
22
33 <PropertyGroup >
44 <TargetFramework >netstandard1.3</TargetFramework >
55 <RootNamespace >FluentAssertions.Analyzers</RootNamespace >
66 </PropertyGroup >
77
88 <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" />
1110 <PackageReference Include =" Microsoft.Composition" Version =" 1.0.31" />
1211 </ItemGroup >
1312
Original file line number Diff line number Diff line change @@ -62,21 +62,25 @@ protected virtual Diagnostic AnalyzeExpression(ExpressionSyntax expression)
6262
6363 private class ConditionalAccessExpressionVisitor : CSharpSyntaxWalker
6464 {
65- public bool CodeSmells { get ; private set ; }
65+ private bool _foundConditionalAccess ;
66+ private bool _foundShouldMethod ;
67+
68+ public bool CodeSmells => _foundShouldMethod && _foundConditionalAccess ;
6669 public Location ConditionalAccess { get ; private set ; }
6770
6871 public override void VisitConditionalAccessExpression ( ConditionalAccessExpressionSyntax node )
6972 {
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" )
7882 {
79- ConditionalAccess = node . GetLocation ( ) ;
83+ _foundShouldMethod = true ;
8084 }
8185 }
8286 }
You can’t perform that action at this time.
0 commit comments