You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: documentation/Configuration.md
+108-24
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Configuring StyleCop Analyzers
2
2
3
-
StyleCop Analyzers is configured using two separate mechanisms: code analysis rule set files, and **stylecop.json**.
3
+
StyleCop Analyzers can be configured using multiple separate mechanisms:
4
4
5
5
1. Code analysis rule set files
6
6
@@ -12,7 +12,11 @@ StyleCop Analyzers is configured using two separate mechanisms: code analysis ru
12
12
* Specify project-specific text, such as the name of the company and the structure to use for copyright headers
13
13
* Fine-tune the behavior of certain rules
14
14
15
-
Code analysis rule sets are the standard way to configure most diagnostic analyzers within Visual Studio. Information about creating and customizing these files can be found in the [Using Rule Sets to Group Code Analysis Rules](https://docs.microsoft.com/visualstudio/code-quality/using-rule-sets-to-group-code-analysis-rules) documentation on docs.microsoft.com.
15
+
3.**.editorconfig**
16
+
17
+
* Can be used in place of rule set files and **stylecop.json**
18
+
19
+
Code analysis rule sets have been the standard way to configure most diagnostic analyzers within Visual Studio. Information about creating and customizing these files can be found in the [Using Rule Sets to Group Code Analysis Rules](https://docs.microsoft.com/visualstudio/code-quality/using-rule-sets-to-group-code-analysis-rules) documentation on docs.microsoft.com.
16
20
17
21
An example rule set file containing the default StyleCop Analyzers configuration is available at <https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/rulesets/StyleCopAnalyzersDefault.ruleset>.
18
22
@@ -47,8 +51,7 @@ For best results, **stylecop.json** should be included in source control. This w
47
51
48
52
## Indentation
49
53
50
-
This section describes the indentation rules which can be configured in **stylecop.json**. Each of the described
51
-
properties are configured in the `indentation` object, which is shown in the following sample file.
54
+
This section describes the indentation rules which can be configured in **stylecop.json** or **.editorconfig**. Each of the described properties can be configured in the `indentation` object of the **stylecop.json** file, which is shown in the following sample.
52
55
53
56
```json
54
57
{
@@ -61,22 +64,22 @@ properties are configured in the `indentation` object, which is shown in the fol
61
64
62
65
### Basic Indentation
63
66
64
-
The following properties are used to configure basic indentation in StyleCop Analyzers.
67
+
The following properties are used in **stylecop.json**to configure basic indentation in StyleCop Analyzers.
65
68
66
69
| Property | Default Value | Minimum Version | Summary |
67
70
| --- | --- | --- | --- |
68
71
|`indentationSize`|**4**| 1.1.0 | The number of columns to use for each indentation of code. Depending on the `useTabs` and `tabSize` settings, this will be filled with tabs and/or spaces. |
69
72
|`tabSize`|**4**| 1.1.0 | The width of a hard tab character in source code. This value is used when converting between tabs and spaces. |
70
73
|`useTabs`|**false**| 1.1.0 |**true** to indent using hard tabs; otherwise, **false** to indent using spaces |
71
74
75
+
When using an **.editorconfig** file to configure StyleCop Analyzers, the basic indentation settings (`indent_size`, `tab_width` and `indent_style`) as described at editorconfig.org can be used.
72
76
> :bulb: When working in Visual Studio, the IDE will not automatically adjust editor settings according to the values in
73
-
> **stylecop.json**. To provide this functionality as well, we recommend duplicating the basic indentation settings in a
74
-
> [**.editorconfig**](http://editorconfig.org/) file. Users of the [EditorConfig](https://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328)
77
+
> **stylecop.json**. To provide this functionality, we recommend using the **.editorconfig** file instead. Users of the [EditorConfig](https://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328)
75
78
> extension for Visual Studio will not need to update their C# indentation settings in order to match your project style.
76
79
77
80
## Spacing Rules
78
81
79
-
This section describes the features of spacing rules which can be configured in **stylecop.json**. Each of the described properties are configured in the `spacingRules` object, which is shown in the following sample file.
82
+
This section describes the features of spacing rules which can be configured in **stylecop.json** or **.editorconfig**. Each of the described properties are configured in the `spacingRules` object of the **stylecop.json** file, which is shown in the following sample.
80
83
81
84
```json
82
85
{
@@ -91,7 +94,7 @@ This section describes the features of spacing rules which can be configured in
91
94
92
95
## Readability Rules
93
96
94
-
This section describes the features of readability rules which can be configured in **stylecop.json**. Each of the described properties are configured in the `readabilityRules` object, which is shown in the following sample file.
97
+
This section describes the features of readability rules which can be configured in **stylecop.json** or **.editorconfig**. Each of the described properties are configured in the `readabilityRules` object of the **stylecop.json** file, which is shown in the following sample.
95
98
96
99
```json
97
100
{
@@ -104,6 +107,8 @@ This section describes the features of readability rules which can be configured
104
107
105
108
### Aliases for Built-In Types
106
109
110
+
The following property is used in **stylecop.json** to configure aliases for built-in types.
111
+
107
112
| Property | Default Value | Minimum Version | Summary |
108
113
| --- | --- | --- | --- |
109
114
|`allowBuiltInTypeAliases`|**false**| 1.1.0-beta007 | Specifies whether aliases are allowed for built-in types. |
The `allowBuiltInTypeAliases` configuration property can be set to `true` to allow cases like this while continuing to report diagnostics for direct references to the metadata type name, `Int32`.
120
125
126
+
When using an **.editorconfig** file to configure StyleCop Analyzers, the following property can be used:
This section describes the features of ordering rules which can be configured in **stylecop.json**. Each of the described properties are configured in the `orderingRules` object, which is shown in the following sample file.
133
+
This section describes the features of ordering rules which can be configured in **stylecop.json** or **.editorconfig**. Each of the described properties are configured in the `orderingRules` object of the **stylecop.json** file, which is shown in the following sample.
124
134
125
135
```json
126
136
{
@@ -133,7 +143,7 @@ This section describes the features of ordering rules which can be configured in
133
143
134
144
### Element Order
135
145
136
-
The following properties are used to configure element ordering in StyleCop Analyzers.
146
+
The following properties are used in **stylecop.json**to configure element ordering in StyleCop Analyzers.
137
147
138
148
| Property | Default Value | Minimum Version | Summary |
139
149
| --- | --- | --- | --- |
@@ -194,16 +204,25 @@ rules remain enforced.
194
204
}
195
205
```
196
206
207
+
> :bulb: This property can currently not be set in an **.editorconfig** file.
208
+
197
209
### Using Directives
198
210
199
-
The following properties are used to configure using directives in StyleCop Analyzers.
211
+
The following properties are used in **stylecop.json**to configure using directives in StyleCop Analyzers.
200
212
201
213
| Property | Default Value | Minimum Version | Summary |
202
214
| --- | --- | --- | --- |
203
215
|`systemUsingDirectivesFirst`| true | 1.0.0 | Specifies whether `System` using directives are placed before other using directives |
204
216
|`usingDirectivesPlacement`|`"insideNamespace"`| 1.0.0 | Specifies the desired placement of using directives |
205
217
|`blankLinesBetweenUsingGroups`|`"allow"`| 1.1.0 | Specifies is blank lines are required to separate groups of using statements |
206
218
219
+
When using an **.editorconfig** file to configure StyleCop Analyzers, the respective properties for [formatting .NET/C#](https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/formatting-rules) can be used:
The `usingDirectivesPlacement` property affects the behavior of the following rules which report incorrectly placed
@@ -281,7 +300,7 @@ In this mode, a blank line between groups for using directives is *not allowed*.
281
300
282
301
## Naming Rules
283
302
284
-
This section describes the features of naming rules which can be configured in **stylecop.json**. Each of the described properties are configured in the `namingRules` object, which is shown in the following sample file.
303
+
This section describes the features of naming rules which can be configured in **stylecop.json** or **.editorconfig**. Each of the described properties are configured in the `namingRules` object of the **stylecop.json** file, which is shown in the following sample.
285
304
286
305
```json
287
306
{
@@ -294,7 +313,7 @@ This section describes the features of naming rules which can be configured in *
294
313
295
314
### Hungarian Notation
296
315
297
-
The following properties are used to configure allowable Hungarian notation prefixes in StyleCop Analyzers.
316
+
The following properties are used in **stylecop.json**to configure allowable Hungarian notation prefixes in StyleCop Analyzers.
298
317
299
318
| Property | Default Value | Minimum Version | Summary |
300
319
| --- | --- | --- | --- |
@@ -316,9 +335,15 @@ The following example shows a settings file which allows the common prefixes as
316
335
}
317
336
```
318
337
338
+
When using an **.editorconfig** file to configure StyleCop Analyzers, the following properties can be used:
The `tupleElementNameCasing` property affects the behavior of the [SA1316 Tuple element names should use correct casing](SA1316.md) analyzer.
367
402
@@ -376,7 +411,7 @@ In this mode, tuple element names must start with an uppercase letter.
376
411
377
412
## Maintainability Rules
378
413
379
-
This section describes the features of maintainability rules which can be configured in **stylecop.json**. Each of the described properties are configured in the `maintainabilityRules` object, which is shown in the following sample file.
414
+
This section describes the features of maintainability rules which can be configured in **stylecop.json** or **.editorconfig**. Each of the described properties are configured in the `maintainabilityRules` object of the **stylecop.json** file, which is shown in the following sample.
380
415
381
416
```json
382
417
{
@@ -387,7 +422,7 @@ This section describes the features of maintainability rules which can be config
387
422
}
388
423
```
389
424
390
-
The following properties are used to configure maintainability rules in StyleCop Analyzers.
425
+
The following properties are used in **stylecop.json**to configure maintainability rules in StyleCop Analyzers.
391
426
392
427
| Property | Default Value | Minimum Version | Summary |
393
428
| --- | --- | --- | --- |
@@ -401,9 +436,11 @@ according to rule SA1402. The following types are supported:
401
436
*`enum`
402
437
*`delegate`
403
438
439
+
> :bulb: This property can currently not be set in an **.editorconfig** file.
440
+
404
441
## Layout Rules
405
442
406
-
This section describes the features of layout rules which can be configured in **stylecop.json**. Each of the described properties are configured in the `layoutRules` object, which is shown in the following sample file.
443
+
This section describes the features of layout rules which can be configured in **stylecop.json** or **.editorconfig**. Each of the described properties are configured in the `layoutRules` object of the **stylecop.json** file, which is shown in the following sample.
407
444
408
445
```json
409
446
{
@@ -414,14 +451,20 @@ This section describes the features of layout rules which can be configured in *
414
451
}
415
452
```
416
453
417
-
The following properties are used to configure layout rules in StyleCop Analyzers.
454
+
The following properties are used in **stylecop.json**to configure layout rules in StyleCop Analyzers.
418
455
419
456
| Property | Default Value | Minimum Version | Summary |
420
457
| --- | --- | --- | --- |
421
458
|`newlineAtEndOfFile`|`"allow"`| 1.0.0 | Specifies the handling for newline characters which appear at the end of a file |
422
459
|`allowConsecutiveUsings`|`true`| 1.1.0 | Specifies if SA1519 will allow consecutive using statements without braces |
423
460
|`allowDoWhileOnClosingBrace`|`false`| >1.2.0 | Specifies if SA1500 will allow the `while` expression of a `do`/`while` loop to be on the same line as the closing brace, as is generated by the default code snippet of Visual Studio |
424
461
462
+
When using an **.editorconfig** file to configure StyleCop Analyzers, the newline setting (`insert_final_newline`) as described at editorconfig.org can be used, and the following additional properties:
The behavior of [SA1518](SA1518.md) can be customized regarding the manner in which newline characters at the end of a
@@ -451,7 +494,7 @@ The behavior of [SA1500](SA1500.md) can be customized regarding the manner in wh
451
494
452
495
## Documentation Rules
453
496
454
-
This section describes the features of documentation rules which can be configured in **stylecop.json**. Each of the described properties are configured in the `documentationRules` object, which is shown in the following sample file.
497
+
This section describes the features of documentation rules which can be configured in **stylecop.json** or **.editorconfig**. Each of the described properties are configured in the `documentationRules` object of the **stylecop.json** file, which is shown in the following sample.
455
498
456
499
```json
457
500
{
@@ -464,7 +507,7 @@ This section describes the features of documentation rules which can be configur
464
507
465
508
### Copyright Headers
466
509
467
-
The following properties are used to configure copyright headers in StyleCop Analyzers.
510
+
The following properties are used in **stylecop.json**to configure copyright headers in StyleCop Analyzers.
468
511
469
512
| Property | Default Value | Minimum Version | Summary |
470
513
| --- | --- | --- | --- |
@@ -474,6 +517,18 @@ The following properties are used to configure copyright headers in StyleCop Ana
474
517
|`variables`| n/a | 1.0.0 | Specifies replacement variables which can be referenced in the `copyrightText` value |
475
518
|`headerDecoration`| n/a | 1.1.0 | This value can be set to add a decoration for the header comment so headers look similar to the ones generated by the StyleCop Classic ReSharper fix |
476
519
520
+
When using an **.editorconfig** file to configure StyleCop Analyzers, the following properties can be used:
> :memo: Instead of `stylecop.documentation.copyrightText` the `file_header_template` property as described in [IDE0073 (Require file header)](https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0073) can be used. However the StyleCop specific property will take precedence.
529
+
530
+
> :bulb: The `variables` property can currently not be set in an **.editorconfig** file.
531
+
477
532
#### Configuring Copyright Text
478
533
479
534
In order to successfully use StyleCop-checked file headers, most projects will need to configure the `companyName`
@@ -602,6 +657,15 @@ The following example shows a configuration file which requires developers to do
602
657
}
603
658
```
604
659
660
+
When using an **.editorconfig** file to configure StyleCop Analyzers, the following properties can be used:
Some documentation rules require summary texts to start with specific strings. To allow teams to document their code in their native language, **stylecop.json** contains the `documentationCulture` property.
@@ -640,9 +704,19 @@ The following values are currently supported. Unsupported values will automatica
640
704
}
641
705
```
642
706
707
+
When using an **.editorconfig** file to configure StyleCop Analyzers, the following property can be used:
The `fileNamingConvention` property will determine how the [SA1649 File name should match type name](SA1649.md) analyzer will check file names.
714
+
The `fileNamingConvention` property in **stylecop.json** will determine how the [SA1649 File name should match type name](SA1649.md) analyzer will check file names.
715
+
716
+
| Property | Default Value | Minimum Version | Summary |
717
+
| --- | --- | --- | --- |
718
+
|`fileNamingConvention`|`"stylecop"`| 1.0.0 | Specifies the convention for file names of generics. |
The [SA1629 Documentation Text Must End With A Period](SA1629.md) analyzer checks if sections within XML documentation end with a period. The following properties can be used to control the behavior of the analyzer:
742
+
The [SA1629 Documentation Text Must End With A Period](SA1629.md) analyzer checks if sections within XML documentation end with a period. The following properties can be used in **stylecop.json**to control the behavior of the analyzer:
664
743
665
744
| Property | Default Value | Minimum Version | Summary |
666
745
| --- | --- | --- | --- |
667
746
|`excludeFromPunctuationCheck`|`[ "seealso" ]`| 1.1.0 | Specifies the top-level tags within XML documentation that will be excluded from analysis. |
668
747
748
+
When using an **.editorconfig** file to configure StyleCop Analyzers, the following property can be used:
It is possible to define your preferred configuration once and reuse it across multiple independent projects. This involves rolling out your own NuGet package,
0 commit comments