Skip to content

Commit 54cf670

Browse files
authored
Merge pull request #196 from graphql-dotnet/code-style-unification
Code style unification
2 parents 525b915 + 755bd98 commit 54cf670

File tree

89 files changed

+4815
-4044
lines changed

Some content is hidden

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

89 files changed

+4815
-4044
lines changed

.editorconfig

Lines changed: 248 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,256 @@
1-
# EditorConfig (http://editorconfig.org/)
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# Create portable, custom editor settings with EditorConfig
4+
# https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options
5+
6+
# .NET coding convention settings for EditorConfig
7+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2019
8+
9+
# Language conventions
10+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019
11+
12+
# Formatting conventions
13+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-formatting-conventions?view=vs-2019
14+
15+
# .NET naming conventions for EditorConfig
16+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2019
17+
18+
# Top-most EditorConfig file
219
root = true
320

4-
# Default Code Style
21+
# Editor default newlines with a newline ending every file
522
[*]
6-
charset = utf-8
7-
end_of_line = lf
8-
indent_size = 4
9-
indent_style = tab
1023
insert_final_newline = true
11-
tab_width = 4
24+
charset = utf-8
25+
indent_style = space
26+
indent_size = 2
1227
trim_trailing_whitespace = true
1328

1429
[*.cs]
15-
csharp_new_line_before_open_brace = false
30+
indent_size = 4
1631

17-
[*.{yaml,yml}]
18-
indent_size = 2
19-
indent_style = space
32+
# Do not insert newline for ApiApprovalTests
33+
[*.txt]
34+
insert_final_newline = false
35+
36+
# Code files
37+
[*.{cs,vb}]
38+
39+
# .NET code style settings - "This." and "Me." qualifiers
40+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#this-and-me
41+
dotnet_style_qualification_for_field = false:warning
42+
dotnet_style_qualification_for_property = false:warning
43+
dotnet_style_qualification_for_method = false:warning
44+
dotnet_style_qualification_for_event = false:warning
45+
46+
# .NET code style settings - Language keywords instead of framework type names for type references
47+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#language-keywords
48+
dotnet_style_predefined_type_for_locals_parameters_members = true:error
49+
dotnet_style_predefined_type_for_member_access = true:error
50+
51+
# .NET code style settings - Modifier preferences
52+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#normalize-modifiers
53+
dotnet_style_require_accessibility_modifiers = always:warning
54+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:warning
55+
dotnet_style_readonly_field = true:warning
56+
57+
# .NET code style settings - Parentheses preferences
58+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#parentheses-preferences
59+
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:suggestion
60+
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:suggestion
61+
dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:suggestion
62+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
63+
64+
# .NET code style settings - Expression-level preferences
65+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#expression-level-preferences
66+
dotnet_style_object_initializer = true:error
67+
dotnet_style_collection_initializer = true:error
68+
dotnet_style_explicit_tuple_names = true:warning
69+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
70+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
71+
dotnet_style_prefer_auto_properties = true:warning
72+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
73+
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
74+
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
75+
dotnet_style_prefer_compound_assignment = true:warning
76+
77+
# .NET code style settings - Null-checking preferences
78+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#null-checking-preferences
79+
dotnet_style_coalesce_expression = true:warning
80+
dotnet_style_null_propagation = true:error
81+
82+
# .NET code quality settings - Parameter preferences
83+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#parameter-preferences
84+
dotnet_code_quality_unused_parameters = all:warning
85+
86+
# C# code style settings - Implicit and explicit types
87+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#implicit-and-explicit-types
88+
csharp_style_var_for_built_in_types = false:suggestion
89+
csharp_style_var_when_type_is_apparent = true:warning
90+
csharp_style_var_elsewhere = true:suggestion
91+
92+
# C# code style settings - Expression-bodied members
93+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#expression-bodied-members
94+
csharp_style_expression_bodied_methods = when_on_single_line:warning
95+
csharp_style_expression_bodied_constructors = false:suggestion
96+
csharp_style_expression_bodied_operators = when_on_single_line:warning
97+
csharp_style_expression_bodied_properties = when_on_single_line:warning
98+
csharp_style_expression_bodied_indexers = when_on_single_line:warning
99+
csharp_style_expression_bodied_accessors = when_on_single_line:warning
100+
csharp_style_expression_bodied_lambdas = when_on_single_line:warning
101+
csharp_style_expression_bodied_local_functions = when_on_single_line:warning
102+
103+
# C# code style settings - Pattern matching
104+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#pattern-matching
105+
csharp_style_pattern_matching_over_is_with_cast_check = true:error
106+
csharp_style_pattern_matching_over_as_with_null_check = true:error
107+
108+
# C# code style settings - Inlined variable declaration
109+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#inlined-variable-declarations
110+
csharp_style_inlined_variable_declaration = true:error
111+
112+
# C# code style settings - C# expression-level preferences
113+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#c-expression-level-preferences
114+
csharp_prefer_simple_default_expression = true:suggestion
115+
116+
# C# code style settings - C# null-checking preferences
117+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#c-null-checking-preferences
118+
csharp_style_throw_expression = true:warning
119+
csharp_style_conditional_delegate_call = true:warning
120+
121+
# C# code style settings - Code block preferences
122+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#code-block-preferences
123+
csharp_prefer_braces = false:suggestion
124+
125+
# C# code style - Unused value preferences
126+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#unused-value-preferences
127+
csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion
128+
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
129+
130+
# C# code style - Index and range preferences
131+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#index-and-range-preferences
132+
csharp_style_prefer_index_operator = true:warning
133+
csharp_style_prefer_range_operator = true:warning
134+
135+
# C# code style - Miscellaneous preferences
136+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#miscellaneous-preferences
137+
csharp_style_deconstructed_variable_declaration = true:suggestion
138+
csharp_style_pattern_local_over_anonymous_function = true:suggestion
139+
csharp_using_directive_placement = outside_namespace:warning
140+
csharp_prefer_static_local_function = true:suggestion
141+
csharp_prefer_simple_using_statement = false:suggestion
142+
csharp_style_prefer_switch_expression = true:suggestion
143+
144+
# .NET formatting settings - Organize using directives
145+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-formatting-conventions?view=vs-2019#organize-using-directives
146+
dotnet_sort_system_directives_first = true
147+
dotnet_separate_import_directive_groups = false
148+
149+
# C# formatting settings - New-line options
150+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-formatting-conventions?view=vs-2019#new-line-options
151+
csharp_new_line_before_open_brace = all
152+
csharp_new_line_before_else = true
153+
csharp_new_line_before_catch = true
154+
csharp_new_line_before_finally = true
155+
csharp_new_line_before_members_in_object_initializers = true
156+
csharp_new_line_before_members_in_anonymous_types = true
157+
csharp_new_line_between_query_expression_clauses = true
158+
159+
# C# formatting settings - Indentation options
160+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-formatting-conventions?view=vs-2019#indentation-options
161+
csharp_indent_case_contents = true
162+
csharp_indent_switch_labels = true
163+
csharp_indent_labels = one_less_than_current
164+
csharp_indent_block_contents = true
165+
csharp_indent_braces = false
166+
csharp_indent_case_contents_when_block = false
167+
168+
# C# formatting settings - Spacing options
169+
csharp_space_after_cast = false
170+
csharp_space_after_keywords_in_control_flow_statements = true
171+
csharp_space_between_parentheses = false
172+
csharp_space_before_colon_in_inheritance_clause = true
173+
csharp_space_after_colon_in_inheritance_clause = true
174+
csharp_space_around_binary_operators = before_and_after
175+
csharp_space_between_method_declaration_parameter_list_parentheses = false
176+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
177+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
178+
csharp_space_between_method_call_parameter_list_parentheses = false
179+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
180+
csharp_space_between_method_call_name_and_opening_parenthesis = false
181+
csharp_space_after_comma = true
182+
csharp_space_before_comma = false
183+
csharp_space_after_dot = false
184+
csharp_space_before_dot = false
185+
csharp_space_after_semicolon_in_for_statement = true
186+
csharp_space_before_semicolon_in_for_statement = false
187+
csharp_space_around_declaration_statements = false
188+
csharp_space_before_open_square_brackets = false
189+
csharp_space_between_empty_square_brackets = false
190+
csharp_space_between_square_brackets = false
191+
192+
# C# formatting settings - Wrap options
193+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-formatting-conventions?view=vs-2019#wrap-options
194+
csharp_preserve_single_line_blocks = true
195+
csharp_preserve_single_line_statements = false
196+
197+
########## name all private fields using camelCase with underscore prefix ##########
198+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2019
199+
# dotnet_naming_rule.<namingRuleTitle>.symbols = <symbolTitle>
200+
dotnet_naming_rule.private_fields_with_underscore.symbols = private_fields
201+
202+
# dotnet_naming_symbols.<symbolTitle>.<property> = <value>
203+
dotnet_naming_symbols.private_fields.applicable_kinds = field
204+
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
205+
206+
# dotnet_naming_rule.<namingRuleTitle>.style = <styleTitle>
207+
dotnet_naming_rule.private_fields_with_underscore.style = prefix_underscore
208+
209+
# dotnet_naming_style.<styleTitle>.<property> = <value>
210+
dotnet_naming_style.prefix_underscore.capitalization = camel_case
211+
dotnet_naming_style.prefix_underscore.required_prefix = _
212+
213+
# dotnet_naming_rule.<namingRuleTitle>.severity = <value>
214+
dotnet_naming_rule.private_fields_with_underscore.severity = warning
215+
216+
########## name all constant fields using UPPER_CASE ##########
217+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2019
218+
# dotnet_naming_rule.<namingRuleTitle>.symbols = <symbolTitle>
219+
dotnet_naming_rule.constant_fields_should_be_upper_case.symbols = constant_fields
220+
221+
# dotnet_naming_symbols.<symbolTitle>.<property> = <value>
222+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
223+
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
224+
dotnet_naming_symbols.constant_fields.required_modifiers = const
225+
226+
# dotnet_naming_rule.<namingRuleTitle>.style = <styleTitle>
227+
dotnet_naming_rule.constant_fields_should_be_upper_case.style = upper_case_style
228+
229+
# dotnet_naming_style.<styleTitle>.<property> = <value>
230+
dotnet_naming_style.upper_case_style.capitalization = all_upper
231+
dotnet_naming_style.upper_case_style.word_separator = _
232+
233+
# dotnet_naming_rule.<namingRuleTitle>.severity = <value>
234+
dotnet_naming_rule.constant_fields_should_be_upper_case.severity = warning
235+
236+
########## Async methods should have "Async" suffix ##########
237+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2019
238+
# dotnet_naming_rule.<namingRuleTitle>.symbols = <symbolTitle>
239+
dotnet_naming_rule.async_methods_end_in_async.symbols = any_async_methods
240+
241+
# dotnet_naming_symbols.<symbolTitle>.<property> = <value>
242+
dotnet_naming_symbols.any_async_methods.applicable_kinds = method
243+
dotnet_naming_symbols.any_async_methods.applicable_accessibilities = *
244+
dotnet_naming_symbols.any_async_methods.required_modifiers = async
245+
246+
# dotnet_naming_rule.<namingRuleTitle>.style = <styleTitle>
247+
dotnet_naming_rule.async_methods_end_in_async.style = end_in_async_style
248+
249+
# dotnet_naming_style.<styleTitle>.<property> = <value>
250+
dotnet_naming_style.end_in_async_style.capitalization = pascal_case
251+
dotnet_naming_style.end_in_async_style.word_separator =
252+
dotnet_naming_style.end_in_async_style.required_prefix =
253+
dotnet_naming_style.end_in_async_style.required_suffix = Async
254+
255+
# dotnet_naming_rule.<namingRuleTitle>.severity = <value>
256+
dotnet_naming_rule.async_methods_end_in_async.severity = warning
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
using System.Collections.Generic;
22

3-
namespace GraphQL.Client.Http.Examples
3+
namespace GraphQL.Client.Example
44
{
5-
public class PersonAndFilmsResponse {
6-
public PersonContent Person { get; set; }
5+
public class PersonAndFilmsResponse
6+
{
7+
public PersonContent Person { get; set; }
78

8-
public class PersonContent {
9-
public string Name { get; set; }
10-
public FilmConnectionContent FilmConnection { get; set; }
9+
public class PersonContent
10+
{
11+
public string Name { get; set; }
12+
public FilmConnectionContent FilmConnection { get; set; }
1113

12-
public class FilmConnectionContent {
13-
public List<FilmContent> Films { get; set; }
14+
public class FilmConnectionContent
15+
{
16+
public List<FilmContent> Films { get; set; }
1417

15-
public class FilmContent {
16-
public string Title { get; set; }
17-
}
18-
}
19-
}
20-
}
18+
public class FilmContent
19+
{
20+
public string Title { get; set; }
21+
}
22+
}
23+
}
24+
}
2125
}

examples/GraphQL.Client.Example/Program.cs

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22
using System.Linq;
33
using System.Text.Json;
44
using System.Threading.Tasks;
5-
using GraphQL.Client.Serializer.Newtonsoft;
5+
using GraphQL.Client.Http;
66

7-
namespace GraphQL.Client.Http.Examples {
7+
namespace GraphQL.Client.Example
8+
{
89

9-
public class Program {
10+
public class Program
11+
{
1012

11-
public static async Task Main(string[] args) {
13+
public static async Task Main(string[] args)
14+
{
15+
_ = args;
16+
using var graphQLClient = new GraphQLHttpClient("https://swapi.apis.guru/");
1217

13-
using var graphQLClient = new GraphQLHttpClient("https://swapi.apis.guru/");
14-
15-
var personAndFilmsRequest = new GraphQLRequest {
16-
Query = @"
18+
var personAndFilmsRequest = new GraphQLRequest
19+
{
20+
Query = @"
1721
query PersonAndFilms($id: ID) {
1822
person(id: $id) {
1923
name
@@ -24,25 +28,26 @@ query PersonAndFilms($id: ID) {
2428
}
2529
}
2630
}",
27-
OperationName = "PersonAndFilms",
28-
Variables = new {
29-
id = "cGVvcGxlOjE="
30-
}
31-
};
32-
33-
var graphQLResponse = await graphQLClient.SendQueryAsync<PersonAndFilmsResponse>(personAndFilmsRequest);
34-
Console.WriteLine("raw response:");
35-
Console.WriteLine(JsonSerializer.Serialize(graphQLResponse, new JsonSerializerOptions { WriteIndented = true }));
36-
37-
Console.WriteLine();
38-
Console.WriteLine($"Name: {graphQLResponse.Data.Person.Name}" );
39-
var films = string.Join(", ", graphQLResponse.Data.Person.FilmConnection.Films.Select(f => f.Title));
40-
Console.WriteLine($"Films: {films}");
41-
42-
Console.WriteLine();
43-
Console.WriteLine("Press any key to quit...");
44-
Console.ReadKey();
45-
}
46-
47-
}
31+
OperationName = "PersonAndFilms",
32+
Variables = new
33+
{
34+
id = "cGVvcGxlOjE="
35+
}
36+
};
37+
38+
var graphQLResponse = await graphQLClient.SendQueryAsync<PersonAndFilmsResponse>(personAndFilmsRequest);
39+
Console.WriteLine("raw response:");
40+
Console.WriteLine(JsonSerializer.Serialize(graphQLResponse, new JsonSerializerOptions { WriteIndented = true }));
41+
42+
Console.WriteLine();
43+
Console.WriteLine($"Name: {graphQLResponse.Data.Person.Name}");
44+
var films = string.Join(", ", graphQLResponse.Data.Person.FilmConnection.Films.Select(f => f.Title));
45+
Console.WriteLine($"Films: {films}");
46+
47+
Console.WriteLine();
48+
Console.WriteLine("Press any key to quit...");
49+
Console.ReadKey();
50+
}
51+
52+
}
4853
}

0 commit comments

Comments
 (0)