Skip to content

Commit 6848e65

Browse files
authored
Merge pull request #3285 from sharwell/editorconfig
Support defining options in .editorconfig
2 parents 56c677b + b5228ba commit 6848e65

File tree

55 files changed

+1221
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1221
-238
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ indent_size = 4
1212

1313
# Sort using and Import directives with System.* appearing first
1414
dotnet_sort_system_directives_first = true
15+
dotnet_separate_import_directive_groups = false
16+
csharp_using_directive_placement = inside_namespace:none
1517

1618
# Always use "this." and "Me." when applicable; let StyleCop Analyzers provide the warning and fix
1719
dotnet_style_qualification_for_field = true:none

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/FileHeaderCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen
7777
private static async Task<SyntaxNode> GetTransformedSyntaxRootAsync(Document document, CancellationToken cancellationToken)
7878
{
7979
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
80-
var settings = document.Project.AnalyzerOptions.GetStyleCopSettings(cancellationToken);
80+
var settings = document.Project.AnalyzerOptions.GetStyleCopSettings(root.SyntaxTree, cancellationToken);
8181

8282
var fileHeader = FileHeaderHelpers.ParseFileHeader(root);
8383
SyntaxNode newSyntaxRoot;

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1642SA1643CodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
8282
internal static ImmutableArray<string> GenerateStandardText(Document document, BaseMethodDeclarationSyntax methodDeclaration, BaseTypeDeclarationSyntax typeDeclaration, CancellationToken cancellationToken)
8383
{
8484
bool isStruct = typeDeclaration.IsKind(SyntaxKind.StructDeclaration);
85-
var settings = document.Project.AnalyzerOptions.GetStyleCopSettings(cancellationToken);
85+
var settings = document.Project.AnalyzerOptions.GetStyleCopSettings(methodDeclaration.SyntaxTree, cancellationToken);
8686
var culture = new CultureInfo(settings.DocumentationRules.DocumentationCulture);
8787
var resourceManager = DocumentationResources.ResourceManager;
8888

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1500CodeFixProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen
5555
{
5656
var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
5757

58-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, cancellationToken);
58+
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, cancellationToken);
5959
var braceToken = syntaxRoot.FindToken(diagnostic.Location.SourceSpan.Start);
6060
var tokenReplacements = GenerateBraceFixes(settings.Indentation, ImmutableArray.Create(braceToken));
6161

@@ -282,7 +282,7 @@ protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fi
282282
.OrderBy(token => token.SpanStart)
283283
.ToImmutableArray();
284284

285-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, fixAllContext.CancellationToken);
285+
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, fixAllContext.CancellationToken);
286286

287287
var tokenReplacements = GenerateBraceFixes(settings.Indentation, tokens);
288288

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1501CodeFixProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
5858
private static async Task<Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
5959
{
6060
var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
61-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, cancellationToken);
61+
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, cancellationToken);
6262
if (!(syntaxRoot.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true) is StatementSyntax statement))
6363
{
6464
return document;
@@ -301,8 +301,8 @@ protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fi
301301
}
302302

303303
var tokenReplaceMap = new Dictionary<SyntaxToken, SyntaxToken>();
304-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, fixAllContext.CancellationToken);
305304
SyntaxNode syntaxRoot = await document.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
305+
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, fixAllContext.CancellationToken);
306306

307307
foreach (var diagnostic in diagnostics.Sort(DiagnosticComparer.Instance))
308308
{

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1502CodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
5353
private async Task<Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
5454
{
5555
var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
56-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, cancellationToken);
56+
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, cancellationToken);
5757
var newDocument = this.CreateCodeFix(document, settings.Indentation, diagnostic, syntaxRoot);
5858

5959
return newDocument;

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1504CodeFixProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private static bool IsAllowedTrivia(SyntaxTrivia trivia)
109109
private static async Task<Document> GetTransformedDocumentForSingleLineAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
110110
{
111111
var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
112-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, cancellationToken);
112+
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, cancellationToken);
113113

114114
var node = syntaxRoot.FindNode(diagnostic.Location.SourceSpan);
115115
var accessorList = GetAccessorList(node);
@@ -188,7 +188,7 @@ private static BlockSyntax ReformatBodyAsSingleLine(BlockSyntax body)
188188
private static async Task<Document> GetTransformedDocumentForMutipleLinesAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
189189
{
190190
var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
191-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, cancellationToken);
191+
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, cancellationToken);
192192

193193
var node = syntaxRoot.FindNode(diagnostic.Location.SourceSpan);
194194
var accessorList = GetAccessorList(node);

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/LayoutRules/SA1518CodeFixProvider.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ public override FixAllProvider GetFixAllProvider()
3232
}
3333

3434
/// <inheritdoc/>
35-
public override Task RegisterCodeFixesAsync(CodeFixContext context)
35+
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3636
{
37-
var settings = SettingsHelper.GetStyleCopSettings(context.Document.Project.AnalyzerOptions, context.CancellationToken);
37+
var syntaxTree = await context.Document.GetSyntaxTreeAsync(context.CancellationToken).ConfigureAwait(false);
38+
var settings = SettingsHelper.GetStyleCopSettings(context.Document.Project.AnalyzerOptions, syntaxTree, context.CancellationToken);
3839
foreach (var diagnostic in context.Diagnostics)
3940
{
4041
context.RegisterCodeFix(
@@ -44,8 +45,6 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
4445
nameof(SA1518CodeFixProvider)),
4546
diagnostic);
4647
}
47-
48-
return SpecializedTasks.CompletedTask;
4948
}
5049

5150
/// <summary>
@@ -78,7 +77,8 @@ protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fi
7877
return null;
7978
}
8079

81-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, fixAllContext.CancellationToken);
80+
var syntaxTree = await document.GetSyntaxTreeAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
81+
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxTree, fixAllContext.CancellationToken);
8282
Document updatedDocument = await FixEndOfFileAsync(document, diagnostics[0], settings.LayoutRules.NewlineAtEndOfFile, fixAllContext.CancellationToken).ConfigureAwait(false);
8383
return await updatedDocument.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
8484
}

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1402CodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private static async Task<Solution> GetTransformedSolutionAsync(Document documen
6464
DocumentId extractedDocumentId = DocumentId.CreateNewId(document.Project.Id);
6565
string suffix;
6666
FileNameHelpers.GetFileNameAndSuffix(document.Name, out suffix);
67-
var settings = document.Project.AnalyzerOptions.GetStyleCopSettings(cancellationToken);
67+
var settings = document.Project.AnalyzerOptions.GetStyleCopSettings(root.SyntaxTree, cancellationToken);
6868
string extractedDocumentName = FileNameHelpers.GetConventionalFileName(memberDeclarationSyntax, settings.DocumentationRules.FileNamingConvention) + suffix;
6969

7070
List<SyntaxNode> nodesToRemoveFromExtracted = new List<SyntaxNode>();

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/OrderingRules/ElementOrderCodeFixProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
5757

5858
private static async Task<Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
5959
{
60-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, cancellationToken);
61-
var elementOrder = settings.OrderingRules.ElementOrder;
6260
var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
61+
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, cancellationToken);
62+
var elementOrder = settings.OrderingRules.ElementOrder;
6363

6464
var memberDeclaration = syntaxRoot.FindNode(diagnostic.Location.SourceSpan).FirstAncestorOrSelf<MemberDeclarationSyntax>();
6565
if (memberDeclaration == null)
@@ -263,9 +263,9 @@ protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fi
263263
return null;
264264
}
265265

266-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, fixAllContext.CancellationToken);
266+
var syntaxRoot = await document.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
267+
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, fixAllContext.CancellationToken);
267268
var elementOrder = settings.OrderingRules.ElementOrder;
268-
var syntaxRoot = await document.GetSyntaxRootAsync().ConfigureAwait(false);
269269

270270
var trackedDiagnosticMembers = new List<MemberDeclarationSyntax>();
271271
foreach (var diagnostic in diagnostics)

0 commit comments

Comments
 (0)