Skip to content

Commit f8ba4c0

Browse files
committed
Merge pull request #1802 from sharwell/known-changes
Add information about known changes
2 parents d4de0b6 + 3f3fc29 commit f8ba4c0

45 files changed

Lines changed: 396 additions & 43 deletions

Some content is hidden

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

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ 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

2225
StyleCopAnalyzers can be installed using the NuGet Package Manager in Visual Studio 2015.

StyleCopAnalyzers.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "documentation", "documentat
3535
ProjectSection(SolutionItems) = preProject
3636
documentation\Configuration.md = documentation\Configuration.md
3737
documentation\EnableConfiguration.md = documentation\EnableConfiguration.md
38+
documentation\KnownChanges.md = documentation\KnownChanges.md
3839
documentation\SA1000.md = documentation\SA1000.md
3940
documentation\SA1001.md = documentation\SA1001.md
4041
documentation\SA1002.md = documentation\SA1002.md

documentation/KnownChanges.md

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
# Known Changes
2+
3+
This document describes the known changes in behavior of StyleCop Analyzers relative to StyleCop Classic. The changes
4+
here meet all of the following conditions:
5+
6+
1. The change in behavior affects code for C# 5 or earlier. StyleCop Classic did not support C# 6, so the necessary
7+
changes made solely to support new language features are not considered here.
8+
2. The change in behavior is currently by-design. Unintentional changes in behavior are filed as bugs when they are
9+
discovered.
10+
3. The change affects a rule which was present in StyleCop Classic. New rules introduced for StyleCop Analyzers can
11+
be disabled for closer adherence to the behavior of StyleCop Classic.
12+
13+
In many cases, the change in behavior was simply a change to the documentation, where the StyleCop Classic
14+
implementation deviated from its own documented rules. For completeness, these changes are included below whenever we
15+
found them. The following symbol is used to mark cases which are not simply a documentation error:
16+
17+
> :warning: Cases where the StyleCop Analyzers implementation will produce different warnings from StyleCop Classic for
18+
the same code are marked with this symbol.
19+
20+
## Disabled Rules
21+
22+
Several rules present StyleCop Classic have been intentionally omitted from StyleCop Analyzers. The following table
23+
lists each of these issues, along with a link to the issue where the decision was made to omit the rule.
24+
25+
| ID | Title | Issue |
26+
| --- | --- | --- |
27+
| SA1109 | Block statements must not contain embedded regions | [#998](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/998) |
28+
| SA1126 | Prefix calls correctly | [#59](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/59) |
29+
| SA1409 | Remove unnecessary code | [#1058](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1058) |
30+
| SA1603 | Documentation must contain valid XML | [#1291](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1291) |
31+
| SA1628 | Documentation text must begin with a capital letter | [#1057](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1057) |
32+
| SA1630 | Documentation text must contain whitespace | [#1057](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1057) |
33+
| SA1631 | Documentation must meet character percentage | [#1057](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1057) |
34+
| SA1632 | Documentation text must meet minimum character length | [#1057](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1057) |
35+
| SA1645 | Included documentation file does not exist | [#165](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/165) |
36+
| SA1646 | Included documentation XPath does not exist | [#166](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/166) |
37+
| SA1647 | Include node does not contain valid file and path | [#167](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/167) |
38+
| SA1650 | Element documentation must be spelled correctly | [#1057](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1057) |
39+
40+
## Spacing Rules
41+
42+
### SA1000: Keywords must be spaced correctly
43+
44+
The following changes were made to SA1000:
45+
46+
1. :warning: A space is now required after `await` and `case`.
47+
48+
2. An exception to the requirement that a space follow the `throw` keyword was added when it appears in a re-throw
49+
statement. This exception was not mentioned in the documentation for StyleCop Classic.
50+
51+
```csharp
52+
throw;
53+
```
54+
55+
3. :warning: An exception to the requirement that a space follow the `new` keyword was added when it appears as a
56+
generic type constraint. StyleCop Classic did not check the spacing around the `new` keyword in a generic type
57+
constraint.
58+
59+
```csharp
60+
public void Foo<T>() where T : IInterface, new()
61+
{
62+
// ...
63+
}
64+
```
65+
66+
### SA1001
67+
68+
:warning: A slight change was made to the spacing around commas in open generic types. The following table demonstrates this
69+
change.
70+
71+
| StyleCop Analyzers | StyleCop Classic |
72+
| --- | --- |
73+
| `typeof(Func<,>)` | `typeof(Func<, >)` |
74+
75+
### SA1002
76+
77+
:warning: StyleCop Classic required an infinite `for` loop to be written as follows:
78+
79+
```csharp
80+
for (;;)
81+
{
82+
}
83+
```
84+
85+
StyleCop Analyzers reports SA1002 for this same code, and instead requires the code be written as follows:
86+
87+
```csharp
88+
for (; ;)
89+
{
90+
}
91+
```
92+
93+
:bulb: When this code is encountered, users are encouraged to rewrite the code as follows for enhanced readability:
94+
95+
```csharp
96+
while (true)
97+
{
98+
}
99+
```
100+
101+
### SA1003
102+
103+
:warning: StyleCop Classic allowed a type cast to appear at the end of a line, such as the following:
104+
105+
```csharp
106+
uint value = (uint)
107+
3;
108+
```
109+
110+
StyleCop Analyzers forbids this same case, requiring the following instead:
111+
112+
```csharp
113+
uint value = (uint)3;
114+
```
115+
116+
### SA1025
117+
118+
StyleCop Classic allowed multiple spaces to precede a comment placed at the end of a line, such as the following:
119+
120+
```csharp
121+
int x; // comment
122+
```
123+
124+
StyleCop Analyzers does not currently make an exception to the SA1025 rule for this case, although this decision is
125+
still under review.
126+
127+
## Readability Rules
128+
129+
### SA1110, SA1111, SA1113, SA1114
130+
131+
StyleCop Analyzers examines several constructs which are not mentioned in the original documentation for these rules:
132+
133+
* Delegate declarations
134+
* Anonymous method expressions
135+
* Lambda expressions
136+
137+
### SA1119
138+
139+
:warning: StyleCop Classic did not report SA1119 for the following code:
140+
141+
```csharp
142+
var a = (new[] { 1, 2, 3 }).ToArray();
143+
```
144+
145+
StyleCop Analyzers reports SA1119 for this same code, and requires the following change to correct it:
146+
147+
```csharp
148+
var a = new[] { 1, 2, 3 }.ToArray();
149+
```
150+
151+
## Ordering Rules
152+
153+
There are no known changes at this time.
154+
155+
## Naming Rules
156+
157+
### SA1305
158+
159+
This rule is disabled by default in StyleCop Analyzers, but can be enabled by users via a rule set file.
160+
161+
## Maintainability Rules
162+
163+
There are no known changes at this time.
164+
165+
## Layout Rules
166+
167+
### SA1515
168+
169+
:warning: The following code does not report a warning in StyleCop Classic:
170+
171+
```csharp
172+
[ContractClassFor(typeof(ILinkActivator<>))]
173+
// ReSharper disable once InconsistentNaming
174+
// Contract class containing only metadata pertaining to an interface.
175+
// Using naming convention adopted by the Code Contracts team for .NET framework contracts.
176+
public abstract class ILinkActivatorContract<T> : ILinkActivator<T> where T : LinkTemplate
177+
```
178+
179+
StyleCop Analyzers reports SA1515 for this code, and instead requires the following:
180+
181+
```csharp
182+
[ContractClassFor(typeof(ILinkActivator<>))]
183+
184+
// ReSharper disable once InconsistentNaming
185+
// Contract class containing only metadata pertaining to an interface.
186+
// Using naming convention adopted by the Code Contracts team for .NET framework contracts.
187+
public abstract class ILinkActivatorContract<T> : ILinkActivator<T> where T : LinkTemplate
188+
```
189+
190+
## Documentation Rules
191+
192+
### SA1642
193+
194+
StyleCop Analyzers requires the use of a `<see>` element when referencing the class name in the standard constructor
195+
text. In StyleCop Classic, this element was optional.
196+
197+
StyleCop Classic included a special case for constructor text used for `private` constructors. StyleCop Analyzers still
198+
allows users to use this wording in the documentation of private constructors, but prefers the use of the standard
199+
constructor text. When the code fix for SA1642 is applied to a private constructor, the inserted text will comply with
200+
StyleCop Analyzers but will result in a warning in StyleCop Classic. For example:
201+
202+
The following code does not produce a warning in StyleCop Classic or StyleCop Analyzers:
203+
204+
```csharp
205+
public class ApiStatus
206+
{
207+
/// <summary>
208+
/// Prevents a default instance of the <see cref="ApiStatus"/> class from being created.
209+
/// </summary>
210+
private ApiStatus()
211+
{
212+
}
213+
}
214+
```
215+
216+
:warning: The following code produces a warning in StyleCop Classic, but does not produce a warning in StyleCop Analyzers:
217+
218+
```csharp
219+
public class ApiStatus
220+
{
221+
/// <summary>
222+
/// Initializes a new instance of the <see cref="ApiStatus"/> class.
223+
/// </summary>
224+
private ApiStatus()
225+
{
226+
}
227+
}
228+
```
229+
230+
### SA1649
231+
232+
StyleCop Analyzers modified SA1649 to check the first type against the actual file name as opposed to checking against a
233+
value which appeared in the file header. For StyleCop Classic users who had both SA1638 and SA1649 enabled, this change
234+
does not produce any new warnings in code which previously complied with StyleCop.

documentation/SA1000.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ The spacing around a C# keyword is incorrect.
2323

2424
A violation of this rule occurs when the spacing around a keyword is incorrect.
2525

26-
The following C# keywords must always be followed by a single space: *catch, fixed, for, foreach, from, group, if, in, into, join, let, lock, orderby, return, select, stackalloc, switch, throw, using, where, while, yield*.
26+
The following C# keywords must always be followed by a single space: `await`, `case`, `catch`, `fixed`, `for`,
27+
`foreach`, `from`, `group`, `if`, `in`, `into`, `join`, `let`, `lock`, `orderby`, `return`, `select`, `stackalloc`,
28+
`switch`, `using`, `where`, `while`, `yield`.
2729

28-
The following keywords must not be followed by any space: *checked, default, sizeof, typeof, unchecked*.
30+
The following keywords must not be followed by any space: `checked`, `default`, `sizeof`, `typeof`, `unchecked`.
2931

30-
The *new* keyword should always be followed by a space, unless it is used to create a new array, in which case there should be no space between the *new* keyword and the opening array bracket.
32+
The `new` keyword should always be followed by a space, except in the following cases:
33+
34+
* The `new` keyword is used to create a new array. In this case there should be no space between the `new` keyword and
35+
the opening array bracket.
36+
* The `new` keyword is part of a generic type constraint. In this case there should be no space between the `new`
37+
keyword and the opening parenthesis.
38+
39+
The `throw` keyword should always be followed by a space, unless it is part of a re-throw statement, in which case there
40+
should be no space between the `throw` keyword and the semicolon.
3141

3242
## How to fix violations
3343

documentation/SA1001.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ The spacing around a comma is incorrect, within a C# code file.
2323

2424
A violation of this rule occurs when the spacing around a comma is incorrect.
2525

26-
A comma should always be followed by a single space, unless it is the last character on the line, and a comma should never be preceded by any whitespace.
26+
A comma should be followed by a single space, except in the following cases.
27+
28+
* A comma may appear at the end of a line
29+
* A comma should not be followed by a space when used in an open generic type in a `typeof` expression
30+
31+
A comma must never be preceded by a space or appear as the first token on a line.
2732

2833
## How to fix violations
2934

documentation/SA1002.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ The spacing around a semicolon is incorrect, within a C# code file.
2323

2424
A violation of this rule occurs when the spacing around a semicolon is incorrect.
2525

26-
A semicolon should always be followed by a single space, unless it is the last character on the line, and a semicolon should never be preceded by any whitespace, unless it is the first character on the line.
26+
A semicolon should always be followed by a single space, except in the following cases:
27+
28+
* The semicolon is the last character on the line
29+
* The semicolon followed by a closing parenthesis
30+
31+
A semicolon should never be preceded by any whitespace, unless it is the first character on the line.
2732

2833
## How to fix violations
2934

documentation/SA1003.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ The spacing around an operator symbol is incorrect, within a C# code file.
2323

2424
A violation of this rule occurs when the spacing around an operator symbol is incorrect.
2525

26-
The following types of operator symbols must be surrounded by a single space on either side: colons, arithmetic operators, assignment operators, conditional operators, logical operators, relational operators, shift operators, and lambda operators. For example:
26+
The following types of operator symbols must be surrounded by a single space on either side: colons, arithmetic
27+
operators, assignment operators, conditional operators, logical operators, relational operators, shift operators, and
28+
lambda operators. For example:
2729

2830
```csharp
2931
int x = 4 + y;
@@ -35,7 +37,8 @@ In contrast, unary operators must be preceded by a single space, but must never
3537
bool x = !value;
3638
```
3739

38-
An exception occurs whenever the symbol is preceded or followed by a parenthesis or bracket, in which case there should be no space between the symbol and the bracket. For example:
40+
An exception occurs whenever the symbol is preceded or followed by a parenthesis or bracket, in which case there should
41+
be no space between the symbol and the bracket. For example:
3942

4043
```csharp
4144
if (!value)

documentation/SA1025.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ The code contains multiple whitespace characters in a row.
2121

2222
## Rule description
2323

24-
A violation of this rule occurs whenever the code contains multiple whitespace characters in a row, unless the characters come at the beginning or end of a line of code,
25-
following a comma or semicolon or preceeding a symbol.
24+
A violation of this rule occurs whenever the code contains multiple whitespace characters in a row, unless the
25+
characters come at the beginning or end of a line of code, following a comma or semicolon or preceding a symbol.
2626

2727
## How to fix violations
2828

documentation/SA1028.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
</tr>
1616
</table>
1717

18+
:memo: This rule is new for StyleCop Analyzers, and was not present in StyleCop Classic.
19+
1820
## Cause
1921

2022
A line of code ends with a space, tab, or other whitespace characters before the end of line character(s).

documentation/SA1109.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
</tr>
1616
</table>
1717

18+
:warning: This rule has been intentionally omitted from StyleCop Analyzers. See [KnownChanges.md](KnownChanges.md) for
19+
additional information.
20+
1821
## Cause
1922

2023
A C# statement contains a region tag between the declaration of the statement and the opening brace of the statement.

0 commit comments

Comments
 (0)