Skip to content

Commit ee13833

Browse files
committed
Add formatting code after apply code fix
1 parent 6bc683d commit ee13833

File tree

7 files changed

+15
-10
lines changed

7 files changed

+15
-10
lines changed

System.IO.Abstractions.Analyzers/CodeActions/DirectoryInfoCodeAction.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.CodeAnalysis.CodeActions;
66
using Microsoft.CodeAnalysis.CSharp.Syntax;
77
using Microsoft.CodeAnalysis.Editing;
8+
using Microsoft.CodeAnalysis.Formatting;
89
using SF = Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
910

1011
namespace System.IO.Abstractions.Analyzers.CodeActions
@@ -22,7 +23,7 @@ public class DirectoryInfoCodeAction : CodeAction
2223
public override string EquivalenceKey => Title;
2324

2425
public DirectoryInfoCodeAction(string title, Document document, ObjectCreationExpressionSyntax creationExpressionSyntax,
25-
FieldDeclarationSyntax field)
26+
FieldDeclarationSyntax field)
2627
{
2728
Title = title;
2829
_document = document;
@@ -36,9 +37,10 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
3637
var arguments = _creationExpressionSyntax.ArgumentList.Arguments.Select(x => x.ToFullString());
3738

3839
editor.ReplaceNode(_creationExpressionSyntax,
39-
SF.ParseExpression($"{_field.Declaration.Variables.ToFullString()}.DirectoryInfo.FromDirectoryName({string.Join(",", arguments)})"));
40+
SF.ParseExpression(
41+
$"{_field.Declaration.Variables.ToFullString()}.DirectoryInfo.FromDirectoryName({string.Join(",", arguments)})"));
4042

41-
return editor.GetChangedDocument();
43+
return await Formatter.FormatAsync(editor.GetChangedDocument(), cancellationToken: cancellationToken).ConfigureAwait(false);
4244
}
4345
}
4446
}

System.IO.Abstractions.Analyzers/CodeActions/FileInfoCodeAction.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.CodeAnalysis.CodeActions;
66
using Microsoft.CodeAnalysis.CSharp.Syntax;
77
using Microsoft.CodeAnalysis.Editing;
8+
using Microsoft.CodeAnalysis.Formatting;
89
using SF = Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
910

1011
namespace System.IO.Abstractions.Analyzers.CodeActions
@@ -38,7 +39,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
3839
editor.ReplaceNode(_creationExpressionSyntax,
3940
SF.ParseExpression($"{_field.Declaration.Variables.ToFullString()}.FileInfo.FromFileName({string.Join(",", arguments)})"));
4041

41-
return editor.GetChangedDocument();
42+
return await Formatter.FormatAsync(editor.GetChangedDocument(), cancellationToken: cancellationToken).ConfigureAwait(false);
4243
}
4344
}
4445
}

System.IO.Abstractions.Analyzers/CodeActions/FileServiceConstructorInitialCodeAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
7171
editor.InsertAfter(systemIo, RoslynClassFileSystem.GetFileSystemUsing());
7272
}
7373

74-
return editor.GetChangedDocument();
74+
return await Formatter.FormatAsync(editor.GetChangedDocument(), cancellationToken: cancellationToken).ConfigureAwait(false);
7575
}
7676

7777
private static ExpressionStatementSyntax CreateAssignmentExpression(string field = Constants.FieldFileSystemName)

System.IO.Abstractions.Analyzers/CodeActions/FileServiceInterfaceInjectionCodeAction.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
7171
editor.InsertAfter(systemIo, RoslynClassFileSystem.GetFileSystemUsing());
7272
}
7373

74-
return editor.GetChangedDocument();
74+
return await Formatter.FormatAsync(editor.GetChangedDocument(), cancellationToken: cancellationToken).ConfigureAwait(false);
7575
}
7676

7777
private static ExpressionStatementSyntax CreateAssignmentExpression(string field, string parameter)
@@ -105,7 +105,8 @@ private static void ConstructorAddParameter(ClassDeclarationSyntax classDeclarat
105105
{
106106
var fileSystem = RoslynClassFileSystem.GetFileSystemFieldFromClass(classDeclaration);
107107

108-
newConstructor = newConstructor.AddBodyStatements(CreateAssignmentExpression(fileSystem.Declaration.Variables.ToFullString(),
108+
newConstructor = newConstructor.AddBodyStatements(CreateAssignmentExpression(
109+
fileSystem.Declaration.Variables.ToFullString(),
109110
parameterSyntax.Identifier.Text));
110111
} else
111112
{

System.IO.Abstractions.Analyzers/CodeActions/FileStreamCodeAction.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.CodeAnalysis.CodeActions;
66
using Microsoft.CodeAnalysis.CSharp.Syntax;
77
using Microsoft.CodeAnalysis.Editing;
8+
using Microsoft.CodeAnalysis.Formatting;
89
using SF = Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
910

1011
namespace System.IO.Abstractions.Analyzers.CodeActions
@@ -38,7 +39,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
3839
editor.ReplaceNode(_creationExpressionSyntax,
3940
SF.ParseExpression($"{_field.Declaration.Variables.ToFullString()}.FileStream.Create({string.Join(",", arguments)})"));
4041

41-
return editor.GetChangedDocument();
42+
return await Formatter.FormatAsync(editor.GetChangedDocument(), cancellationToken: cancellationToken).ConfigureAwait(false);
4243
}
4344
}
4445
}

System.IO.Abstractions.Analyzers/CodeActions/FileSystemInvokeCodeAction.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.CodeAnalysis.CodeActions;
55
using Microsoft.CodeAnalysis.CSharp.Syntax;
66
using Microsoft.CodeAnalysis.Editing;
7+
using Microsoft.CodeAnalysis.Formatting;
78
using SF = Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
89

910
namespace System.IO.Abstractions.Analyzers.CodeActions
@@ -37,7 +38,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
3738
SF.ParseExpression(
3839
$"{_field.Declaration.Variables.FirstOrDefault().Identifier.Text}.{_invocation.NormalizeWhitespace().ToFullString()}"));
3940

40-
return editor.GetChangedDocument();
41+
return await Formatter.FormatAsync(editor.GetChangedDocument(), cancellationToken: cancellationToken).ConfigureAwait(false);
4142
}
4243
}
4344
}

System.IO.Abstractions.Analyzers/CodeFixes/BaseInvokeCodeFix.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.IO.Abstractions.Analyzers.RoslynToken;
44
using System.Linq;
55
using System.Threading.Tasks;
6-
using Microsoft.CodeAnalysis;
76
using Microsoft.CodeAnalysis.CodeFixes;
87
using Microsoft.CodeAnalysis.CSharp.Syntax;
98

0 commit comments

Comments
 (0)