Skip to content

Commit 20dc72a

Browse files
Federico ColettoFederico Coletto
Federico Coletto
authored and
Federico Coletto
committed
Added root contents
1 parent 8f5e87c commit 20dc72a

7 files changed

+681
-0
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# .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_:
15+
- **Lindhart.Analyser.MissingAwaitWarning**[NuGet](https://www.nuget.org/packages/Lindhart.Analyser.MissingAwaitWarning/) / [GitHub](https://github.com/ykoksen/unused-task-warning)
16+
- **Microsoft.CodeAnalysis.FxCopAnalyzers**[NuGet](https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers/) / [GitHub](https://github.com/dotnet/roslyn-analyzers)
17+
- **Microsoft.VisualStudio.Threading.Analyzers**[NuGet](https://www.nuget.org/packages/Microsoft.VisualStudio.Threading.Analyzers/) / [GitHub](https://github.com/Microsoft/vs-threading)
18+
- **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

Root/.editorconfig

+345
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,345 @@
1+
[*.cs]
2+
3+
# CA1806: Do not ignore method results
4+
dotnet_diagnostic.CA1806.severity = error
5+
6+
# CA1305: Specify IFormatProvider
7+
dotnet_diagnostic.CA1305.severity = error
8+
9+
# CA1304: Specify CultureInfo
10+
dotnet_diagnostic.CA1304.severity = error
11+
12+
# CA1816: Call GC.SuppressFinalize correctly
13+
dotnet_diagnostic.CA1816.severity = error
14+
15+
# CA1823: Avoid unused private fields
16+
dotnet_diagnostic.CA1823.severity = error
17+
18+
# 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
100+
dotnet_diagnostic.LindhartAnalyserMissingAwaitWarning.severity = error
101+
102+
# 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.
148+
dotnet_diagnostic.NU1603.severity = suggestion
149+
150+
# CA2208: Instantiate argument exceptions correctly
151+
dotnet_diagnostic.CA2208.severity = error
152+
153+
# 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
193+
dotnet_diagnostic.CA2100.severity = error
194+
195+
indent_style = space
196+
indent_size = 3
197+
tab_width = 1
198+
199+
# Microsoft .NET properties
200+
csharp_new_line_before_members_in_object_initializers = false
201+
csharp_preferred_modifier_order = public, private, protected, internal, new, abstract, virtual, sealed, override, static, readonly, extern, unsafe, volatile, async:suggestion
202+
csharp_style_var_elsewhere = true:suggestion
203+
csharp_style_var_for_built_in_types = true:suggestion
204+
csharp_style_var_when_type_is_apparent = true:suggestion
205+
206+
dotnet_naming_rule.constants_rule.severity = warning
207+
dotnet_naming_rule.constants_rule.style = all_upper
208+
dotnet_naming_rule.constants_rule.symbols = constants_symbols
209+
dotnet_naming_rule.private_constants_rule.severity = warning
210+
dotnet_naming_rule.private_constants_rule.style = all_upper
211+
dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols
212+
dotnet_naming_rule.private_static_readonly_rule.severity = warning
213+
dotnet_naming_rule.private_static_readonly_rule.style = lower_camel_case_style
214+
dotnet_naming_rule.private_static_readonly_rule.symbols = private_static_readonly_symbols
215+
dotnet_naming_rule.public_fields_rule.severity = warning
216+
dotnet_naming_rule.public_fields_rule.style = upper_camel_case_style
217+
dotnet_naming_rule.public_fields_rule.symbols = public_fields_symbols
218+
dotnet_naming_rule.static_readonly_rule.severity = warning
219+
dotnet_naming_rule.static_readonly_rule.style = upper_camel_case_style
220+
dotnet_naming_rule.static_readonly_rule.symbols = static_readonly_symbols
221+
dotnet_naming_style.lower_camel_case_style.capitalization = camel_case
222+
dotnet_naming_style.lower_camel_case_style.required_prefix = _
223+
dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case
224+
dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected
225+
dotnet_naming_symbols.constants_symbols.applicable_kinds = field
226+
dotnet_naming_symbols.constants_symbols.required_modifiers = const
227+
dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private
228+
dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field
229+
dotnet_naming_symbols.private_constants_symbols.required_modifiers = const
230+
dotnet_naming_symbols.private_static_readonly_symbols.applicable_accessibilities = private
231+
dotnet_naming_symbols.private_static_readonly_symbols.applicable_kinds = field
232+
dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static,readonly
233+
dotnet_naming_symbols.public_fields_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected
234+
dotnet_naming_symbols.public_fields_symbols.applicable_kinds = field
235+
dotnet_naming_symbols.static_readonly_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected
236+
dotnet_naming_symbols.static_readonly_symbols.applicable_kinds = field
237+
dotnet_naming_symbols.static_readonly_symbols.required_modifiers = static,readonly
238+
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
239+
dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none
240+
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none
241+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
242+
dotnet_style_predefined_type_for_member_access = true:suggestion
243+
dotnet_style_qualification_for_event = false:suggestion
244+
dotnet_style_qualification_for_field = false:suggestion
245+
dotnet_style_qualification_for_method = false:suggestion
246+
dotnet_style_qualification_for_property = false:suggestion
247+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
248+
249+
# ReSharper properties
250+
resharper_autodetect_indent_settings = true
251+
resharper_cpp_indent_size = 4
252+
resharper_cpp_tab_width = 4
253+
resharper_csharp_indent_size = 3
254+
resharper_csharp_max_line_length = 175
255+
resharper_csharp_naming_rule.constants = AaBb, AA_BB
256+
resharper_csharp_naming_rule.private_constants = AaBb
257+
resharper_csharp_naming_rule.public_fields = AaBb, AA_BB
258+
resharper_csharp_naming_rule.static_readonly = AaBb
259+
resharper_csharp_place_type_constraints_on_same_line = false
260+
resharper_csharp_tab_width = 1
261+
resharper_csharp_wrap_after_declaration_lpar = true
262+
resharper_csharp_wrap_after_invocation_lpar = true
263+
resharper_csharp_wrap_arguments_style = chop_if_long
264+
resharper_csharp_wrap_before_first_type_parameter_constraint = true
265+
resharper_csharp_wrap_extends_list_style = chop_if_long
266+
resharper_csharp_wrap_parameters_style = chop_if_long
267+
resharper_html_indent_size = 4
268+
resharper_html_tab_width = 4
269+
resharper_max_formal_parameters_on_line = 5
270+
resharper_max_invocation_arguments_on_line = 4
271+
resharper_place_simple_anonymousmethod_on_single_line = false
272+
resharper_resx_indent_size = 4
273+
resharper_resx_tab_width = 4
274+
resharper_show_autodetect_configure_formatting_tip = false
275+
resharper_use_indent_from_vs = false
276+
resharper_vb_indent_size = 4
277+
resharper_vb_tab_width = 4
278+
resharper_wrap_after_dot_in_method_calls = true
279+
resharper_wrap_chained_binary_expressions = chop_if_long
280+
resharper_wrap_chained_method_calls = chop_if_long
281+
resharper_xmldoc_indent_size = 4
282+
resharper_xmldoc_tab_width = 4
283+
resharper_xml_indent_size = 4
284+
resharper_xml_tab_width = 4
285+
286+
# ReSharper inspection severities
287+
resharper_arrange_redundant_parentheses_highlighting = hint
288+
resharper_arrange_this_qualifier_highlighting = hint
289+
resharper_arrange_type_member_modifiers_highlighting = hint
290+
resharper_arrange_type_modifiers_highlighting = hint
291+
resharper_built_in_type_reference_style_for_member_access_highlighting = hint
292+
resharper_built_in_type_reference_style_highlighting = hint
293+
resharper_heap_view_boxing_allocation_highlighting = none
294+
resharper_heap_view_closure_allocation_highlighting = none
295+
resharper_heap_view_delegate_allocation_highlighting = none
296+
resharper_heap_view_object_allocation_evident_highlighting = none
297+
resharper_heap_view_object_allocation_highlighting = none
298+
resharper_identifier_typo_highlighting = none
299+
resharper_razor_section_not_resolved_highlighting = none
300+
resharper_redundant_base_qualifier_highlighting = warning
301+
resharper_string_literal_typo_highlighting = none
302+
resharper_suggest_var_or_type_built_in_types_highlighting = hint
303+
resharper_suggest_var_or_type_elsewhere_highlighting = hint
304+
resharper_suggest_var_or_type_simple_types_highlighting = hint
305+
resharper_unused_auto_property_accessor_global_highlighting = suggestion
306+
resharper_web_config_module_not_resolved_highlighting = warning
307+
resharper_web_config_type_not_resolved_highlighting = warning
308+
resharper_web_config_wrong_module_highlighting = warning
309+
310+
[*]
311+
charset = utf-8
312+
end_of_line = crlf
313+
trim_trailing_whitespace = false
314+
insert_final_newline = false
315+
indent_style = space
316+
indent_size = 4
317+
318+
[{*.har,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.stylelintrc,bowerrc,jest.config}]
319+
indent_style = space
320+
indent_size = 2
321+
322+
[*.less]
323+
indent_style = space
324+
indent_size = 2
325+
326+
[*.scss]
327+
indent_style = space
328+
indent_size = 2
329+
330+
[*.styl]
331+
indent_style = space
332+
indent_size = 2
333+
334+
[{*.yaml,*.yml}]
335+
indent_style = space
336+
indent_size = 2
337+
338+
[*.js.map]
339+
indent_style = space
340+
indent_size = 2
341+
342+
[*.{appxmanifest,asax,ascx,aspx,axaml,build,cg,cginc,compute,cshtml,dtd,hlsl,hlsli,hlslinc,master,nuspec,paml,razor,resw,resx,skin,usf,ush,vb,xaml,xamlx,xoml,xsd}]
343+
indent_style = space
344+
indent_size = 4
345+
tab_width = 4

Root/BannedSymbols.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
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

Comments
 (0)