File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed
FluentAssertions.Analyzers.Tests/Tips
FluentAssertions.Analyzers/Utilities Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,22 @@ public static void Main() { }
9191 DiagnosticVerifier . VerifyCSharpDiagnosticUsingAllAnalyzers ( source ) ;
9292 }
9393
94+ [ TestMethod ]
95+ [ Implemented ( Reason = "https://github.com/fluentassertions/fluentassertions.analyzers/issues/58" ) ]
96+ public void StaticWithNameof_ShouldNotThrow ( )
97+ {
98+ const string source = @"public class TestClass
99+ {
100+ private static string StaticResult { get; set; }
101+
102+ public static void Main()
103+ {
104+ StaticResult = nameof(Main);
105+ }
106+ }" ;
107+ DiagnosticVerifier . VerifyCSharpDiagnosticUsingAllAnalyzers ( source ) ;
108+ }
109+
94110 [ TestMethod ]
95111 [ Implemented ( Reason = "https://github.com/fluentassertions/fluentassertions.analyzers/issues/49" ) ]
96112 public void WritingToConsole_ShouldNotThrow ( )
Original file line number Diff line number Diff line change @@ -53,11 +53,17 @@ public static string ExtractVariabeName(InvocationExpressionSyntax invocation)
5353
5454 private bool IsVariable ( IdentifierNameSyntax node )
5555 {
56- // TODO: cleanup
57- if ( _semanticModel == null ) return true ;
56+ if ( _semanticModel != null )
57+ {
58+ SymbolInfo info = _semanticModel . GetSymbolInfo ( node ) ;
59+ if ( info . Symbol == null ||
60+ info . Symbol . Kind == SymbolKind . Method ||
61+ info . Symbol . IsStatic )
62+ {
63+ return false ;
64+ }
65+ }
5866
59- var info = _semanticModel . GetSymbolInfo ( node ) ;
60- if ( info . Symbol . Kind == SymbolKind . Method || info . Symbol . IsStatic ) return false ;
6167 return true ;
6268 }
6369 }
You can’t perform that action at this time.
0 commit comments