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
# .NET 5 Quality Assurance coding rules and best practices
2
+
An opinionated set of files and configurations usefull to enforce coding best practices and uniformity in .NET 5 projects
3
+
4
+
# Usage
5
+
Just copy all the files into the root of your target solution and/or related subfolders as needed (if and when an override/extension is required).
6
+
7
+
If your root already contains one or more of these file, you will need to merge them manually.
8
+
9
+
10
+
# Root folder
11
+
This folder represents the root directory containing all the projects of the solution, and contains the following files:
12
+
13
+
-**Directory.Build.props** → This is the backbone gluing together the other configuration files. It defines the basic NuGet dependencies (and the related configuration files) applied to all the projects in the root folder and its subfolders.
14
+
-**.editorconfig** → Define an opinionated set of global rules applied to the editor and enforced into the build process via the Roslyn Analyzers referenced by _Directory.Build.props_:
-**Philips.CodeAnalysis.DuplicateCodeAnalyzer** → [NuGet](https://www.nuget.org/packages/Philips.CodeAnalysis.DuplicateCodeAnalyzer/) / [GitHub](https://github.com/philips-software/roslyn-analyzers). This analyzer is also parametrized using the _DuplicateCode.Allowed.txt_ file
19
+
-**Global.ruleset** → define the code styling rules enforced by StyleCop and its _StyleCop.Analyzers_ NuGet package ([NuGet](https://www.nuget.org/packages/StyleCop.Analyzers/) / [GitHub](https://github.com/DotNetAnalyzers/StyleCopAnalyzers))
20
+
-**BannedSymbols.txt** → the configuration file used by the Roslyn Analyzer _Microsoft.CodeAnalysis.BannedApiAnalyzers_ ([NuGet](https://www.nuget.org/packages/Microsoft.CodeAnalysis.BannedApiAnalyzers/) / [GitHub](https://github.com/dotnet/roslyn-analyzers))
21
+
-**DuplicateCode.Allowed.txt** → the file containing the exceptions allowed by the _Philips.CodeAnalysis.DuplicateCodeAnalyzer_ ([NuGet](https://www.nuget.org/packages/Philips.CodeAnalysis.DuplicateCodeAnalyzer/) / [GitHub](https://github.com/philips-software/roslyn-analyzers))
22
+
-**RiderInspectionSettings.xml** → the configuration file used by [JetBrains Rider](https://www.jetbrains.com/rider/) for the editor inspections
# CA1827: Do not use Count/LongCount when Any can be used
19
+
dotnet_diagnostic.CA1827.severity = error
20
+
21
+
# CA1828: Do not use CountAsync/LongCountAsync when AnyAsync can be used
22
+
dotnet_diagnostic.CA1828.severity = error
23
+
24
+
# CA1829: Use Length/Count property instead of Enumerable.Count method
25
+
dotnet_diagnostic.CA1829.severity = error
26
+
27
+
# CA1837: Use Environment.ProcessId instead of Process.GetCurrentProcess().Id
28
+
dotnet_diagnostic.CA1837.severity = error
29
+
30
+
# CA1505: Avoid unmaintainable code
31
+
dotnet_diagnostic.CA1505.severity = error
32
+
33
+
# CA1506: Avoid excessive class coupling
34
+
dotnet_diagnostic.CA1506.severity = warning
35
+
36
+
# CA1822: Mark members as static
37
+
dotnet_diagnostic.CA1822.severity = none
38
+
39
+
# CA2227: Collection properties should be read only
40
+
dotnet_diagnostic.CA2227.severity = none
41
+
42
+
# CA2007: Consider calling ConfigureAwait on the awaited task
43
+
dotnet_diagnostic.CA2007.severity = error
44
+
45
+
# CA1707: Identifiers should not contain underscores
46
+
dotnet_diagnostic.CA1707.severity = none
47
+
48
+
# CA1031: Do not catch general exception types
49
+
dotnet_diagnostic.CA1031.severity = none
50
+
51
+
# CA1040: Avoid empty interfaces
52
+
dotnet_diagnostic.CA1040.severity = none
53
+
54
+
# CA1052: Type is a static holder type but is neither static nor NotInheritable
55
+
dotnet_diagnostic.CA1052.severity = error
56
+
57
+
# CA1056: URI-like properties should not be strings
58
+
dotnet_diagnostic.CA1056.severity = none
59
+
60
+
# CA1308: Normalize strings to uppercase
61
+
dotnet_diagnostic.CA1308.severity = none
62
+
63
+
# CA1032: Implement standard exception constructors
64
+
dotnet_diagnostic.CA1032.severity = none
65
+
66
+
# CA1801: Review unused parameters
67
+
dotnet_diagnostic.CA1801.severity = none
68
+
69
+
# CA1720: Identifier contains type name
70
+
dotnet_diagnostic.CA1720.severity = suggestion
71
+
72
+
# CA1721: Property names should not match get methods
73
+
dotnet_diagnostic.CA1721.severity = none
74
+
75
+
# CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the await operator to the result of the call.
76
+
dotnet_diagnostic.CS4014.severity = error
77
+
78
+
# CA1805: Do not initialize unnecessarily
79
+
dotnet_diagnostic.CA1805.severity = error
80
+
81
+
# CA2213: Disposable fields should be disposed
82
+
dotnet_diagnostic.CA2213.severity = error
83
+
84
+
# CS0168: Variable is declared but never used
85
+
dotnet_diagnostic.CS0168.severity = error
86
+
87
+
# CA1062: In externally visible method validate parameter is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.
88
+
dotnet_diagnostic.CA1062.severity = error
89
+
90
+
# CA1810: Initialize reference type static fields inline
91
+
dotnet_diagnostic.CA1810.severity = error
92
+
93
+
# CA1310: Specify StringComparison for correctness
94
+
dotnet_diagnostic.CA1310.severity = error
95
+
96
+
# CA1716: Rename virtual/interface member so that it no longer conflicts with the reserved language keyword 'Call'. Using a reserved keyword as the name of a virtual/interface member makes it harder for consumers in other languages to override/implement the member.
97
+
dotnet_diagnostic.CA1716.severity = suggestion
98
+
99
+
# LindhartAnalyserMissingAwaitWarning: Possible missing await keyword
# CA1054: URI-like parameters should not be strings
103
+
dotnet_diagnostic.CA1054.severity = suggestion
104
+
105
+
# VSTHRD100: Avoid async void methods
106
+
dotnet_diagnostic.VSTHRD100.severity = error
107
+
108
+
# VSTHRD101: Avoid unsupported async delegates
109
+
dotnet_diagnostic.VSTHRD101.severity = error
110
+
111
+
# VSTHRD110: Observe result of async calls
112
+
dotnet_diagnostic.VSTHRD110.severity = error
113
+
114
+
# VSTHRD114: Avoid returning a null Task
115
+
dotnet_diagnostic.VSTHRD114.severity = error
116
+
117
+
# VSTHRD200: Use "Async" suffix for async methods
118
+
dotnet_diagnostic.VSTHRD200.severity = none
119
+
120
+
# IDE0005: Using directive is unnecessary.
121
+
dotnet_diagnostic.IDE0005.severity = error
122
+
123
+
# CA2016: Forward the CancellationToken parameter to methods that take one
124
+
dotnet_diagnostic.CA2016.severity = error
125
+
126
+
# CA1825: Avoid zero-length array allocations
127
+
dotnet_diagnostic.CA1825.severity = error
128
+
129
+
# CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
130
+
dotnet_diagnostic.CS1998.severity = error
131
+
132
+
# CA1068: CancellationToken parameters must come last
133
+
dotnet_diagnostic.CA1068.severity = error
134
+
135
+
# VSTHRD103: Result synchronously blocks. Use await instead.
136
+
dotnet_diagnostic.VSTHRD103.severity = error
137
+
138
+
# CA2211: Non-constant fields should not be visible
139
+
dotnet_diagnostic.CA2211.severity = error
140
+
141
+
# CA1051: Do not declare visible instance fields
142
+
dotnet_diagnostic.CA1051.severity = error
143
+
144
+
# VSTHRD002: Synchronously waiting on tasks or awaiters may cause deadlocks. Use await or JoinableTaskFactory.Run instead.
145
+
dotnet_diagnostic.VSTHRD002.severity = error
146
+
147
+
# NU1603: A package dependency specified a version that could not be found. Typically, the package sources do not contain the expected lower bound version. A higher version was used instead, which differs from what the package was authored against.
# CA1063: Provide an overridable implementation of Dispose(bool) or mark the type as sealed. A call to Dispose(false) should only clean up native resources. A call to Dispose(true) should clean up both managed and native resources. Modify the class so that it calls Dispose(true), then calls GC.SuppressFinalize on the current object instance ('this' or 'Me' in Visual Basic), and then returns
154
+
dotnet_diagnostic.CA1063.severity = error
155
+
156
+
# CA1819: Properties should not return arrays
157
+
dotnet_diagnostic.CA1819.severity = suggestion
158
+
159
+
# CA1028: If possible, make the underlying type System.Int32 instead of long
160
+
dotnet_diagnostic.CA1028.severity = suggestion
161
+
162
+
# CA1717: Only FlagsAttribute enums should have plural names
163
+
dotnet_diagnostic.CA1717.severity = suggestion
164
+
165
+
# RS0030: Don't use DateTime.Now in a i18n-compliant system. Use DateTime.UtcNow instead
166
+
dotnet_diagnostic.RS0030.severity = error
167
+
168
+
# PH2071: Duplicated shape found
169
+
dotnet_diagnostic.PH2071.severity = suggestion
170
+
dotnet_diagnostic.PH2071.token_count=80
171
+
dotnet_code_quality.PH2071.severity = suggestion
172
+
dotnet_code_quality.PH2071.token_count=80
173
+
174
+
# CA1713: Events should not have 'Before' or 'After' prefix
175
+
dotnet_diagnostic.CA1713.severity = suggestion
176
+
177
+
# CS0108: Use the new keyword if hiding was intended.
178
+
dotnet_diagnostic.CS0108.severity = suggestion
179
+
180
+
# CA1303 Method passes a literal string as parameter 'format' of a call to. Retrieve the following string(s) from a resource table instead:
181
+
dotnet_diagnostic.CA1303.severity = suggestion
182
+
183
+
# CA1724: The type name conflicts in whole or in part with the namespace name. Change either name to eliminate the conflict.
184
+
dotnet_diagnostic.CA1724.severity = suggestion
185
+
186
+
# CA1001: Types that own disposable fields should be disposable
187
+
dotnet_diagnostic.CA1001.severity = error
188
+
189
+
# CA2213: Disposable fields should be disposed
190
+
dotnet_diagnostic.CA2213.severity = error
191
+
192
+
# CA2100: Review SQL queries for security vulnerabilities
P:System.DateTime.Now;In a i18n-compliant system, it's almost never a good idea to use System.DateTime.Now. Please use System.DateTime.UtcNow instead. If you are sure you want to use System.DateTime.Now, use a '#pragma warning disable RS0030 / #pragma warning restore RS0030' directives pair
2
+
P:System.Threading.Tasks.Task.Id;The `Task.Id` property is rarely used, and in some scenarios it can be easily confused with the integer value returned by an invoked method. This is an example of possible misusage/confusion: `var expectedIntValue = MethodInvokedAsync().Id;` instead of `var expectedIntValue = (await MethodInvokedAsync()).Id;` or `var expectedIntValue = await MethodInvokedAsync();`. In this scenario `expectedIntValue` contains the value of the Id of the task instead of the legitimate value returned by the invoked method. If you are sure you want to use `Task.Id`, use a '#pragma warning disable RS0030 / #pragma warning restore RS0030' directives pair.
0 commit comments