Skip to content

Commit 2c55155

Browse files
Merge pull request #22 from notion-dotnet/add-editorconfig-for-consistent-coding-style
Add editorconfig for consistent coding style 🎨
2 parents c855a67 + 94699e1 commit 2c55155

Some content is hidden

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

45 files changed

+358
-70
lines changed

.editorconfig

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

Notion.sln

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ VisualStudioVersion = 16.6.30114.105
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Src", "Src", "{4A92506A-3CF1-4E86-B9FD-D5F109655D87}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notion.Client", "Src\Notion.Client\Notion.Client.csproj", "{BF5F85F3-901C-40B0-8357-A1919F89AE2E}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notion.Client", "Src\Notion.Client\Notion.Client.csproj", "{BF5F85F3-901C-40B0-8357-A1919F89AE2E}"
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{F474CF12-E2AC-4388-B764-BAE891D307B8}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notion.UnitTests", "Test\Notion.UnitTests\Notion.UnitTests.csproj", "{B3AE07EA-49CC-4A86-A2D4-04E1FF00AB04}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notion.UnitTests", "Test\Notion.UnitTests\Notion.UnitTests.csproj", "{B3AE07EA-49CC-4A86-A2D4-04E1FF00AB04}"
13+
EndProject
14+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1C2A6790-B7D6-4CFA-B572-E6B3BA482A7F}"
15+
ProjectSection(SolutionItems) = preProject
16+
.editorconfig = .editorconfig
17+
EndProjectSection
1318
EndProject
1419
Global
1520
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -20,9 +25,6 @@ Global
2025
Release|x64 = Release|x64
2126
Release|x86 = Release|x86
2227
EndGlobalSection
23-
GlobalSection(SolutionProperties) = preSolution
24-
HideSolutionNode = FALSE
25-
EndGlobalSection
2628
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2729
{BF5F85F3-901C-40B0-8357-A1919F89AE2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2830
{BF5F85F3-901C-40B0-8357-A1919F89AE2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
@@ -49,8 +51,14 @@ Global
4951
{B3AE07EA-49CC-4A86-A2D4-04E1FF00AB04}.Release|x86.ActiveCfg = Release|Any CPU
5052
{B3AE07EA-49CC-4A86-A2D4-04E1FF00AB04}.Release|x86.Build.0 = Release|Any CPU
5153
EndGlobalSection
54+
GlobalSection(SolutionProperties) = preSolution
55+
HideSolutionNode = FALSE
56+
EndGlobalSection
5257
GlobalSection(NestedProjects) = preSolution
5358
{BF5F85F3-901C-40B0-8357-A1919F89AE2E} = {4A92506A-3CF1-4E86-B9FD-D5F109655D87}
5459
{B3AE07EA-49CC-4A86-A2D4-04E1FF00AB04} = {F474CF12-E2AC-4388-B764-BAE891D307B8}
5560
EndGlobalSection
61+
GlobalSection(ExtensibilityGlobals) = postSolution
62+
SolutionGuid = {3C5C8AC9-88CA-4079-BC0B-C1A81248B0B1}
63+
EndGlobalSection
5664
EndGlobal

Src/Notion.Client/Api/ApiEndpoints.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ public static class BlocksApiUrls
2121
public static string AppendChildren(string blockId) => $"/v1/blocks/{blockId}/children";
2222
}
2323
}
24-
}
24+
}

Src/Notion.Client/Api/Blocks/BlocksClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
44
using static Notion.Client.ApiEndpoints;

Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22

33
namespace Notion.Client
44
{

Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Notion.Client
1+
namespace Notion.Client
22
{
33
public class BlocksRetrieveChildrenParameters : IBlocksRetrieveChildrenQueryParameters
44
{

Src/Notion.Client/Api/Databases/DatabasesClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Threading.Tasks;
33
using static Notion.Client.ApiEndpoints;
44

@@ -38,4 +38,4 @@ public async Task<PaginatedList<Page>> QueryAsync(string databaseId, DatabasesQu
3838
return await _client.PostAsync<PaginatedList<Page>>(DatabasesApiUrls.Query(databaseId), body);
3939
}
4040
}
41-
}
41+
}

Src/Notion.Client/Api/Databases/IDatabasesClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ public interface IDatabasesClient
88
Task<PaginatedList<Page>> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters);
99
Task<PaginatedList<Database>> ListAsync(DatabasesListParameters databasesListParameters = null);
1010
}
11-
}
11+
}

Src/Notion.Client/Api/Databases/RequestParams/Sort.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
22
using Newtonsoft.Json.Converters;
33

44
namespace Notion.Client

Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.IO;
1+
using System.IO;
22
using System.Net.Http;
33
using System.Threading.Tasks;
44
using Newtonsoft.Json;
@@ -32,4 +32,4 @@ internal static async Task<T> ParseStreamAsync<T>(this HttpResponseMessage respo
3232
}
3333
}
3434
}
35-
}
35+
}

0 commit comments

Comments
 (0)