Skip to content

Commit 21516ab

Browse files
committed
Merge branch 'master' into add-part
2 parents 4452ff5 + f5843ae commit 21516ab

File tree

689 files changed

+11059
-835
lines changed

Some content is hidden

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

689 files changed

+11059
-835
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ OpenCover.Symbols/
1414
.nuget/NuGet.exe
1515
build/nuget/
1616
*.log
17-
StyleCop.Analyzers/StyleCop.Analyzers/Lightup/.generated/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/
1817

1918
# Visual Studio performance tools
2019
*.psess

.nuget/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Codecov" version="1.9.0" />
3+
<package id="CodecovUploader" version="0.7.1" />
44
<package id="OpenCover" version="4.6.519" />
5-
<package id="ReportGenerator" version="2.3.5.0" targetFramework="net452" />
5+
<package id="ReportGenerator" version="5.2.0" />
66
<package id="xunit.runner.console" version="2.4.1" />
77
</packages>

NuGet.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
77
<add key="dotnet5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" />
88
<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />
9+
<add key="dotnet9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json" />
910

1011
<!-- Uncomment this to test unpublished builds from the AppVeyor feed. -->
1112
<!--<add key="appveyor-stylecop" value="https://ci.appveyor.com/nuget/stylecopanalyzers" />-->

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[![Build status](https://ci.appveyor.com/api/projects/status/8jw2lq431kgg44jl/branch/master?svg=true)](https://ci.appveyor.com/project/sharwell/stylecopanalyzers/branch/master)
88

9-
[![codecov.io](http://codecov.io/github/DotNetAnalyzers/StyleCopAnalyzers/coverage.svg?branch=master)](http://codecov.io/github/DotNetAnalyzers/StyleCopAnalyzers?branch=master)
9+
[![codecov.io](https://codecov.io/github/DotNetAnalyzers/StyleCopAnalyzers/coverage.svg?branch=master)](https://codecov.io/github/DotNetAnalyzers/StyleCopAnalyzers?branch=master)
1010

1111
This repository contains an implementation of the StyleCop rules using the .NET Compiler Platform. Where possible, code fixes are also provided to simplify the process of correcting violations.
1212

StyleCop.Analyzers/Directory.Build.props

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,24 @@
4040
<NoWarn>$(NoWarn),1573,1591,1712</NoWarn>
4141
</PropertyGroup>
4242

43+
<PropertyGroup>
44+
<SharedMicrosoftCodeAnalysisAnalyzersVersion>3.11.0-beta1.24052.1</SharedMicrosoftCodeAnalysisAnalyzersVersion>
45+
</PropertyGroup>
46+
4347
<ItemGroup>
4448
<PackageReference Include="Nerdbank.GitVersioning" Version="2.2.13" PrivateAssets="all" />
4549
</ItemGroup>
4650

4751
<ItemGroup>
4852
<PackageReference Include="AsyncUsageAnalyzers" Version="1.0.0-alpha003" PrivateAssets="all" />
4953
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.46" PrivateAssets="all" />
50-
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all" />
51-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.5-beta1.23223.2" PrivateAssets="all" />
54+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="all" />
55+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(SharedMicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
5256
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.0.1" PrivateAssets="all" />
5357
</ItemGroup>
5458

5559
<ItemGroup>
56-
<PackageReference Include="Microsoft.CodeAnalysis.ResxSourceGenerator" Version="3.3.5-beta1.23223.2" PrivateAssets="all" />
60+
<PackageReference Include="Microsoft.CodeAnalysis.ResxSourceGenerator" Version="$(SharedMicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
5761
</ItemGroup>
5862

5963
<!-- C# Compiler -->
@@ -63,7 +67,7 @@
6367

6468
<!-- Public API -->
6569
<ItemGroup>
66-
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="2.9.7" PrivateAssets="all" />
70+
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(SharedMicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
6771
</ItemGroup>
6872

6973
<ItemGroup>

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

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

8484
var fileHeader = FileHeaderHelpers.ParseFileHeader(root);
8585
SyntaxNode newSyntaxRoot;

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1629CodeFixProvider.cs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace StyleCop.Analyzers.DocumentationRules
77
{
8+
using System.Collections.Generic;
89
using System.Collections.Immutable;
910
using System.Composition;
1011
using System.Threading;
@@ -29,7 +30,7 @@ internal class SA1629CodeFixProvider : CodeFixProvider
2930
/// <inheritdoc/>
3031
public override FixAllProvider GetFixAllProvider()
3132
{
32-
return CustomFixAllProviders.BatchFixer;
33+
return FixAll.Instance;
3334
}
3435

3536
/// <inheritdoc/>
@@ -54,10 +55,46 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
5455
private static async Task<Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
5556
{
5657
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
57-
bool replaceChar = diagnostic.Properties.ContainsKey(SA1629DocumentationTextMustEndWithAPeriod.ReplaceCharKey);
58-
var newText = text.WithChanges(new TextChange(new TextSpan(diagnostic.Location.SourceSpan.Start, replaceChar ? 1 : 0), "."));
58+
var textChange = GetTextChange(diagnostic);
59+
var newText = text.WithChanges(textChange);
5960

6061
return document.WithText(newText);
6162
}
63+
64+
private static TextChange GetTextChange(Diagnostic diagnostic)
65+
{
66+
var replaceChar = diagnostic.Properties.ContainsKey(SA1629DocumentationTextMustEndWithAPeriod.ReplaceCharKey);
67+
var textChange = new TextChange(new TextSpan(diagnostic.Location.SourceSpan.Start, replaceChar ? 1 : 0), ".");
68+
return textChange;
69+
}
70+
71+
private class FixAll : DocumentBasedFixAllProvider
72+
{
73+
public static FixAllProvider Instance { get; } =
74+
new FixAll();
75+
76+
protected override string CodeActionTitle =>
77+
DocumentationResources.SA1629CodeFix;
78+
79+
protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> diagnostics)
80+
{
81+
if (diagnostics.IsEmpty)
82+
{
83+
return null;
84+
}
85+
86+
var changes = new List<TextChange>();
87+
foreach (var diagnostic in diagnostics)
88+
{
89+
changes.Add(GetTextChange(diagnostic));
90+
}
91+
92+
changes.Sort((left, right) => left.Span.Start.CompareTo(right.Span.Start));
93+
94+
var text = await document.GetTextAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
95+
var tree = await document.GetSyntaxTreeAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
96+
return await tree.WithChangedText(text.WithChanges(changes)).GetRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
97+
}
98+
}
6299
}
63100
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
8585
internal static ImmutableArray<string> GenerateStandardText(Document document, BaseMethodDeclarationSyntax methodDeclaration, BaseTypeDeclarationSyntax typeDeclaration, CancellationToken cancellationToken)
8686
{
8787
bool isStruct = typeDeclaration.IsKind(SyntaxKind.StructDeclaration) || typeDeclaration.IsKind(SyntaxKindEx.RecordStructDeclaration);
88-
var settings = document.Project.AnalyzerOptions.GetStyleCopSettings(methodDeclaration.SyntaxTree, cancellationToken);
88+
var settings = document.Project.AnalyzerOptions.GetStyleCopSettingsInCodeFix(methodDeclaration.SyntaxTree, cancellationToken);
8989
var culture = settings.DocumentationRules.DocumentationCultureInfo;
9090
var resourceManager = DocumentationResources.ResourceManager;
9191

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

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

61-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, cancellationToken);
61+
var settings = SettingsHelper.GetStyleCopSettingsInCodeFix(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, cancellationToken);
6262
var braceToken = syntaxRoot.FindToken(diagnostic.Location.SourceSpan.Start);
6363
var tokenReplacements = GenerateBraceFixes(settings, ImmutableArray.Create(braceToken));
6464

@@ -290,7 +290,7 @@ protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fi
290290
.OrderBy(token => token.SpanStart)
291291
.ToImmutableArray();
292292

293-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, fixAllContext.CancellationToken);
293+
var settings = SettingsHelper.GetStyleCopSettingsInCodeFix(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, fixAllContext.CancellationToken);
294294

295295
var tokenReplacements = GenerateBraceFixes(settings, tokens);
296296

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

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

305305
var tokenReplaceMap = new Dictionary<SyntaxToken, SyntaxToken>();
306306
SyntaxNode syntaxRoot = await document.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
307-
var settings = SettingsHelper.GetStyleCopSettings(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, fixAllContext.CancellationToken);
307+
var settings = SettingsHelper.GetStyleCopSettingsInCodeFix(document.Project.AnalyzerOptions, syntaxRoot.SyntaxTree, fixAllContext.CancellationToken);
308308

309309
foreach (var diagnostic in diagnostics.Sort(DiagnosticComparer.Instance))
310310
{

0 commit comments

Comments
 (0)