Skip to content

Commit 922010c

Browse files
committed
#7 False positive if in method returned type from System.IO
Now code fix applying from Invocation Expression or Object Creation Expression
1 parent 85c5646 commit 922010c

22 files changed

+49
-296
lines changed

System.IO.Abstractions.Analyzers.Tests/Analyzers/FileServiceInterfaceInjectionAnalyzerTests.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

System.IO.Abstractions.Analyzers.Tests/CodeFixes/FileServiceConstructorInitialCodeFixTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using System.IO.Abstractions.Analyzers.Analyzers;
2+
using System.IO.Abstractions.Analyzers.Analyzers.FileSystemTypeAnalyzers;
33
using System.IO.Abstractions.Analyzers.CodeFixes;
44
using Microsoft.CodeAnalysis;
55
using Roslyn.Testing.CodeFix;
@@ -8,7 +8,7 @@
88
namespace System.IO.Abstractions.Analyzers.Tests.CodeFixes
99
{
1010
public class FileServiceConstructorInitialCodeFixTests :
11-
CSharpCodeFixProviderTest<FileServiceInterfaceInjectionAnalyzer, FileServiceConstructorInitialCodeFix>
11+
CSharpCodeFixProviderTest<PathAnalyzer, FileServiceConstructorInitialCodeFix>
1212
{
1313
[Theory]
1414
[InlineData("BeforeFix.txt", "AfterFix.txt")]

System.IO.Abstractions.Analyzers.Tests/CodeFixes/FileServiceInterfaceInjectionCodeFixTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using System.IO.Abstractions.Analyzers.Analyzers;
2+
using System.IO.Abstractions.Analyzers.Analyzers.FileSystemTypeAnalyzers;
33
using System.IO.Abstractions.Analyzers.CodeFixes;
44
using Microsoft.CodeAnalysis;
55
using Roslyn.Testing.CodeFix;
@@ -8,7 +8,7 @@
88
namespace System.IO.Abstractions.Analyzers.Tests.CodeFixes
99
{
1010
public class FileServiceInterfaceInjectionCodeFixTests :
11-
CSharpCodeFixProviderTest<FileServiceInterfaceInjectionAnalyzer, FileServiceInterfaceInjectionCodeFix>
11+
CSharpCodeFixProviderTest<PathAnalyzer, FileServiceInterfaceInjectionCodeFix>
1212
{
1313
[Theory]
1414
[InlineData("BeforeFix.txt", "AfterFix.txt")]

System.IO.Abstractions.Analyzers.Tests/TestData/Analyzer/FileServiceInterfaceInjectionAnalyzer/Valid.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

System.IO.Abstractions.Analyzers.Tests/TestData/Analyzer/FileServiceInterfaceInjectionAnalyzer/Valid2.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.

System.IO.Abstractions.Analyzers.Tests/TestData/Analyzer/FileServiceInterfaceInjectionAnalyzer/WithOutFileSystem.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.

System.IO.Abstractions.Analyzers.Tests/TestData/CodeFix/FileServiceConstructorInitialCodeFix/AfterFix.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ namespace SomeNameSpace
1414

1515
public void SomeMethod()
1616
{
17-
const string filePath = "C:\\temp.txt";
18-
19-
if (File.Exists(filePath))
20-
{
21-
File.Delete(filePath);
22-
}
17+
var newPath = Path.Combine("C:\\", "temp.txt");
2318
}
2419
}
2520
}

System.IO.Abstractions.Analyzers.Tests/TestData/CodeFix/FileServiceConstructorInitialCodeFix/AfterFixWithCustomField.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ namespace SomeNameSpace
1414

1515
public void SomeMethod()
1616
{
17-
const string filePath = "C:\\temp.txt";
18-
19-
if (File.Exists(filePath))
20-
{
21-
File.Delete(filePath);
22-
}
17+
var newPath = Path.Combine("C:\\", "temp.txt");
2318
}
2419
}
2520
}

System.IO.Abstractions.Analyzers.Tests/TestData/CodeFix/FileServiceConstructorInitialCodeFix/BeforeFix.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ namespace SomeNameSpace
1010

1111
public void SomeMethod()
1212
{
13-
const string filePath = "C:\\temp.txt";
14-
15-
if (File.Exists(filePath))
16-
{
17-
File.Delete(filePath);
18-
}
13+
var newPath = Path.Combine("C:\\", "temp.txt");
1914
}
2015
}
2116
}

System.IO.Abstractions.Analyzers.Tests/TestData/CodeFix/FileServiceConstructorInitialCodeFix/BeforeFixWithCustomField.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ namespace SomeNameSpace
1212

1313
public void SomeMethod()
1414
{
15-
const string filePath = "C:\\temp.txt";
16-
17-
if (File.Exists(filePath))
18-
{
19-
File.Delete(filePath);
20-
}
15+
var newPath = Path.Combine("C:\\", "temp.txt");
2116
}
2217
}
2318
}

0 commit comments

Comments
 (0)