Skip to content

Commit ffdc1db

Browse files
committed
Update .editorconfig file to apply several rules and add dotnet format tool
1 parent f556967 commit ffdc1db

File tree

3 files changed

+273
-2
lines changed

3 files changed

+273
-2
lines changed

.editorconfig

Lines changed: 268 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,273 @@
1-
[*.cs]
1+
# EditorConfig is awesome:http://EditorConfig.org
2+
# from https://github.com/dotnet/format/blob/main/.editorconfig
3+
4+
# top-most EditorConfig file
5+
root = true
6+
7+
# Don't use tabs for indentation.
8+
[*]
29
indent_style = space
10+
# (Please don't specify an indent_size here; that has too many unintended consequences.)
11+
12+
# Code files
13+
[*.{cs,csx,vb,vbx}]
314
indent_size = 2
415
insert_final_newline = true
516
charset = utf-8-bom
17+
18+
# Xml project files
19+
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shpro,nlog.configj}]
20+
indent_size = 2
21+
22+
# Xml config files
23+
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
24+
indent_size = 2
25+
26+
# JSON files
27+
[*.json]
28+
indent_size = 2
29+
30+
[*.{sh}]
31+
end_of_line = lf
32+
indent_size = 2
33+
34+
# Dotnet code style settings:
35+
[*.{cs,vb}]
36+
37+
# Sort using and Import directives with System.* appearing first
638
dotnet_sort_system_directives_first = true
7-
csharp_add_imports_to_deepest_scope = true
39+
dotnet_separate_import_directive_groups = false
40+
41+
# Avoid "this." and "Me." if not necessary
42+
dotnet_style_qualification_for_field = false:error
43+
dotnet_style_qualification_for_property = false:error
44+
dotnet_style_qualification_for_method = false:error
45+
dotnet_style_qualification_for_event = false:error
46+
47+
# Use language keywords instead of framework type names for type references
48+
dotnet_style_predefined_type_for_locals_parameters_members = true:error
49+
dotnet_style_predefined_type_for_member_access = true:error
50+
51+
# Suggest more modern language features when available
52+
dotnet_style_object_initializer = true:suggestion
53+
dotnet_style_collection_initializer = true:suggestion
54+
dotnet_style_coalesce_expression = true:suggestion
55+
dotnet_style_null_propagation = true:suggestion
56+
dotnet_style_explicit_tuple_names = true:suggestion
57+
58+
# Whitespace options
59+
dotnet_style_allow_multiple_blank_lines_experimental = false
60+
dotnet_style_allow_statement_immediately_after_block_experimental = false
61+
62+
# Non-private static fields are PascalCase
63+
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.severity = suggestion
64+
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.symbols = non_private_static_fields
65+
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.style = non_private_static_field_style
66+
67+
dotnet_naming_symbols.non_private_static_fields.applicable_kinds = field
68+
dotnet_naming_symbols.non_private_static_fields.applicable_accessibilities = public, protected, internal, protected_internal, private_protected
69+
dotnet_naming_symbols.non_private_static_fields.required_modifiers = static
70+
71+
dotnet_naming_style.non_private_static_field_style.capitalization = pascal_case
72+
73+
# Non-private readonly fields are PascalCase
74+
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.severity = suggestion
75+
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.symbols = non_private_readonly_fields
76+
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.style = non_private_readonly_field_style
77+
78+
dotnet_naming_symbols.non_private_readonly_fields.applicable_kinds = field
79+
dotnet_naming_symbols.non_private_readonly_fields.applicable_accessibilities = public, protected, internal, protected_internal, private_protected
80+
dotnet_naming_symbols.non_private_readonly_fields.required_modifiers = readonly
81+
82+
dotnet_naming_style.non_private_readonly_field_style.capitalization = pascal_case
83+
84+
# Constants are PascalCase
85+
dotnet_naming_rule.constants_should_be_pascal_case.severity = suggestion
86+
dotnet_naming_rule.constants_should_be_pascal_case.symbols = constants
87+
dotnet_naming_rule.constants_should_be_pascal_case.style = constant_style
88+
89+
dotnet_naming_symbols.constants.applicable_kinds = field, local
90+
dotnet_naming_symbols.constants.required_modifiers = const
91+
92+
dotnet_naming_style.constant_style.capitalization = pascal_case
93+
94+
# Static fields are camelCase and start with s_
95+
dotnet_naming_rule.static_fields_should_be_camel_case.severity = suggestion
96+
dotnet_naming_rule.static_fields_should_be_camel_case.symbols = static_fields
97+
dotnet_naming_rule.static_fields_should_be_camel_case.style = static_field_style
98+
99+
dotnet_naming_symbols.static_fields.applicable_kinds = field
100+
dotnet_naming_symbols.static_fields.required_modifiers = static
101+
102+
dotnet_naming_style.static_field_style.capitalization = camel_case
103+
dotnet_naming_style.static_field_style.required_prefix = s_
104+
105+
# Instance fields are camelCase and start with _
106+
dotnet_naming_rule.instance_fields_should_be_camel_case.severity = suggestion
107+
dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields
108+
dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style
109+
110+
dotnet_naming_symbols.instance_fields.applicable_kinds = field
111+
112+
dotnet_naming_style.instance_field_style.capitalization = camel_case
113+
dotnet_naming_style.instance_field_style.required_prefix = _
114+
115+
# Locals and parameters are camelCase
116+
dotnet_naming_rule.locals_should_be_camel_case.severity = suggestion
117+
dotnet_naming_rule.locals_should_be_camel_case.symbols = locals_and_parameters
118+
dotnet_naming_rule.locals_should_be_camel_case.style = camel_case_style
119+
120+
dotnet_naming_symbols.locals_and_parameters.applicable_kinds = parameter, local
121+
122+
dotnet_naming_style.camel_case_style.capitalization = camel_case
123+
124+
# Local functions are PascalCase
125+
dotnet_naming_rule.local_functions_should_be_pascal_case.severity = suggestion
126+
dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions
127+
dotnet_naming_rule.local_functions_should_be_pascal_case.style = local_function_style
128+
129+
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
130+
131+
dotnet_naming_style.local_function_style.capitalization = pascal_case
132+
133+
# By default, name items with PascalCase
134+
dotnet_naming_rule.members_should_be_pascal_case.severity = suggestion
135+
dotnet_naming_rule.members_should_be_pascal_case.symbols = all_members
136+
dotnet_naming_rule.members_should_be_pascal_case.style = pascal_case_style
137+
138+
dotnet_naming_symbols.all_members.applicable_kinds = *
139+
140+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
141+
142+
# IDE0035: Remove unreachable code
143+
dotnet_diagnostic.IDE0035.severity = warning
144+
145+
# IDE0036: Order modifiers
146+
dotnet_diagnostic.IDE0036.severity = warning
147+
148+
# IDE0043: Format string contains invalid placeholder
149+
dotnet_diagnostic.IDE0043.severity = warning
150+
151+
# IDE0044: Make field readonly
152+
dotnet_diagnostic.IDE0044.severity = warning
153+
154+
# IDE0011: Add braces
155+
csharp_prefer_braces = when_multiline:warning
156+
# NOTE: We need the below severity entry for Add Braces due to https://github.com/dotnet/roslyn/issues/44201
157+
dotnet_diagnostic.IDE0011.severity = warning
158+
159+
# IDE0040: Add accessibility modifiers
160+
dotnet_diagnostic.IDE0040.severity = warning
161+
162+
# CONSIDER: Are IDE0051 and IDE0052 too noisy to be warnings for IDE editing scenarios? Should they be made build-only warnings?
163+
# IDE0051: Remove unused private member
164+
dotnet_diagnostic.IDE0051.severity = warning
165+
166+
# IDE0052: Remove unread private member
167+
dotnet_diagnostic.IDE0052.severity = warning
168+
169+
# IDE0059: Unnecessary assignment to a value
170+
dotnet_diagnostic.IDE0059.severity = warning
171+
172+
# IDE0060: Remove unused parameter
173+
dotnet_diagnostic.IDE0060.severity = warning
174+
175+
# CA1012: Abstract types should not have public constructors
176+
dotnet_diagnostic.CA1012.severity = warning
177+
178+
# CA1822: Make member static
179+
dotnet_diagnostic.CA1822.severity = warning
180+
181+
# IDE0005: Using directive is unnecessary
182+
dotnet_diagnostic.IDE0005.severity = warning
183+
184+
# dotnet_style_allow_multiple_blank_lines_experimental
185+
dotnet_diagnostic.IDE2000.severity = warning
186+
187+
# csharp_style_allow_embedded_statements_on_same_line_experimental
188+
dotnet_diagnostic.IDE2001.severity = warning
189+
190+
# csharp_style_allow_blank_lines_between_consecutive_braces_experimental
191+
dotnet_diagnostic.IDE2002.severity = warning
192+
193+
# dotnet_style_allow_statement_immediately_after_block_experimental
194+
dotnet_diagnostic.IDE2003.severity = warning
195+
196+
# csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental
197+
dotnet_diagnostic.IDE2004.severity = warning
198+
199+
# CSharp code style settings:
200+
[*.cs]
201+
# Newline settings
202+
csharp_new_line_before_open_brace = all
203+
csharp_new_line_before_else = true
204+
csharp_new_line_before_catch = true
205+
csharp_new_line_before_finally = true
206+
csharp_new_line_before_members_in_object_initializers = true
207+
csharp_new_line_before_members_in_anonymous_types = true
208+
csharp_new_line_between_query_expression_clauses = true
209+
210+
# Indentation preferences
211+
csharp_indent_block_contents = true
212+
csharp_indent_braces = false
213+
csharp_indent_case_contents = true
214+
csharp_indent_case_contents_when_block = true
215+
csharp_indent_switch_labels = true
216+
csharp_indent_labels = flush_left
217+
218+
# Whitespace options
219+
csharp_style_allow_embedded_statements_on_same_line_experimental = false
220+
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
221+
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false
222+
223+
# Prefer "var" everywhere
224+
dotnet_diagnostic.IDE0007.severity = error
225+
csharp_style_var_for_built_in_types = true:error
226+
csharp_style_var_when_type_is_apparent = true:error
227+
csharp_style_var_elsewhere = true:error
228+
229+
# Prefer method-like constructs to have a block body
230+
csharp_style_expression_bodied_methods = false:none
231+
csharp_style_expression_bodied_constructors = false:none
232+
csharp_style_expression_bodied_operators = false:none
233+
234+
# Prefer property-like constructs to have an expression-body
235+
csharp_style_expression_bodied_properties = true:error
236+
csharp_style_expression_bodied_indexers = true:error
237+
csharp_style_expression_bodied_accessors = true:error
238+
239+
# Suggest more modern language features when available
240+
csharp_style_pattern_matching_over_is_with_cast_check = true:error
241+
csharp_style_pattern_matching_over_as_with_null_check = true:error
242+
csharp_style_inlined_variable_declaration = true:suggestion
243+
csharp_style_throw_expression = true:error
244+
csharp_style_conditional_delegate_call = true:suggestion
245+
246+
# Spacing
247+
csharp_space_after_cast = false
248+
csharp_space_after_colon_in_inheritance_clause = true
249+
csharp_space_after_comma = true
250+
csharp_space_after_dot = false
251+
csharp_space_after_keywords_in_control_flow_statements = true
252+
csharp_space_after_semicolon_in_for_statement = true
253+
csharp_space_around_binary_operators = before_and_after
254+
csharp_space_around_declaration_statements = do_not_ignore
255+
csharp_space_before_colon_in_inheritance_clause = true
256+
csharp_space_before_comma = false
257+
csharp_space_before_dot = false
258+
csharp_space_before_open_square_brackets = false
259+
csharp_space_before_semicolon_in_for_statement = false
260+
csharp_space_between_empty_square_brackets = false
261+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
262+
csharp_space_between_method_call_name_and_opening_parenthesis = false
263+
csharp_space_between_method_call_parameter_list_parentheses = false
264+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
265+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
266+
csharp_space_between_method_declaration_parameter_list_parentheses = false
267+
csharp_space_between_parentheses = false
268+
csharp_space_between_square_brackets = false
269+
270+
# Blocks are allowed
271+
csharp_prefer_braces = true:silent
272+
csharp_preserve_single_line_blocks = true
273+
csharp_preserve_single_line_statements = true

MegaApiClient.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
88
key.snk = key.snk
99
LICENSE = LICENSE
1010
README.md = README.md
11+
.editorconfig = .editorconfig
1112
EndProjectSection
1213
EndProject
1314
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MegaApiClient.Tests", "MegaApiClient.Tests\MegaApiClient.Tests.csproj", "{16CAE1A9-1690-4EBE-BBE1-DF9249FCFCB9}"

format.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Install dotnet-format if needed
2+
# dotnet tool install -g dotnet-format --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json
3+
4+
dotnet format --fix-whitespace --fix-style info MegaApiClient.sln

0 commit comments

Comments
 (0)