Skip to content

Commit 8b88030

Browse files
authored
Update editorconfig to match Roslyn IDE style (#1502)
1 parent 28a8aea commit 8b88030

File tree

49 files changed

+421
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+421
-346
lines changed

.editorconfig

Lines changed: 164 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,203 @@
1-
# EditorConfig is awesome:
2-
http://EditorConfig.org
1+
# EditorConfig is awesome: https://EditorConfig.org
32

43
# top-most EditorConfig file
54
root = true
65

6+
# Don't use tabs for indentation.
77
[*]
88
indent_style = space
9-
insert_final_newline = false
109

10+
# Code files
1111
[*.{cs,csx,vb,vbx}]
1212
indent_size = 4
13+
insert_final_newline = true
14+
charset = utf-8-bom
1315

14-
[*.*proj]
16+
# XML project files
17+
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
1518
indent_size = 2
1619

17-
[*.{json,props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct,vcxproj.filters,projitems}]
20+
# XML config files
21+
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
1822
indent_size = 2
1923

20-
[*.{sh}]
21-
end_of_line = lf
24+
# JSON files
25+
[*.json]
2226
indent_size = 2
2327

24-
[*.{ps1,cmd}]
28+
# Powershell files
29+
[*.ps1]
2530
indent_size = 2
2631

27-
#### .NET Coding Conventions ####
32+
# Shell script files
33+
[*.sh]
34+
end_of_line = lf
35+
indent_size = 2
2836

29-
# this. and Me. preferences
30-
dotnet_style_qualification_for_event = false:warning
31-
dotnet_style_qualification_for_field = false:warning
32-
dotnet_style_qualification_for_method = false:warning
33-
dotnet_style_qualification_for_property = false:warning
37+
# Dotnet code style settings:
38+
[*.{cs,vb}]
3439

35-
# Language keywords vs BCL types preferences
36-
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
37-
dotnet_style_predefined_type_for_member_access = true:warning
40+
# Sort using and Import directives with System.* appearing first
41+
dotnet_sort_system_directives_first = true
42+
dotnet_separate_import_directive_groups = false
43+
# Avoid "this." and "Me." if not necessary
44+
dotnet_style_qualification_for_field = false:refactoring
45+
dotnet_style_qualification_for_property = false:refactoring
46+
dotnet_style_qualification_for_method = false:refactoring
47+
dotnet_style_qualification_for_event = false:refactoring
3848

39-
# Parentheses preferences
40-
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:silent
41-
dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:silent
42-
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
43-
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:silent
49+
# Use language keywords instead of framework type names for type references
50+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
51+
dotnet_style_predefined_type_for_member_access = true:suggestion
4452

45-
# Modifier preferences
46-
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
53+
# Suggest more modern language features when available
54+
dotnet_style_object_initializer = true:suggestion
55+
dotnet_style_collection_initializer = true:suggestion
56+
dotnet_style_coalesce_expression = true:suggestion
57+
dotnet_style_null_propagation = true:suggestion
58+
dotnet_style_explicit_tuple_names = true:suggestion
4759

48-
# Expression-level preferences
49-
csharp_style_deconstructed_variable_declaration = true:suggestion
50-
csharp_style_inlined_variable_declaration = true:suggestion
51-
csharp_style_throw_expression = true:suggestion
52-
dotnet_style_coalesce_expression = true:warning
53-
dotnet_style_collection_initializer = false:silent
54-
dotnet_style_explicit_tuple_names = true:warning
55-
dotnet_style_null_propagation = true:warning
56-
dotnet_style_object_initializer = false:silent
57-
dotnet_style_prefer_auto_properties = true:suggestion
58-
dotnet_style_prefer_compound_assignment = true:suggestion
59-
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
60-
dotnet_style_prefer_conditional_expression_over_return = true:silent
61-
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
62-
dotnet_style_prefer_inferred_tuple_names = true:suggestion
63-
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
64-
65-
# Field preferences
66-
dotnet_style_readonly_field = true:warning
67-
68-
# Parameter preferences
69-
dotnet_code_quality_unused_parameters = all:warning
70-
71-
#### C# Coding Conventions ####
72-
73-
# var preferences
74-
csharp_style_var_elsewhere = true:silent
75-
csharp_style_var_for_built_in_types = false:silent
76-
csharp_style_var_when_type_is_apparent = true:suggestion
60+
# Whitespace options
61+
dotnet_style_allow_multiple_blank_lines_experimental = false
7762

78-
# Expression-bodied members
79-
csharp_style_expression_bodied_accessors = true:suggestion
80-
csharp_style_expression_bodied_constructors = true:silent
81-
csharp_style_expression_bodied_indexers = true:suggestion
82-
csharp_style_expression_bodied_lambdas = true:suggestion
83-
csharp_style_expression_bodied_local_functions = true:suggestion
84-
csharp_style_expression_bodied_methods = when_on_single_line:suggestion
85-
csharp_style_expression_bodied_operators = when_on_single_line:suggestion
86-
csharp_style_expression_bodied_properties = true:suggestion
87-
88-
# Pattern matching preferences
89-
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
90-
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
63+
# Non-private static fields are PascalCase
64+
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.severity = suggestion
65+
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.symbols = non_private_static_fields
66+
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.style = non_private_static_field_style
9167

92-
# Null-checking preferences
93-
csharp_style_conditional_delegate_call = true:warning
68+
dotnet_naming_symbols.non_private_static_fields.applicable_kinds = field
69+
dotnet_naming_symbols.non_private_static_fields.applicable_accessibilities = public, protected, internal, protected_internal, private_protected
70+
dotnet_naming_symbols.non_private_static_fields.required_modifiers = static
9471

95-
# Modifier preferences
96-
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
72+
dotnet_naming_style.non_private_static_field_style.capitalization = pascal_case
9773

98-
# Code-block preferences
99-
csharp_prefer_braces = true:warning
74+
# Non-private readonly fields are PascalCase
75+
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.severity = suggestion
76+
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.symbols = non_private_readonly_fields
77+
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.style = non_private_readonly_field_style
10078

101-
# Expression-level preferences
102-
csharp_prefer_simple_default_expression = true:warning
103-
csharp_style_pattern_local_over_anonymous_function = true:suggestion
104-
csharp_style_prefer_index_operator = true:suggestion
105-
csharp_style_prefer_range_operator = true:suggestion
106-
csharp_style_unused_value_assignment_preference = discard_variable:warning
107-
csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion
79+
dotnet_naming_symbols.non_private_readonly_fields.applicable_kinds = field
80+
dotnet_naming_symbols.non_private_readonly_fields.applicable_accessibilities = public, protected, internal, protected_internal, private_protected
81+
dotnet_naming_symbols.non_private_readonly_fields.required_modifiers = readonly
10882

109-
#### C# Formatting Rules ####
83+
dotnet_naming_style.non_private_readonly_field_style.capitalization = pascal_case
11084

111-
# New line preferences
112-
csharp_new_line_before_catch = true
85+
# Constants are PascalCase
86+
dotnet_naming_rule.constants_should_be_pascal_case.severity = suggestion
87+
dotnet_naming_rule.constants_should_be_pascal_case.symbols = constants
88+
dotnet_naming_rule.constants_should_be_pascal_case.style = constant_style
89+
90+
dotnet_naming_symbols.constants.applicable_kinds = field, local
91+
dotnet_naming_symbols.constants.required_modifiers = const
92+
93+
dotnet_naming_style.constant_style.capitalization = pascal_case
94+
95+
# Static fields are camelCase and start with s_
96+
dotnet_naming_rule.static_fields_should_be_camel_case.severity = suggestion
97+
dotnet_naming_rule.static_fields_should_be_camel_case.symbols = static_fields
98+
dotnet_naming_rule.static_fields_should_be_camel_case.style = static_field_style
99+
100+
dotnet_naming_symbols.static_fields.applicable_kinds = field
101+
dotnet_naming_symbols.static_fields.required_modifiers = static
102+
103+
dotnet_naming_style.static_field_style.capitalization = camel_case
104+
dotnet_naming_style.static_field_style.required_prefix = s_
105+
106+
# Instance fields are camelCase and start with _
107+
dotnet_naming_rule.instance_fields_should_be_camel_case.severity = suggestion
108+
dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields
109+
dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style
110+
111+
dotnet_naming_symbols.instance_fields.applicable_kinds = field
112+
113+
dotnet_naming_style.instance_field_style.capitalization = camel_case
114+
dotnet_naming_style.instance_field_style.required_prefix = _
115+
116+
# Locals and parameters are camelCase
117+
dotnet_naming_rule.locals_should_be_camel_case.severity = suggestion
118+
dotnet_naming_rule.locals_should_be_camel_case.symbols = locals_and_parameters
119+
dotnet_naming_rule.locals_should_be_camel_case.style = camel_case_style
120+
121+
dotnet_naming_symbols.locals_and_parameters.applicable_kinds = parameter, local
122+
123+
dotnet_naming_style.camel_case_style.capitalization = camel_case
124+
125+
# Local functions are PascalCase
126+
dotnet_naming_rule.local_functions_should_be_pascal_case.severity = suggestion
127+
dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions
128+
dotnet_naming_rule.local_functions_should_be_pascal_case.style = local_function_style
129+
130+
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
131+
132+
dotnet_naming_style.local_function_style.capitalization = pascal_case
133+
134+
# By default, name items with PascalCase
135+
dotnet_naming_rule.members_should_be_pascal_case.severity = suggestion
136+
dotnet_naming_rule.members_should_be_pascal_case.symbols = all_members
137+
dotnet_naming_rule.members_should_be_pascal_case.style = pascal_case_style
138+
139+
dotnet_naming_symbols.all_members.applicable_kinds = *
140+
141+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
142+
143+
file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license.\nSee the LICENSE file in the project root for more information.
144+
145+
# RS0016: Only enable if API files are present
146+
dotnet_public_api_analyzer.require_api_files = true
147+
148+
# IDE0055: Fix formatting
149+
# Workaround for https://github.com/dotnet/roslyn/issues/70570
150+
dotnet_diagnostic.IDE0055.severity = warning
151+
152+
153+
# CSharp code style settings:
154+
[*.cs]
155+
# Newline settings
156+
csharp_new_line_before_open_brace = all
113157
csharp_new_line_before_else = true
158+
csharp_new_line_before_catch = true
114159
csharp_new_line_before_finally = true
115-
csharp_new_line_before_members_in_anonymous_types = true
116160
csharp_new_line_before_members_in_object_initializers = true
117-
csharp_new_line_before_open_brace = all
161+
csharp_new_line_before_members_in_anonymous_types = true
118162
csharp_new_line_between_query_expression_clauses = true
119163

120164
# Indentation preferences
121165
csharp_indent_block_contents = true
122166
csharp_indent_braces = false
123167
csharp_indent_case_contents = true
124168
csharp_indent_case_contents_when_block = true
125-
csharp_indent_labels = one_less_than_current
126169
csharp_indent_switch_labels = true
170+
csharp_indent_labels = flush_left
171+
172+
# Whitespace options
173+
csharp_style_allow_embedded_statements_on_same_line_experimental = false
174+
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
175+
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false
176+
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false
177+
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false
178+
179+
# Prefer "var" everywhere
180+
csharp_style_var_for_built_in_types = true:suggestion
181+
csharp_style_var_when_type_is_apparent = true:suggestion
182+
csharp_style_var_elsewhere = true:suggestion
183+
184+
# Prefer method-like constructs to have a block body
185+
csharp_style_expression_bodied_methods = false:none
186+
csharp_style_expression_bodied_constructors = false:none
187+
csharp_style_expression_bodied_operators = false:none
188+
189+
# Prefer property-like constructs to have an expression-body
190+
csharp_style_expression_bodied_properties = true:none
191+
csharp_style_expression_bodied_indexers = true:none
192+
csharp_style_expression_bodied_accessors = true:none
193+
194+
# Suggest more modern language features when available
195+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
196+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
197+
csharp_style_inlined_variable_declaration = true:suggestion
198+
csharp_style_throw_expression = true:suggestion
199+
csharp_style_conditional_delegate_call = true:suggestion
200+
csharp_style_prefer_extended_property_pattern = true:suggestion
127201

128202
# Space preferences
129203
csharp_space_after_cast = false
@@ -133,7 +207,7 @@ csharp_space_after_dot = false
133207
csharp_space_after_keywords_in_control_flow_statements = true
134208
csharp_space_after_semicolon_in_for_statement = true
135209
csharp_space_around_binary_operators = before_and_after
136-
csharp_space_around_declaration_statements = false
210+
csharp_space_around_declaration_statements = do_not_ignore
137211
csharp_space_before_colon_in_inheritance_clause = true
138212
csharp_space_before_comma = false
139213
csharp_space_before_dot = false
@@ -149,10 +223,11 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false
149223
csharp_space_between_parentheses = false
150224
csharp_space_between_square_brackets = false
151225

152-
# Wrapping preferences
226+
# Blocks are allowed
227+
csharp_prefer_braces = true:silent
153228
csharp_preserve_single_line_blocks = true
154229
csharp_preserve_single_line_statements = true
155230

231+
# IDE0060: Remove unused parameter
232+
dotnet_diagnostic.IDE0060.severity = warning
156233

157-
[*.{cs}]
158-
file_header_template = Licensed to the.NET Foundation under one or more agreements.\nThe.NET Foundation licenses this file to you under the MIT license.\nSee the License.txt file in the project root for more information.

src/Common/AzureDevOps/AzureDevOpsUrlParser.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public static bool TryParseHostedHttp(string host, string relativeUrl, [NotNullW
2929
return false;
3030
}
3131

32-
int index = 0;
32+
var index = 0;
3333
string? account;
34-
bool isVisualStudioHost = IsVisualStudioHostedServer(host);
34+
var isVisualStudioHost = IsVisualStudioHostedServer(host);
3535

3636
if (isVisualStudioHost)
3737
{
@@ -98,7 +98,7 @@ public static bool TryParseOnPremHttp(string relativeUrl, string virtualDirector
9898
}
9999

100100
// collection:
101-
int i = virtualDirectoryParts.Length;
101+
var i = virtualDirectoryParts.Length;
102102
var collection = parts[i++];
103103

104104
if (!TryParsePath(parts, i, "_git", out var projectName, out _, out repositoryName))
@@ -138,7 +138,7 @@ public static bool TryParseHostedSsh(Uri uri, [NotNullWhen(true)]out string? acc
138138

139139
account = uri.UserInfo;
140140

141-
int index = 0;
141+
var index = 0;
142142
if (StringComparer.OrdinalIgnoreCase.Equals(parts[0], "DefaultCollection"))
143143
{
144144
index++;
@@ -168,7 +168,7 @@ public static bool TryParseOnPremSsh(Uri uri, [NotNullWhen(true)]out string? rep
168168
return false;
169169
}
170170

171-
if (!TryParseRepositoryName(parts, out int teamNameIndex, "_ssh", out repositoryName))
171+
if (!TryParseRepositoryName(parts, out var teamNameIndex, "_ssh", out repositoryName))
172172
{
173173
return false;
174174
}
@@ -195,7 +195,7 @@ private static bool TryParsePath(string[] parts, int projectPartIndex, string? t
195195

196196
projectName = teamName = null;
197197

198-
if (!TryParseRepositoryName(parts, out int teamNameIndex, type, out repositoryName))
198+
if (!TryParseRepositoryName(parts, out var teamNameIndex, type, out repositoryName))
199199
{
200200
return false;
201201
}
@@ -228,7 +228,7 @@ private static bool TryParseRepositoryName(string[] parts, out int teamNameIndex
228228
repositoryName = null;
229229
teamNameIndex = -1;
230230

231-
int i = parts.Length - 1;
231+
var i = parts.Length - 1;
232232

233233
if (i < 0)
234234
{

0 commit comments

Comments
 (0)