File tree Expand file tree Collapse file tree 4 files changed +15
-11
lines changed
System.IO.Abstractions.Analyzers.Tests/TestData/CodeFix/DirectoryCodeFix
System.IO.Abstractions.Analyzers Expand file tree Collapse file tree 4 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ namespace SomeNameSpace
1515 {
1616 const string filePath = "C:\\temp";
1717
18- _fileSystem.Directory.Exists(filePath );
18+ new ConfigurationBuilder().SetBasePath( _fileSystem.Directory.GetCurrentDirectory() );
1919 }
2020 }
2121}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ namespace SomeNameSpace
1515 {
1616 const string filePath = "C:\\temp";
1717
18- Directory.Exists(filePath );
18+ new ConfigurationBuilder().SetBasePath( Directory.GetCurrentDirectory() );
1919 }
2020 }
2121}
Original file line number Diff line number Diff line change @@ -46,8 +46,10 @@ protected override void AnalyzeCompilation(CompilationStartAnalysisContext compi
4646
4747 private bool IsTypesEquals ( TypeSyntax type ) => type . NormalizeWhitespace ( ) . ToFullString ( ) == GetFileSystemType ( ) . Name ;
4848
49- private bool IsStaticInvocationStartWith ( InvocationExpressionSyntax invocation ) => invocation . Expression . NormalizeWhitespace ( )
50- . ToFullString ( )
51- . StartsWith ( GetFileSystemType ( ) . Name + "." , StringComparison . CurrentCultureIgnoreCase ) ;
49+ private bool IsStaticInvocationStartWith ( InvocationExpressionSyntax invocation ) =>
50+ invocation . IsKind ( SyntaxKind . InvocationExpression )
51+ && invocation . Expression . NormalizeWhitespace ( )
52+ . ToFullString ( )
53+ . StartsWith ( GetFileSystemType ( ) . Name + "." , StringComparison . CurrentCultureIgnoreCase ) ;
5254 }
5355}
Original file line number Diff line number Diff line change @@ -22,14 +22,16 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
2222 {
2323 var root = await context . Document . GetSyntaxRootAsync ( context . CancellationToken ) . ConfigureAwait ( false ) ;
2424
25- if ( root . FindNode ( context . Span ) . Ancestors ( ) . OfType < ClassDeclarationSyntax > ( ) . Any ( RoslynClassFileSystem . HasFileSystemField ) )
26- {
27- var invocation = root . FindNode ( context . Span ) . FirstAncestorOrSelf < InvocationExpressionSyntax > ( ) ;
25+ var classDeclaration = root . FindNode ( context . Span ) . FirstAncestorOrSelf < ClassDeclarationSyntax > ( ) ;
2826
29- var @class = root . FindNode ( context . Span )
30- . FirstAncestorOrSelf < ClassDeclarationSyntax > ( ) ;
27+ if ( RoslynClassFileSystem . HasFileSystemField ( classDeclaration ) )
28+ {
29+ var invocation = root . FindNode ( context . Span )
30+ . DescendantNodesAndSelf ( )
31+ . OfType < InvocationExpressionSyntax > ( )
32+ . FirstOrDefault ( ) ;
3133
32- var field = RoslynClassFileSystem . GetFileSystemFieldFromClass ( @class ) ;
34+ var field = RoslynClassFileSystem . GetFileSystemFieldFromClass ( classDeclaration ) ;
3335
3436 context . RegisterCodeFix ( new FileSystemInvokeCodeAction ( Title ,
3537 context . Document ,
You can’t perform that action at this time.
0 commit comments