Skip to content

Commit 06bf968

Browse files
authored
Format repo with editorconfig (#530)
1 parent ebc4b82 commit 06bf968

File tree

31 files changed

+144
-150
lines changed

31 files changed

+144
-150
lines changed

.editorconfig

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
# https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options
55

66
# .NET coding convention settings for EditorConfig
7-
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2019
7+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
88

99
# Language conventions
10-
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019
10+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions
1111

1212
# Formatting conventions
13-
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-formatting-conventions?view=vs-2019
13+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-formatting-conventions
1414

1515
# .NET naming conventions for EditorConfig
16-
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2019
16+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions
1717

1818
# Top-most EditorConfig file
1919
root = true
@@ -26,6 +26,9 @@ indent_style = space
2626
indent_size = 2
2727
trim_trailing_whitespace = true
2828

29+
[*.json]
30+
insert_final_newline = false
31+
2932
[*.cs]
3033
indent_size = 4
3134

@@ -91,8 +94,8 @@ csharp_style_var_elsewhere = true:suggestion
9194

9295
# C# code style settings - Expression-bodied members
9396
# 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
97+
csharp_style_expression_bodied_methods = when_on_single_line:suggestion
98+
csharp_style_expression_bodied_constructors = false:warning
9699
csharp_style_expression_bodied_operators = when_on_single_line:warning
97100
csharp_style_expression_bodied_properties = when_on_single_line:warning
98101
csharp_style_expression_bodied_indexers = when_on_single_line:warning
@@ -120,7 +123,7 @@ csharp_style_conditional_delegate_call = true:warning
120123

121124
# C# code style settings - Code block preferences
122125
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#code-block-preferences
123-
csharp_prefer_braces = false:suggestion
126+
csharp_prefer_braces = when_multiline:suggestion
124127

125128
# C# code style - Unused value preferences
126129
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#unused-value-preferences
@@ -129,17 +132,17 @@ csharp_style_unused_value_assignment_preference = discard_variable:suggestion
129132

130133
# C# code style - Index and range preferences
131134
# 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
135+
csharp_style_prefer_index_operator = true:suggestion
136+
csharp_style_prefer_range_operator = true:suggestion
134137

135138
# C# code style - Miscellaneous preferences
136139
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#miscellaneous-preferences
137140
csharp_style_deconstructed_variable_declaration = true:suggestion
138141
csharp_style_pattern_local_over_anonymous_function = true:suggestion
139142
csharp_using_directive_placement = outside_namespace:warning
140143
csharp_prefer_static_local_function = true:suggestion
141-
csharp_prefer_simple_using_statement = false:suggestion
142-
csharp_style_prefer_switch_expression = true:suggestion
144+
csharp_prefer_simple_using_statement = true:warning
145+
csharp_style_prefer_switch_expression = true:warning
143146

144147
# .NET formatting settings - Organize using directives
145148
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-formatting-conventions?view=vs-2019#organize-using-directives
@@ -260,3 +263,27 @@ dotnet_naming_rule.async_methods_end_in_async.severity = warning
260263

261264
# ReSharper: Configure await
262265
configure_await_analysis_mode = library
266+
267+
# Remove unnecessary import https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0005
268+
dotnet_diagnostic.IDE0005.severity = error
269+
270+
# Enforce formatting https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#rule-id-ide0055-fix-formatting
271+
dotnet_diagnostic.IDE0055.severity = error
272+
273+
# https://github.com/JosefPihrt/Roslynator/blob/master/docs/analyzers/RCS0060.md
274+
dotnet_diagnostic.RCS0060.severity = warning
275+
roslynator_blank_line_after_file_scoped_namespace_declaration = true
276+
277+
# https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1080.md
278+
dotnet_diagnostic.RCS1080.severity = warning
279+
280+
# ConfigureAwait https://github.com/JosefPihrt/Roslynator/blob/master/docs/analyzers/RCS1090.md
281+
dotnet_diagnostic.RCS1090.severity = warning
282+
roslynator_configure_await = true
283+
284+
# https://github.com/JosefPihrt/Roslynator/blob/master/docs/analyzers/RCS1102.md
285+
# TODO: NullabilityInfo issue in Patching.cs in internal class SR
286+
dotnet_diagnostic.RCS1102.severity = suggestion
287+
288+
# https://github.com/JosefPihrt/Roslynator/blob/master/docs/analyzers/RCS1194.md
289+
dotnet_diagnostic.RCS1194.severity = suggestion

examples/GraphQL.Client.Example/PersonAndFilmsResponse.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Collections.Generic;
2-
31
namespace GraphQL.Client.Example;
42

53
public class PersonAndFilmsResponse

examples/GraphQL.Client.Example/Program.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Linq;
31
using System.Text.Json;
4-
using System.Threading.Tasks;
52
using GraphQL.Client.Http;
63
using GraphQL.Client.Serializer.Newtonsoft;
74

src/GraphQL.Client.Abstractions/Utilities/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace GraphQL.Client.Abstractions.Utilities;
1+
namespace GraphQL.Client.Abstractions.Utilities;
22

33
/// <summary>
44
/// Copied from https://github.com/jquense/StringUtils

src/GraphQL.Client.Abstractions/Utilities/StringUtils.cs

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

33
namespace GraphQL.Client.Abstractions.Utilities;
44

src/GraphQL.Client.Serializer.Newtonsoft/NewtonsoftJsonSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace GraphQL.Client.Serializer.Newtonsoft;
88

99
public class NewtonsoftJsonSerializer : IGraphQLWebsocketJsonSerializer
1010
{
11-
public static JsonSerializerSettings DefaultJsonSerializerSettings => new JsonSerializerSettings
11+
public static JsonSerializerSettings DefaultJsonSerializerSettings => new()
1212
{
1313
ContractResolver = new CamelCasePropertyNamesContractResolver { IgnoreIsSpecifiedMembers = true },
1414
MissingMemberHandling = MissingMemberHandling.Ignore,
@@ -34,7 +34,7 @@ public NewtonsoftJsonSerializer(JsonSerializerSettings jsonSerializerSettings)
3434

3535
public byte[] SerializeToBytes(GraphQLWebSocketRequest request)
3636
{
37-
var json = JsonConvert.SerializeObject(request, JsonSerializerSettings);
37+
string json = JsonConvert.SerializeObject(request, JsonSerializerSettings);
3838
return Encoding.UTF8.GetBytes(json);
3939
}
4040

src/GraphQL.Client.Serializer.SystemTextJson/ConstantCaseJsonNamingPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace GraphQL.Client.Serializer.SystemTextJson;
55

6-
public class ConstantCaseJsonNamingPolicy: JsonNamingPolicy
6+
public class ConstantCaseJsonNamingPolicy : JsonNamingPolicy
77
{
88
public override string ConvertName(string name) => name.ToConstantCase();
99
}

src/GraphQL.Client.Serializer.SystemTextJson/ErrorPathConverter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ public class ErrorPathConverter : JsonConverter<ErrorPath>
77
{
88

99
public override ErrorPath Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
10-
new ErrorPath(ReadArray(ref reader));
10+
new(ReadArray(ref reader));
1111

1212
public override void Write(Utf8JsonWriter writer, ErrorPath value, JsonSerializerOptions options)
1313
=> throw new NotImplementedException(
1414
"This converter currently is only intended to be used to read a JSON object into a strongly-typed representation.");
15-
16-
private IEnumerable<object?> ReadArray(ref Utf8JsonReader reader)
15+
16+
private static IEnumerable<object?> ReadArray(ref Utf8JsonReader reader)
1717
{
1818
if (reader.TokenType != JsonTokenType.StartArray)
1919
{
@@ -33,7 +33,7 @@ public override void Write(Utf8JsonWriter writer, ErrorPath value, JsonSerialize
3333
return array;
3434
}
3535

36-
private object? ReadValue(ref Utf8JsonReader reader)
36+
private static object? ReadValue(ref Utf8JsonReader reader)
3737
=> reader.TokenType switch
3838
{
3939
JsonTokenType.None => null,

src/GraphQL.Client.Serializer.SystemTextJson/MapConverter.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private static TDictionary ReadDictionary<TDictionary>(ref Utf8JsonReader reader
2222
{
2323
if (reader.TokenType != JsonTokenType.StartObject)
2424
throw new JsonException();
25-
25+
2626
while (reader.Read())
2727
{
2828
if (reader.TokenType == JsonTokenType.EndObject)
@@ -60,7 +60,7 @@ private static List<object> ReadArray(ref Utf8JsonReader reader)
6060

6161
return result;
6262
}
63-
63+
6464
private static object? ReadValue(ref Utf8JsonReader reader)
6565
=> reader.TokenType switch
6666
{
@@ -74,6 +74,4 @@ private static List<object> ReadArray(ref Utf8JsonReader reader)
7474
JsonTokenType.None => null,
7575
_ => throw new InvalidOperationException($"Unexpected value kind: {reader.TokenType}")
7676
};
77-
78-
7977
}

src/GraphQL.Client.Serializer.SystemTextJson/SystemTextJsonSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class SystemTextJsonSerializer : IGraphQLWebsocketJsonSerializer
1010
public static JsonSerializerOptions DefaultJsonSerializerOptions => new JsonSerializerOptions
1111
{
1212
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
13-
Converters = { new JsonStringEnumConverter(new ConstantCaseJsonNamingPolicy(), false)}
13+
Converters = { new JsonStringEnumConverter(new ConstantCaseJsonNamingPolicy(), false) }
1414
}.SetupImmutableConverter();
1515

1616
public JsonSerializerOptions Options { get; }

0 commit comments

Comments
 (0)