Skip to content

Commit de45506

Browse files
committed
merged with master
2 parents 987bafc + c219678 commit de45506

508 files changed

Lines changed: 16221 additions & 5596 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
@@ -9,6 +9,7 @@ packages/
99
*.suo
1010
*.user
1111
TestResults/
12+
OpenCover.Reports/
1213
.nuget/NuGet.exe
1314
build/nuget/
1415
*.log

.nuget/packages.config

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="NuGet.CommandLine" version="2.8.3" />
4-
<package id="OpenCover" version="4.6.166" />
4+
<package id="OpenCover" version="4.6.247-rc" />
5+
<package id="ReportGenerator" version="2.3.5.0" targetFramework="net452" />
6+
<package id="xunit.runner.console" version="2.1.0" targetFramework="net452" />
57
</packages>

CONTRIBUTING.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ If you want to contribute code you can get started by looking for issues marked
55
We also have the [easy](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/labels/easy) tag
66
for issues suitable if you are unfamiliar with roslyn.
77

8-
Also see the [contributing guide](CONTRIBUTING.md).
9-
108
You can also help by filing issues, participating in discussions and doing code review.
119

1210
## Implementing a diagnostic
@@ -30,4 +28,4 @@ You can also help by filing issues, participating in discussions and doing code
3028

3129
Visual Studio 2015 RC is required for building this repository.
3230
The Visual Studio 2015 RC SDK is required for building the vsix extension project and for
33-
debugging in an experimental visual studio hive.
31+
debugging in an experimental visual studio hive.

DOCUMENTATION.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
StyleCop.Analyzers provides warnings that indicate style and consistency rule violations in C# code. The warnings are organized into rule areas such as documentation, layout, naming, ordering, readability, spacing, and so forth. Each warning signifies a violation of a style or consistency rule. This section provides an explanation of each of the default StyleCop.Analyzers rules.
2+
3+
### Rule areas
4+
**[Special Rules (SA0000-)](documentation/SpecialRules.md)**
5+
6+
Rules which provide special functionality like workarounds, configuration errors, etc.
7+
8+
**[Spacing Rules (SA1000-)](documentation/SpacingRules.md)**
9+
10+
Rules which enforce spacing requirements around keywords and symbols in the code.
11+
12+
**[Readability Rules (SA1100-)](documentation/ReadabilityRules.md)**
13+
14+
Rules which ensure that the code is well-formatted and readable.
15+
16+
**[Ordering Rules (SA1200-)](documentation/OrderingRules.md)**
17+
18+
Rules which enforce a standard ordering scheme for code contents.
19+
20+
**[Naming Rules (SA1300-)](documentation/NamingRules.md)**
21+
22+
Rules which enforce naming requirements for members, types, and variables.
23+
24+
**[Maintainability Rules (SA1400-)](documentation/MaintainabilityRules.md)**
25+
26+
Rules which improve code maintainability.
27+
28+
**[Layout Rules (SA1500-)](documentation/LayoutRules.md)**
29+
30+
Rules which enforce code layout and line spacing.
31+
32+
**[Documentation Rules (SA1600-)](documentation/DocumentationRules.md)**
33+
34+
Rules which verify the content and formatting of code documentation.
35+
36+
**[Alternative Rules (SX0000-)](documentation/AlternativeRules.md)**
37+
38+
Rules which offer a non-standard extension to the default StyleCop behavior.
39+
40+
### Additional documentation
41+
**[Configuration](documentation/Configuration.md)**
42+
43+
Describes the configuration options for StyleCop.Analyzers
44+
45+
**[How to enable the configuration](documentation/EnableConfiguration.md)**
46+
47+
Describes how to enable the **stylecop.json** file for usage.
48+
49+
**[Known changes](documentation/KnownChanges.md)**
50+
51+
Describes the known differences between StyleCop Analyzers and StyleCop Classic.

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,19 @@ The severity of individual rules may be configured using [rule set files](https:
1717
in Visual Studio 2015. **Settings.StyleCop** is not supported, but a **stylecop.json** file may be used to customize the
1818
behavior of certain rules. See [Configuration.md](documentation/Configuration.md) for more information.
1919

20+
For users upgrading from StyleCop Classic, see [KnownChanges.md](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/tree/master/documentation/KnownChanges.md)
21+
for information about known differences which you may notice when switching to StyleCop Analyzers.
22+
2023
## Installation
2124

22-
StyleCopAnalyzers can be installed using the NuGet Package Manager in Visual Studio 2015.
25+
StyleCopAnalyzers can be installed using the NuGet command line or the NuGet Package Manager in Visual Studio 2015.
26+
27+
**Install using the command line:**
28+
```bash
29+
Install-Package StyleCop.Analyzers
30+
```
2331

32+
**Install using the package manager:**
2433
![Install via nuget](https://cloud.githubusercontent.com/assets/1408396/8233513/491f301a-159c-11e5-8b7a-1e16a0695da6.png)
2534

2635
## Team Considerations
@@ -33,8 +42,8 @@ See [Contributing](CONTRIBUTING.md)
3342

3443
## Current status
3544

36-
An up-to-date list of which StyleCop rules are implemented and which have code fixes can be found [here](http://stylecop.pdelvo.com/).
45+
An up-to-date list of which StyleCop rules are implemented and which have code fixes can be found [here](https://stylecop.pdelvo.com/).
3746

3847
## Source browser
3948

40-
The up-to-date source code can be browsed [here](http://source.pdelvo.com/).
49+
The up-to-date source code can be browsed [here](https://source.pdelvo.com/).
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
$NuGet = '..\..\.nuget\NuGet.exe'
2+
&$NuGet update -Self -Verbosity quiet
3+
4+
# Make sure the project binaries are up-to-date
5+
&$NuGet restore ..\..\StyleCopAnalyzers.sln
6+
Push-Location
7+
cd ..\..\build
8+
.\build.ps1 -Incremental
9+
Pop-Location
10+
11+
&$NuGet install Microsoft.CodeAnalysis -Version 1.1.0 -OutputDirectory ..\..\packages -Verbosity quiet
12+
&$NuGet install Microsoft.CodeAnalysis -Version 1.1.1 -OutputDirectory ..\..\packages -Verbosity quiet
13+
14+
# Create folders for the testing tool
15+
Remove-Item .\bin\StyleCopTester-Roslyn.1.0.0 -Force -Recurse -ErrorAction Ignore
16+
Remove-Item .\bin\StyleCopTester-Roslyn.1.1.0 -Force -Recurse -ErrorAction Ignore
17+
Remove-Item .\bin\StyleCopTester-Roslyn.1.1.1 -Force -Recurse -ErrorAction Ignore
18+
19+
New-Item .\bin\StyleCopTester-Roslyn.1.0.0 -ItemType Directory
20+
New-Item .\bin\StyleCopTester-Roslyn.1.1.0 -ItemType Directory
21+
New-Item .\bin\StyleCopTester-Roslyn.1.1.1 -ItemType Directory
22+
23+
Copy-Item ..\StyleCopTester\bin\Release\* .\bin\StyleCopTester-Roslyn.1.0.0
24+
Copy-Item ..\StyleCopTester\bin\Release\* .\bin\StyleCopTester-Roslyn.1.1.0
25+
Copy-Item ..\StyleCopTester\bin\Release\* .\bin\StyleCopTester-Roslyn.1.1.1
26+
27+
Copy-Item .\StyleCopTester-Roslyn.1.0.exe.config .\bin\StyleCopTester-Roslyn.1.0.0\StyleCopTester.exe.config
28+
Copy-Item .\StyleCopTester-Roslyn.1.1.exe.config .\bin\StyleCopTester-Roslyn.1.1.0\StyleCopTester.exe.config
29+
Copy-Item .\StyleCopTester-Roslyn.1.1.exe.config .\bin\StyleCopTester-Roslyn.1.1.1\StyleCopTester.exe.config
30+
31+
Copy-Item ..\..\packages\Microsoft.CodeAnalysis.Common.1.1.0\lib\net45\*.dll .\bin\StyleCopTester-Roslyn.1.1.0
32+
Copy-Item ..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.1.0\lib\net45\*.dll .\bin\StyleCopTester-Roslyn.1.1.0
33+
Copy-Item ..\..\packages\System.Collections.Immutable.1.1.37\lib\dotnet\*.dll .\bin\StyleCopTester-Roslyn.1.1.0
34+
Copy-Item ..\..\packages\System.Reflection.Metadata.1.1.0\lib\dotnet5.2\*.dll .\bin\StyleCopTester-Roslyn.1.1.0
35+
Copy-Item ..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\*.dll .\bin\StyleCopTester-Roslyn.1.1.0
36+
Copy-Item ..\..\packages\Microsoft.CodeAnalysis.CSharp.1.1.0\lib\net45\*.dll .\bin\StyleCopTester-Roslyn.1.1.0
37+
Copy-Item ..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.1.0\lib\net45\*.dll .\bin\StyleCopTester-Roslyn.1.1.0
38+
Copy-Item ..\..\packages\Microsoft.CodeAnalysis.VisualBasic.1.1.0\lib\net45\*.dll .\bin\StyleCopTester-Roslyn.1.1.0
39+
Copy-Item ..\..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.1.0\lib\net45\*.dll .\bin\StyleCopTester-Roslyn.1.1.0
40+
41+
Copy-Item ..\..\packages\Microsoft.CodeAnalysis.Common.1.1.1\lib\net45\*.dll .\bin\StyleCopTester-Roslyn.1.1.1
42+
Copy-Item ..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.1.1\lib\net45\*.dll .\bin\StyleCopTester-Roslyn.1.1.1
43+
Copy-Item ..\..\packages\System.Collections.Immutable.1.1.37\lib\dotnet\*.dll .\bin\StyleCopTester-Roslyn.1.1.1
44+
Copy-Item ..\..\packages\System.Reflection.Metadata.1.1.0\lib\dotnet5.2\*.dll .\bin\StyleCopTester-Roslyn.1.1.1
45+
Copy-Item ..\..\packages\Microsoft.Composition.1.0.27\lib\portable-net45+win8+wp8+wpa81\*.dll .\bin\StyleCopTester-Roslyn.1.1.1
46+
Copy-Item ..\..\packages\Microsoft.CodeAnalysis.CSharp.1.1.1\lib\net45\*.dll .\bin\StyleCopTester-Roslyn.1.1.1
47+
Copy-Item ..\..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.1.1\lib\net45\*.dll .\bin\StyleCopTester-Roslyn.1.1.1
48+
Copy-Item ..\..\packages\Microsoft.CodeAnalysis.VisualBasic.1.1.1\lib\net45\*.dll .\bin\StyleCopTester-Roslyn.1.1.1
49+
Copy-Item ..\..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.1.1\lib\net45\*.dll .\bin\StyleCopTester-Roslyn.1.1.1
50+
51+
#
52+
# Testing DartVS/DartVS@6f54d1d2
53+
#
54+
55+
git clone https://github.com/DartVS/DartVS.git bin\DartVS
56+
Push-Location
57+
cd bin\DartVS
58+
git checkout 6f54d1d2bf6a16aaac5a6add7e073716e35e21ba
59+
Pop-Location
60+
61+
&$NuGet restore bin\DartVS\DanTup.DartVS.sln -Verbosity quiet
62+
63+
.\bin\StyleCopTester-Roslyn.1.0.0\StyleCopTester.exe bin\DartVS\DanTup.DartVS.sln /all /log:bin\DartVS-1.0.0.txt | Out-Null
64+
.\bin\StyleCopTester-Roslyn.1.1.0\StyleCopTester.exe bin\DartVS\DanTup.DartVS.sln /all /log:bin\DartVS-1.1.0.txt | Out-Null
65+
.\bin\StyleCopTester-Roslyn.1.1.1\StyleCopTester.exe bin\DartVS\DanTup.DartVS.sln /all /log:bin\DartVS-1.1.1.txt | Out-Null
66+
67+
#
68+
# Testing JamesNK/Newtonsoft.Json@48786adc
69+
#
70+
71+
git clone https://github.com/JamesNK/Newtonsoft.Json.git bin\Newtonsoft.Json
72+
Push-Location
73+
cd bin\Newtonsoft.Json
74+
git checkout 48786adc5bf9e9bcaea52147f09d6022ae14082c
75+
Pop-Location
76+
77+
&$NuGet restore bin\Newtonsoft.Json\Src\Newtonsoft.Json.Portable.sln -Verbosity quiet
78+
79+
.\bin\StyleCopTester-Roslyn.1.0.0\StyleCopTester.exe bin\Newtonsoft.Json\Src\Newtonsoft.Json.Portable.sln /all /log:bin\Newtonsoft.Json-1.0.0.txt | Out-Null
80+
.\bin\StyleCopTester-Roslyn.1.1.0\StyleCopTester.exe bin\Newtonsoft.Json\Src\Newtonsoft.Json.Portable.sln /all /log:bin\Newtonsoft.Json-1.1.0.txt | Out-Null
81+
.\bin\StyleCopTester-Roslyn.1.1.1\StyleCopTester.exe bin\Newtonsoft.Json\Src\Newtonsoft.Json.Portable.sln /all /log:bin\Newtonsoft.Json-1.1.1.txt | Out-Null
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
7+
<runtime>
8+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
9+
<dependentAssembly>
10+
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
11+
<bindingRedirect oldVersion="1.0.27.0-1.1.65535.65535" newVersion="1.1.37.0"/>
12+
</dependentAssembly>
13+
<dependentAssembly>
14+
<assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
15+
<bindingRedirect oldVersion="1.0.0.0-1.0.99.0" newVersion="1.1.0.0"/>
16+
</dependentAssembly>
17+
<dependentAssembly>
18+
<assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces.Desktop" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
19+
<bindingRedirect oldVersion="0.7.0.0-1.1.0.0" newVersion="1.1.0.0"/>
20+
</dependentAssembly>
21+
<dependentAssembly>
22+
<assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
23+
<bindingRedirect oldVersion="0.7.0.0-1.1.0.0" newVersion="1.1.0.0"/>
24+
</dependentAssembly>
25+
<dependentAssembly>
26+
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
27+
<bindingRedirect oldVersion="0.7.0.0-1.1.0.0" newVersion="1.1.0.0"/>
28+
</dependentAssembly>
29+
<dependentAssembly>
30+
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
31+
<bindingRedirect oldVersion="0.7.0.0-1.1.0.0" newVersion="1.1.0.0"/>
32+
</dependentAssembly>
33+
<dependentAssembly>
34+
<assemblyIdentity name="Microsoft.CodeAnalysis.VisualBasic" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
35+
<bindingRedirect oldVersion="0.7.0.0-1.1.0.0" newVersion="1.1.0.0"/>
36+
</dependentAssembly>
37+
<dependentAssembly>
38+
<assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
39+
<bindingRedirect oldVersion="0.7.0.0-1.1.0.0" newVersion="1.1.0.0"/>
40+
</dependentAssembly>
41+
</assemblyBinding>
42+
</runtime>
43+
</configuration>
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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.Linq;
9+
using System.Threading;
10+
using System.Threading.Tasks;
11+
using Helpers.ObjectPools;
12+
using Microsoft.CodeAnalysis;
13+
using Microsoft.CodeAnalysis.CodeActions;
14+
using Microsoft.CodeAnalysis.CodeFixes;
15+
using Microsoft.CodeAnalysis.CSharp;
16+
using Microsoft.CodeAnalysis.CSharp.Syntax;
17+
using StyleCop.Analyzers.Helpers;
18+
19+
/// <summary>
20+
/// Implements the code fix for property summary documentation.
21+
/// </summary>
22+
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(PropertySummaryDocumentationCodeFixProvider))]
23+
[Shared]
24+
public class PropertySummaryDocumentationCodeFixProvider : CodeFixProvider
25+
{
26+
/// <inheritdoc/>
27+
public override ImmutableArray<string> FixableDiagnosticIds { get; } =
28+
ImmutableArray.Create(
29+
PropertySummaryDocumentationAnalyzer.SA1623Descriptor.Id,
30+
PropertySummaryDocumentationAnalyzer.SA1624Descriptor.Id);
31+
32+
/// <inheritdoc/>
33+
public override FixAllProvider GetFixAllProvider()
34+
{
35+
return CustomFixAllProviders.BatchFixer;
36+
}
37+
38+
/// <inheritdoc/>
39+
public override Task RegisterCodeFixesAsync(CodeFixContext context)
40+
{
41+
foreach (Diagnostic diagnostic in context.Diagnostics)
42+
{
43+
if (!diagnostic.Properties.ContainsKey(PropertySummaryDocumentationAnalyzer.NoCodeFixKey))
44+
{
45+
context.RegisterCodeFix(
46+
CodeAction.Create(
47+
DocumentationResources.PropertySummaryStartTextCodeFix,
48+
cancellationToken => GetTransformedDocumentAsync(context.Document, diagnostic, cancellationToken),
49+
nameof(PropertySummaryDocumentationCodeFixProvider)),
50+
diagnostic);
51+
}
52+
}
53+
54+
return SpecializedTasks.CompletedTask;
55+
}
56+
57+
private static async Task<Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
58+
{
59+
var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
60+
61+
var node = syntaxRoot.FindNode(diagnostic.Location.SourceSpan);
62+
var documentation = node.GetDocumentationCommentTriviaSyntax();
63+
64+
var summaryElement = (XmlElementSyntax)documentation.Content.GetFirstXmlElement(XmlCommentHelper.SummaryXmlTag);
65+
var textElement = (XmlTextSyntax)summaryElement.Content.FirstOrDefault();
66+
if (textElement == null)
67+
{
68+
return document;
69+
}
70+
71+
var textToken = textElement.TextTokens.First(token => token.IsKind(SyntaxKind.XmlTextLiteralToken));
72+
var text = textToken.ValueText;
73+
74+
// preserve leading whitespace
75+
int index = 0;
76+
while (text.Length > index && char.IsWhiteSpace(text, index))
77+
{
78+
index++;
79+
}
80+
81+
var preservedWhitespace = text.Substring(0, index);
82+
83+
// process the current documentation string
84+
string modifiedText;
85+
string textToRemove;
86+
if (diagnostic.Properties.TryGetValue(PropertySummaryDocumentationAnalyzer.TextToRemoveKey, out textToRemove))
87+
{
88+
modifiedText = text.Substring(text.IndexOf(textToRemove) + textToRemove.Length).TrimStart();
89+
}
90+
else
91+
{
92+
modifiedText = text.Substring(index);
93+
}
94+
95+
if (modifiedText.Length > 0)
96+
{
97+
modifiedText = char.ToLowerInvariant(modifiedText[0]) + modifiedText.Substring(1);
98+
}
99+
100+
// create the new text string
101+
var textToAdd = diagnostic.Properties[PropertySummaryDocumentationAnalyzer.ExpectedTextKey];
102+
var newText = $"{preservedWhitespace}{textToAdd} {modifiedText}";
103+
104+
// replace the token
105+
var newXmlTextLiteral = SyntaxFactory.XmlTextLiteral(textToken.LeadingTrivia, newText, newText, textToken.TrailingTrivia);
106+
var newTextTokens = textElement.TextTokens.Replace(textToken, newXmlTextLiteral);
107+
var newTextElement = textElement.WithTextTokens(newTextTokens);
108+
109+
var newSyntaxRoot = syntaxRoot.ReplaceNode(textElement, newTextElement);
110+
var newDocument = document.WithSyntaxRoot(newSyntaxRoot);
111+
112+
return newDocument;
113+
}
114+
}
115+
}

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1626CodeFixProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ private class FixAll : DocumentBasedFixAllProvider
6868
protected override string CodeActionTitle =>
6969
DocumentationResources.SA1626CodeFix;
7070

71-
protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fixAllContext, Document document)
71+
protected override async Task<SyntaxNode> FixAllInDocumentAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> diagnostics)
7272
{
73-
var diagnostics = await fixAllContext.GetDocumentDiagnosticsAsync(document).ConfigureAwait(false);
7473
if (diagnostics.IsEmpty)
7574
{
7675
return null;

0 commit comments

Comments
 (0)