|
| 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. |
0 commit comments