Skip to content

Commit 23a9178

Browse files
committed
Merge remote-tracking branch 'DotNetAnalyzers/master' into fix-739
2 parents 3b18b2f + b934782 commit 23a9178

452 files changed

Lines changed: 19329 additions & 5004 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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ for information about known differences which you may notice when switching to S
2222

2323
## Installation
2424

25-
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.
2626

27+
**Install using the command line:**
28+
```bash
29+
Install-Package StyleCop.Analyzers
30+
```
31+
32+
**Install using the package manager:**
2733
![Install via nuget](https://cloud.githubusercontent.com/assets/1408396/8233513/491f301a-159c-11e5-8b7a-1e16a0695da6.png)
2834

2935
## Team Considerations
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>

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

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace StyleCop.Analyzers.DocumentationRules
55
{
66
using System;
7+
using System.Collections.Generic;
78
using System.Collections.Immutable;
89
using System.Composition;
910
using System.Text;
@@ -18,6 +19,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1819
using Microsoft.CodeAnalysis.Formatting;
1920
using StyleCop.Analyzers.Helpers;
2021
using StyleCop.Analyzers.Settings.ObjectModel;
22+
using Path = System.IO.Path;
2123

2224
/// <summary>
2325
/// Implements a code fix for file header diagnostics.
@@ -136,8 +138,9 @@ private static SyntaxNode ReplaceWellFormedMultiLineCommentHeader(Document docum
136138
// Pad line that used to be next to a /*
137139
triviaStringParts[0] = commentIndentation + interlinePadding + " " + triviaStringParts[0];
138140
StringBuilder sb = StringBuilderPool.Allocate();
141+
string fileName = Path.GetFileName(document.FilePath);
139142
var copyrightText = commentIndentation + interlinePadding + " " +
140-
GetCopyrightText(commentIndentation + interlinePadding, settings.DocumentationRules.CopyrightText, newLineText);
143+
GetCopyrightText(commentIndentation + interlinePadding, settings.DocumentationRules.GetCopyrightText(fileName), newLineText);
141144
var newHeader = WrapInXmlComment(commentIndentation + interlinePadding, copyrightText, document.Name, settings, newLineText);
142145

143146
sb.Append(commentIndentation);
@@ -212,6 +215,9 @@ private static SyntaxNode ReplaceHeader(Document document, SyntaxNode root, Styl
212215
var leadingSpaces = string.Empty;
213216
string possibleLeadingSpaces = string.Empty;
214217

218+
// remove header decoration lines, they will be re-generated
219+
trivia = RemoveHeaderDecorationLines(trivia, settings);
220+
215221
// Need to do this with index so we get the line endings correct.
216222
for (int i = 0; i < trivia.Count; i++)
217223
{
@@ -350,31 +356,71 @@ private static SyntaxNode AddHeader(Document document, SyntaxNode root, string n
350356
return root.WithLeadingTrivia(newTrivia);
351357
}
352358

353-
private static SyntaxTriviaList CreateNewHeader(string prefixWithLeadingSpaces, string filename, StyleCopSettings settings, string newLineText)
359+
private static SyntaxTriviaList CreateNewHeader(string prefixWithLeadingSpaces, string fileName, StyleCopSettings settings, string newLineText)
354360
{
355-
var copyrightText = prefixWithLeadingSpaces + " " + GetCopyrightText(prefixWithLeadingSpaces, settings.DocumentationRules.CopyrightText, newLineText);
361+
var copyrightText = prefixWithLeadingSpaces + " " + GetCopyrightText(prefixWithLeadingSpaces, settings.DocumentationRules.GetCopyrightText(fileName), newLineText);
356362
var newHeader = settings.DocumentationRules.XmlHeader
357-
? WrapInXmlComment(prefixWithLeadingSpaces, copyrightText, filename, settings, newLineText)
363+
? WrapInXmlComment(prefixWithLeadingSpaces, copyrightText, fileName, settings, newLineText)
358364
: copyrightText;
359365
return SyntaxFactory.ParseLeadingTrivia(newHeader);
360366
}
361367

362-
private static string WrapInXmlComment(string prefixWithLeadingSpaces, string copyrightText, string filename, StyleCopSettings settings, string newLineText)
368+
private static string WrapInXmlComment(string prefixWithLeadingSpaces, string copyrightText, string fileName, StyleCopSettings settings, string newLineText)
363369
{
364-
string encodedFilename = new XAttribute("t", filename).ToString().Substring(2).Trim('"');
370+
string encodedFilename = new XAttribute("t", fileName).ToString().Substring(2).Trim('"');
365371
string encodedCompanyName = new XAttribute("t", settings.DocumentationRules.CompanyName).ToString().Substring(2).Trim('"');
366372
string encodedCopyrightText = new XText(copyrightText).ToString();
367373

368-
return
374+
string copyrightString =
369375
$"{prefixWithLeadingSpaces} <copyright file=\"{encodedFilename}\" company=\"{encodedCompanyName}\">" + newLineText
370376
+ encodedCopyrightText + newLineText
371377
+ prefixWithLeadingSpaces + " </copyright>";
378+
379+
if (!string.IsNullOrEmpty(settings.DocumentationRules.HeaderDecoration))
380+
{
381+
return
382+
$"{prefixWithLeadingSpaces} {settings.DocumentationRules.HeaderDecoration}" + newLineText
383+
+ copyrightString + newLineText
384+
+ $"{prefixWithLeadingSpaces} {settings.DocumentationRules.HeaderDecoration}";
385+
}
386+
387+
return copyrightString;
372388
}
373389

374390
private static string GetCopyrightText(string prefixWithLeadingSpaces, string copyrightText, string newLineText)
375391
{
376392
copyrightText = copyrightText.Replace("\r\n", "\n");
377393
return string.Join(newLineText + prefixWithLeadingSpaces + " ", copyrightText.Split('\n')).Replace(prefixWithLeadingSpaces + " " + newLineText, prefixWithLeadingSpaces + newLineText);
378394
}
395+
396+
private static SyntaxTriviaList RemoveHeaderDecorationLines(SyntaxTriviaList trivia, StyleCopSettings settings)
397+
{
398+
if (!string.IsNullOrEmpty(settings.DocumentationRules.HeaderDecoration))
399+
{
400+
var decorationRemovalList = new List<int>();
401+
for (int i = 0; i < trivia.Count; i++)
402+
{
403+
var triviaLine = trivia[i];
404+
if (triviaLine.Kind() == SyntaxKind.SingleLineCommentTrivia && triviaLine.ToFullString().Contains(settings.DocumentationRules.HeaderDecoration))
405+
{
406+
decorationRemovalList.Add(i);
407+
408+
// also remove the line break
409+
if (i + 1 < trivia.Count && trivia[i + 1].Kind() == SyntaxKind.EndOfLineTrivia)
410+
{
411+
decorationRemovalList.Add(i + 1);
412+
}
413+
}
414+
}
415+
416+
// Remove decoration lines in reverse order.
417+
for (int i = decorationRemovalList.Count - 1; i >= 0; i--)
418+
{
419+
trivia = trivia.RemoveAt(decorationRemovalList[i]);
420+
}
421+
}
422+
423+
return trivia;
424+
}
379425
}
380426
}

0 commit comments

Comments
 (0)