Skip to content

Commit e5c8925

Browse files
committed
Merge branch 'master' into document-testing
2 parents 87c80db + c725402 commit e5c8925

82 files changed

Lines changed: 3023 additions & 361 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ packages/
1010
*.user
1111
TestResults/
1212
OpenCover.Reports/
13+
OpenCover.Symbols/
1314
.nuget/NuGet.exe
1415
build/nuget/
1516
*.log

.nuget/packages.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Codecov" version="1.0.1" />
4-
<package id="OpenCover" version="4.6.247-rc" />
4+
<package id="Microsoft.DiaSymReader.Pdb2Pdb" version="1.1.0-beta1-62624-01" />
5+
<package id="OpenCover" version="4.6.519" />
56
<package id="ReportGenerator" version="2.3.5.0" targetFramework="net452" />
67
<package id="xunit.runner.console" version="2.1.0" targetFramework="net452" />
78
</packages>

NuGet.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<packageSources>
4-
<add key="dotnet.myget.org roslyn" value="https://dotnet.myget.org/F/roslyn/api/v3/index.json" />
4+
<add key="roslyn" value="https://dotnet.myget.org/F/roslyn/api/v3/index.json" />
5+
<add key="symreader-converter" value="https://dotnet.myget.org/F/symreader-converter/api/v3/index.json" />
56
</packageSources>
67
</configuration>

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# StyleCop Analyzers for the .NET Compiler Platform
22

3+
[![NuGet](https://img.shields.io/nuget/v/StyleCop.Analyzers.svg)](https://www.nuget.org/packages/StyleCop.Analyzers)[![NuGet Beta](https://img.shields.io/nuget/vpre/StyleCop.Analyzers.svg)](https://www.nuget.org/packages/StyleCop.Analyzers)
4+
35
[![Join the chat at https://gitter.im/DotNetAnalyzers/StyleCopAnalyzers](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/DotNetAnalyzers/StyleCopAnalyzers?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
46

57
[![Build status](https://ci.appveyor.com/api/projects/status/8jw2lq431kgg44jl/branch/master?svg=true)](https://ci.appveyor.com/project/sharwell/stylecopanalyzers/branch/master)
@@ -13,7 +15,7 @@ This repository contains an implementation of the StyleCop rules using the .NET
1315
The preferable way to use the analyzers is to add the nuget package [StyleCop.Analyzers](http://www.nuget.org/packages/StyleCop.Analyzers/)
1416
to the project where you want to enforce StyleCop rules.
1517

16-
The severity of individual rules may be configured using [rule set files](https://msdn.microsoft.com/en-us/library/dd264996.aspx)
18+
The severity of individual rules may be configured using [rule set files](https://docs.microsoft.com/en-us/visualstudio/code-quality/using-rule-sets-to-group-code-analysis-rules)
1719
in Visual Studio 2015 or newer. **Settings.StyleCop** is not supported, but a **stylecop.json** file may be used to
1820
customize the behavior of certain rules. See [Configuration.md](documentation/Configuration.md) for more information.
1921

StyleCop.Analyzers/Directory.Build.props

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<Copyright>Copyright © Tunnel Vision Laboratories, LLC 2015</Copyright>
99
<NeutralLanguage>en-US</NeutralLanguage>
1010

11-
<Version>1.1.0.35</Version>
12-
<FileVersion>1.1.0.35</FileVersion>
11+
<Version>1.1.0.37</Version>
12+
<FileVersion>1.1.0.37</FileVersion>
1313
<InformationalVersion>1.1.0-dev</InformationalVersion>
1414
</PropertyGroup>
1515

@@ -27,13 +27,8 @@
2727
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
2828
</PropertyGroup>
2929

30-
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
31-
<DebugType>full</DebugType>
32-
<DebugSymbols>true</DebugSymbols>
33-
</PropertyGroup>
34-
35-
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
36-
<DebugType>pdbonly</DebugType>
30+
<PropertyGroup>
31+
<DebugType>portable</DebugType>
3732
<DebugSymbols>true</DebugSymbols>
3833
</PropertyGroup>
3934

@@ -51,7 +46,7 @@
5146

5247
<ItemGroup>
5348
<PackageReference Include="AsyncUsageAnalyzers" Version="1.0.0-alpha003" PrivateAssets="all" />
54-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004" PrivateAssets="all" />
49+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta006" PrivateAssets="all" />
5550
</ItemGroup>
5651

5752
<ItemGroup>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.DocumentationRules
5+
{
6+
using System.Collections.Immutable;
7+
using System.Composition;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
using Microsoft.CodeAnalysis;
11+
using Microsoft.CodeAnalysis.CodeActions;
12+
using Microsoft.CodeAnalysis.CodeFixes;
13+
using Microsoft.CodeAnalysis.Text;
14+
using StyleCop.Analyzers.Helpers;
15+
16+
/// <summary>
17+
/// Implements a code fix for <see cref="SA1629DocumentationTextMustEndWithAPeriod"/>.
18+
/// </summary>
19+
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(SA1629CodeFixProvider))]
20+
[Shared]
21+
internal class SA1629CodeFixProvider : CodeFixProvider
22+
{
23+
/// <inheritdoc/>
24+
public override ImmutableArray<string> FixableDiagnosticIds { get; }
25+
= ImmutableArray.Create(SA1629DocumentationTextMustEndWithAPeriod.DiagnosticId);
26+
27+
/// <inheritdoc/>
28+
public override FixAllProvider GetFixAllProvider()
29+
{
30+
return CustomFixAllProviders.BatchFixer;
31+
}
32+
33+
/// <inheritdoc/>
34+
public override Task RegisterCodeFixesAsync(CodeFixContext context)
35+
{
36+
foreach (Diagnostic diagnostic in context.Diagnostics)
37+
{
38+
if (!diagnostic.Properties.ContainsKey(SA1629DocumentationTextMustEndWithAPeriod.NoCodeFixKey))
39+
{
40+
context.RegisterCodeFix(
41+
CodeAction.Create(
42+
DocumentationResources.SA1629CodeFix,
43+
cancellationToken => GetTransformedDocumentAsync(context.Document, diagnostic, cancellationToken),
44+
nameof(SA1629CodeFixProvider)),
45+
diagnostic);
46+
}
47+
}
48+
49+
return SpecializedTasks.CompletedTask;
50+
}
51+
52+
private static async Task<Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
53+
{
54+
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
55+
var newText = text.WithChanges(new TextChange(new TextSpan(diagnostic.Location.SourceSpan.Start, 0), "."));
56+
57+
return document.WithText(newText);
58+
}
59+
}
60+
}

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/FixAllContextHelper.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,6 @@ public static async Task<ImmutableDictionary<Project, ImmutableArray<Diagnostic>
119119
return ImmutableDictionary<Project, ImmutableArray<Diagnostic>>.Empty;
120120
}
121121

122-
public static async Task<ImmutableArray<Diagnostic>> GetAllDiagnosticsAsync(Compilation compilation, CompilationWithAnalyzers compilationWithAnalyzers, ImmutableArray<DiagnosticAnalyzer> analyzers, IEnumerable<Document> documents, bool includeCompilerDiagnostics, CancellationToken cancellationToken)
123-
{
124-
return await compilationWithAnalyzers.GetAllDiagnosticsAsync(cancellationToken).ConfigureAwait(false);
125-
}
126-
127122
/// <summary>
128123
/// Gets all <see cref="Diagnostic"/> instances within a specific <see cref="Project"/> which are relevant to a
129124
/// <see cref="FixAllContext"/>.

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/IndentationHelper.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ public static int GetIndentationSteps(IndentationSettings indentationSettings, S
5656
/// <returns>The number of steps that the token is indented.</returns>
5757
public static int GetIndentationSteps(IndentationSettings indentationSettings, SyntaxToken token)
5858
{
59-
return GetIndentationSteps(indentationSettings, token.SyntaxTree, token.LeadingTrivia);
59+
// If the token does not belong to a syntax tree, it is a modified token and it is assumed that
60+
// the caller makes sure that the token is the first token on a line.
61+
return token.SyntaxTree != null
62+
? GetIndentationSteps(indentationSettings, token.SyntaxTree, token.LeadingTrivia)
63+
: GetIndentationStepsUnchecked(indentationSettings, token.LeadingTrivia);
6064
}
6165

6266
/// <summary>
@@ -104,6 +108,11 @@ private static int GetIndentationSteps(IndentationSettings indentationSettings,
104108
return 0;
105109
}
106110

111+
return GetIndentationStepsUnchecked(indentationSettings, leadingTrivia);
112+
}
113+
114+
private static int GetIndentationStepsUnchecked(IndentationSettings indentationSettings, SyntaxTriviaList leadingTrivia)
115+
{
107116
var builder = StringBuilderPool.Allocate();
108117

109118
foreach (SyntaxTrivia trivia in leadingTrivia.Reverse())

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,15 @@ private static Dictionary<SyntaxToken, SyntaxToken> GenerateBraceFixes(Document
122122

123123
if (!braceTokens.Contains(nextToken))
124124
{
125-
int newIndentationSteps;
125+
int newIndentationSteps = indentationSteps;
126126
if (braceToken.IsKind(SyntaxKind.OpenBraceToken))
127127
{
128-
newIndentationSteps = indentationSteps + 1;
128+
newIndentationSteps++;
129129
}
130-
else if (nextToken.IsKind(SyntaxKind.CloseBraceToken))
131-
{
132-
newIndentationSteps = Math.Max(0, indentationSteps - 1);
133-
}
134-
else
130+
131+
if (nextToken.IsKind(SyntaxKind.CloseBraceToken))
135132
{
136-
newIndentationSteps = indentationSteps;
133+
newIndentationSteps = Math.Max(0, newIndentationSteps - 1);
137134
}
138135

139136
AddReplacement(tokenReplacements, nextToken, nextToken.WithLeadingTrivia(IndentationHelper.GenerateWhitespaceTrivia(indentationSettings, newIndentationSteps)));
@@ -250,7 +247,15 @@ private static LinePosition GetTokenStartLinePosition(SyntaxToken token)
250247

251248
private static void AddReplacement(Dictionary<SyntaxToken, SyntaxToken> tokenReplacements, SyntaxToken originalToken, SyntaxToken replacementToken)
252249
{
253-
tokenReplacements[originalToken] = replacementToken;
250+
if (tokenReplacements.ContainsKey(originalToken))
251+
{
252+
// This will only happen when a single keyword (like else) has invalid brace tokens before and after it.
253+
tokenReplacements[originalToken] = tokenReplacements[originalToken].WithTrailingTrivia(replacementToken.TrailingTrivia);
254+
}
255+
else
256+
{
257+
tokenReplacements[originalToken] = replacementToken;
258+
}
254259
}
255260

256261
private class FixAll : DocumentBasedFixAllProvider

0 commit comments

Comments
 (0)