Skip to content

Commit d98fc04

Browse files
committed
Optimize IDE* rules to minimize noise, enable recommended ruleset
1 parent edcfcbf commit d98fc04

File tree

2 files changed

+143
-52
lines changed

2 files changed

+143
-52
lines changed

.editorconfig

Lines changed: 118 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,119 @@ root = true
44
[*]
55
indent_style = space
66
indent_size = 4
7+
tab-width = 4
78
charset = utf-8
89
trim_trailing_whitespace = true
910
insert_final_newline = true
1011

11-
[*.{config,csproj,css,js,json,props,ruleset,xslt,html}]
12+
[*.{config,csproj,css,js,json,props,targets,xml,ruleset,xsd,xslt,html,yml,yaml}]
1213
indent_size = 2
14+
tab-width = 2
15+
max_line_length = 160
16+
17+
[*.{cs,cshtml,ascx,aspx}]
1318

14-
[*.{cs}]
1519
#### C#/.NET Coding Conventions ####
1620

21+
# Default severity for IDE* analyzers with category 'Style'
22+
# Note: specific rules below use severity silent, because Resharper code cleanup auto-fixes them.
23+
dotnet_analyzer_diagnostic.category-Style.severity = warning
24+
1725
# 'using' directive preferences
1826
dotnet_sort_system_directives_first = true
19-
csharp_using_directive_placement = outside_namespace:suggestion
27+
csharp_using_directive_placement = outside_namespace:silent
28+
# IDE0005: Remove unnecessary import
29+
dotnet_diagnostic.IDE0005.severity = silent
2030

2131
# Namespace declarations
22-
csharp_style_namespace_declarations = file_scoped:suggestion
32+
csharp_style_namespace_declarations = file_scoped:silent
33+
# IDE0160: Use block-scoped namespace
34+
dotnet_diagnostic.IDE0160.severity = silent
35+
# IDE0161: Use file-scoped namespace
36+
dotnet_diagnostic.IDE0161.severity = silent
2337

2438
# this. preferences
25-
dotnet_style_qualification_for_field = false:suggestion
26-
dotnet_style_qualification_for_property = false:suggestion
27-
dotnet_style_qualification_for_method = false:suggestion
28-
dotnet_style_qualification_for_event = false:suggestion
39+
dotnet_style_qualification_for_field = false:silent
40+
dotnet_style_qualification_for_property = false:silent
41+
dotnet_style_qualification_for_method = false:silent
42+
dotnet_style_qualification_for_event = false:silent
43+
# IDE0003: Remove this or Me qualification
44+
dotnet_diagnostic.IDE0003.severity = silent
45+
# IDE0009: Add this or Me qualification
46+
dotnet_diagnostic.IDE0009.severity = silent
2947

3048
# Language keywords vs BCL types preferences
31-
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
32-
dotnet_style_predefined_type_for_member_access = true:suggestion
49+
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
50+
dotnet_style_predefined_type_for_member_access = true:silent
51+
# IDE0049: Use language keywords instead of framework type names for type references
52+
dotnet_diagnostic.IDE0049.severity = silent
3353

3454
# Modifier preferences
35-
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
36-
csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:suggestion
37-
csharp_style_pattern_local_over_anonymous_function = false:silent
55+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
56+
# IDE0040: Add accessibility modifiers
57+
dotnet_diagnostic.IDE0040.severity = silent
58+
csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:silent
59+
# IDE0036: Order modifiers
60+
dotnet_diagnostic.IDE0036.severity = silent
3861

3962
# Expression-level preferences
4063
dotnet_style_operator_placement_when_wrapping = end_of_line
41-
dotnet_style_prefer_auto_properties = true:suggestion
42-
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
43-
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
44-
csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion
64+
dotnet_style_prefer_auto_properties = true:silent
65+
# IDE0032: Use auto property
66+
dotnet_diagnostic.IDE0032.severity = silent
67+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
68+
# IDE0045: Use conditional expression for assignment
69+
dotnet_diagnostic.IDE0045.severity = silent
70+
dotnet_style_prefer_conditional_expression_over_return = true:silent
71+
# IDE0046: Use conditional expression for return
72+
dotnet_diagnostic.IDE0046.severity = silent
73+
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
74+
# IDE0058: Remove unused expression value
75+
dotnet_diagnostic.IDE0058.severity = silent
76+
77+
# Collection expression preferences (note: partially turned off in Directory.Build.props)
78+
dotnet_style_prefer_collection_expression = when_types_exactly_match
4579

4680
# Parameter preferences
47-
dotnet_code_quality_unused_parameters = non_public:suggestion
81+
dotnet_code_quality_unused_parameters = non_public
82+
83+
# Local functions vs lambdas
84+
csharp_style_prefer_local_over_anonymous_function = false:silent
85+
# IDE0039: Use local function instead of lambda
86+
dotnet_diagnostic.IDE0039.severity = silent
4887

4988
# Expression-bodied members
50-
csharp_style_expression_bodied_accessors = true:suggestion
51-
csharp_style_expression_bodied_constructors = false:suggestion
52-
csharp_style_expression_bodied_indexers = true:suggestion
53-
csharp_style_expression_bodied_lambdas = true:suggestion
54-
csharp_style_expression_bodied_local_functions = false:suggestion
55-
csharp_style_expression_bodied_methods = false:suggestion
56-
csharp_style_expression_bodied_operators = false:suggestion
57-
csharp_style_expression_bodied_properties = true:suggestion
89+
csharp_style_expression_bodied_accessors = true:silent
90+
# IDE0027: Use expression body for accessors
91+
dotnet_diagnostic.IDE0027.severity = silent
92+
csharp_style_expression_bodied_constructors = false:silent
93+
# IDE0021: Use expression body for constructors
94+
dotnet_diagnostic.IDE0021.severity = silent
95+
csharp_style_expression_bodied_indexers = true:silent
96+
# IDE0026: Use expression body for indexers
97+
dotnet_diagnostic.IDE0026.severity = silent
98+
csharp_style_expression_bodied_lambdas = true:silent
99+
# IDE0053: Use expression body for lambdas
100+
dotnet_diagnostic.IDE0053.severity = silent
101+
csharp_style_expression_bodied_local_functions = false:silent
102+
# IDE0061: Use expression body for local functions
103+
dotnet_diagnostic.IDE0061.severity = silent
104+
csharp_style_expression_bodied_methods = false:silent
105+
# IDE0022: Use expression body for methods
106+
dotnet_diagnostic.IDE0022.severity = silent
107+
csharp_style_expression_bodied_operators = false:silent
108+
# IDE0023: Use expression body for conversion operators
109+
dotnet_diagnostic.IDE0023.severity = silent
110+
# IDE0024: Use expression body for operators
111+
dotnet_diagnostic.IDE0024.severity = silent
112+
csharp_style_expression_bodied_properties = true:silent
113+
# IDE0025: Use expression body for properties
114+
dotnet_diagnostic.IDE0025.severity = silent
58115

59116
# Code-block preferences
60-
csharp_prefer_braces = true:suggestion
117+
csharp_prefer_braces = true:silent
118+
# IDE0011: Add braces
119+
dotnet_diagnostic.IDE0011.severity = silent
61120

62121
# Indentation preferences
63122
csharp_indent_case_contents_when_block = false
@@ -66,19 +125,42 @@ csharp_indent_case_contents_when_block = false
66125
csharp_preserve_single_line_statements = false
67126

68127
# 'var' usage preferences
69-
csharp_style_var_for_built_in_types = false:none
70-
csharp_style_var_when_type_is_apparent = true:none
71-
csharp_style_var_elsewhere = false:none
128+
csharp_style_var_for_built_in_types = false:silent
129+
csharp_style_var_when_type_is_apparent = true:silent
130+
csharp_style_var_elsewhere = false:silent
131+
# IDE0007: Use var instead of explicit type
132+
dotnet_diagnostic.IDE0007.severity = silent
133+
# IDE0008: Use explicit type instead of var
134+
dotnet_diagnostic.IDE0008.severity = silent
72135

73136
# Parentheses preferences
74-
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:suggestion
75-
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
76-
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:suggestion
137+
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:silent
138+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
139+
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:silent
140+
# IDE0047: Remove unnecessary parentheses
141+
dotnet_diagnostic.IDE0047.severity = silent
142+
# IDE0048: Add parentheses for clarity
143+
dotnet_diagnostic.IDE0048.severity = silent
144+
145+
# IDE0010: Add missing cases to switch statement
146+
dotnet_diagnostic.IDE0010.severity = silent
147+
# IDE0072: Add missing cases to switch expression
148+
dotnet_diagnostic.IDE0072.severity = silent
149+
150+
# IDE0029: Null check can be simplified
151+
dotnet_diagnostic.IDE0029.severity = silent
152+
# IDE0030: Null check can be simplified
153+
dotnet_diagnostic.IDE0030.severity = silent
154+
# IDE0270: Null check can be simplified
155+
dotnet_diagnostic.IDE0270.severity = silent
156+
157+
# JSON002: Probable JSON string detected
158+
dotnet_diagnostic.JSON002.severity = silent
77159

78-
# Expression value is never used
79-
dotnet_diagnostic.IDE0058.severity = none
160+
# CA1062: Validate arguments of public methods
161+
dotnet_code_quality.CA1062.excluded_symbol_names = Accept|DefaultVisit|Visit*|Apply*
80162

81-
#### Naming Style ####
163+
#### .NET Naming Style ####
82164

83165
dotnet_diagnostic.IDE1006.severity = warning
84166

@@ -128,6 +210,3 @@ dotnet_naming_style.camel_case_prefix_with_underscore.required_prefix = _
128210
dotnet_naming_style.camel_case_prefix_with_underscore.capitalization = camel_case
129211

130212
dotnet_naming_style.camel_case.capitalization = camel_case
131-
132-
# CA1062: Validate arguments of public methods
133-
dotnet_code_quality.CA1062.excluded_symbol_names = Accept|DefaultVisit|Visit*|Apply*

Directory.Build.props

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
<Project>
2+
<PropertyGroup>
3+
<Nullable>enable</Nullable>
4+
<LangVersion>latest</LangVersion>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<IsPackable>false</IsPackable>
7+
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
8+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
9+
<AnalysisMode>Recommended</AnalysisMode>
10+
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
11+
<RunSettingsFilePath>$(MSBuildThisFileDirectory)tests.runsettings</RunSettingsFilePath>
12+
<JsonApiDotNetCoreVersionPrefix>5.6.1</JsonApiDotNetCoreVersionPrefix>
13+
</PropertyGroup>
14+
15+
<PropertyGroup>
16+
<!--
17+
Disabled IDE analyzers for "Use collection expression" because they are dangerous in a subtle way.
18+
For example, a suggestion for the following code is raised:
19+
public IList<string> Items { get; } = new List<string>();
20+
Taking the suggestion TODAY produces List<string>, but the spec doesn't require that, so the compiler may change it over time.
21+
As a result, callers that cast back to List<string> will face a breaking change.
22+
-->
23+
<UseCollectionExpressionRules>IDE0028;IDE0300;IDE0301;IDE0302;IDE0303;IDE0304;IDE0305</UseCollectionExpressionRules>
24+
<NoWarn>$(NoWarn);$(UseCollectionExpressionRules)</NoWarn>
25+
</PropertyGroup>
26+
227
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
328
<NoWarn>$(NoWarn);AV2210</NoWarn>
429
</PropertyGroup>
@@ -32,17 +57,4 @@
3257
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.8.*" PrivateAssets="All" />
3358
<AdditionalFiles Include="$(MSBuildThisFileDirectory)CSharpGuidelinesAnalyzer.config" Visible="False" />
3459
</ItemGroup>
35-
36-
<PropertyGroup>
37-
<Nullable>enable</Nullable>
38-
<LangVersion>latest</LangVersion>
39-
<ImplicitUsings>enable</ImplicitUsings>
40-
<IsPackable>false</IsPackable>
41-
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
42-
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
43-
<AnalysisMode>Recommended</AnalysisMode>
44-
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
45-
<RunSettingsFilePath>$(MSBuildThisFileDirectory)tests.runsettings</RunSettingsFilePath>
46-
<JsonApiDotNetCoreVersionPrefix>5.6.1</JsonApiDotNetCoreVersionPrefix>
47-
</PropertyGroup>
4860
</Project>

0 commit comments

Comments
 (0)