Skip to content

Commit 06bf968

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

31 files changed

+144
-150
lines changed

.editorconfig

+38-11
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

-2
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

-3
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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

+4-4
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

+2-4
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

+1-1
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; }

src/GraphQL.Client/GraphQLHttpClient.cs

+13-15
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,9 @@ public GraphQLHttpClient(GraphQLHttpClientOptions options, IGraphQLWebsocketJson
7777
/// <inheritdoc />
7878
public async Task<GraphQLResponse<TResponse>> SendQueryAsync<TResponse>(GraphQLRequest request, CancellationToken cancellationToken = default)
7979
{
80-
if (Options.UseWebSocketForQueriesAndMutations ||
81-
!(Options.WebSocketEndPoint is null) && Options.EndPoint is null ||
82-
Options.EndPoint.HasWebSocketScheme())
83-
return await GraphQlHttpWebSocket.SendRequest<TResponse>(request, cancellationToken).ConfigureAwait(false);
84-
85-
return await SendHttpRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
80+
return Options.UseWebSocketForQueriesAndMutations || Options.WebSocketEndPoint is not null && Options.EndPoint is null || Options.EndPoint.HasWebSocketScheme()
81+
? await GraphQlHttpWebSocket.SendRequest<TResponse>(request, cancellationToken).ConfigureAwait(false)
82+
: await SendHttpRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
8683
}
8784

8885
/// <inheritdoc />
@@ -132,22 +129,23 @@ private async Task<GraphQLHttpResponse<TResponse>> SendHttpRequestAsync<TRespons
132129
// error handling
133130
string content = null;
134131
if (contentStream != null)
135-
using (var sr = new StreamReader(contentStream))
136-
content = await sr.ReadToEndAsync().ConfigureAwait(false);
132+
{
133+
using var sr = new StreamReader(contentStream);
134+
content = await sr.ReadToEndAsync().ConfigureAwait(false);
135+
}
137136

138137
throw new GraphQLHttpRequestException(httpResponseMessage.StatusCode, httpResponseMessage.Headers, content);
139138
}
140139

141140
private GraphQLHttpWebSocket CreateGraphQLHttpWebSocket()
142141
{
143-
if(Options.WebSocketEndPoint is null && Options.EndPoint is null)
142+
if (Options.WebSocketEndPoint is null && Options.EndPoint is null)
144143
throw new InvalidOperationException("no endpoint configured");
145144

146145
var webSocketEndpoint = Options.WebSocketEndPoint ?? Options.EndPoint.GetWebSocketUri();
147-
if (!webSocketEndpoint.HasWebSocketScheme())
148-
throw new InvalidOperationException($"uri \"{webSocketEndpoint}\" is not a websocket endpoint");
149-
150-
return new GraphQLHttpWebSocket(webSocketEndpoint, this);
146+
return webSocketEndpoint.HasWebSocketScheme()
147+
? new GraphQLHttpWebSocket(webSocketEndpoint, this)
148+
: throw new InvalidOperationException($"uri \"{webSocketEndpoint}\" is not a websocket endpoint");
151149
}
152150

153151
#endregion
@@ -178,9 +176,9 @@ protected virtual void Dispose(bool disposing)
178176
{
179177
Debug.WriteLine($"Disposing GraphQLHttpClient on endpoint {Options.EndPoint}");
180178
_cancellationTokenSource.Cancel();
181-
if(_disposeHttpClient)
179+
if (_disposeHttpClient)
182180
HttpClient.Dispose();
183-
if ( _lazyHttpWebSocket.IsValueCreated )
181+
if (_lazyHttpWebSocket.IsValueCreated)
184182
_lazyHttpWebSocket.Value.Dispose();
185183
_cancellationTokenSource.Dispose();
186184
}

src/GraphQL.Client/GraphQLHttpRequest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public GraphQLHttpRequest(string query, object? variables = null, string? operat
1515
{
1616
}
1717

18-
public GraphQLHttpRequest(GraphQLRequest other): base(other)
18+
public GraphQLHttpRequest(GraphQLRequest other) : base(other)
1919
{
2020
}
2121

src/GraphQL.Client/GraphQLHttpResponse.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public GraphQLHttpResponse(GraphQLResponse<T> response, HttpResponseHeaders resp
2121

2222
public static class GraphQLResponseExtensions
2323
{
24-
public static GraphQLHttpResponse<T> ToGraphQLHttpResponse<T>(this GraphQLResponse<T> response, HttpResponseHeaders responseHeaders, HttpStatusCode statusCode) => new GraphQLHttpResponse<T>(response, responseHeaders, statusCode);
24+
public static GraphQLHttpResponse<T> ToGraphQLHttpResponse<T>(this GraphQLResponse<T> response, HttpResponseHeaders responseHeaders, HttpStatusCode statusCode) => new(response, responseHeaders, statusCode);
2525

2626
/// <summary>
2727
/// Casts <paramref name="response"/> to <see cref="GraphQLHttpResponse{T}"/>. Throws if the cast fails.

src/GraphQL.Client/UriExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class UriExtensions
88
/// <param name="uri"></param>
99
/// <returns></returns>
1010
public static bool HasWebSocketScheme(this Uri? uri) =>
11-
!(uri is null) &&
11+
uri is not null &&
1212
(uri.Scheme.Equals("wss", StringComparison.OrdinalIgnoreCase) || uri.Scheme.Equals("ws", StringComparison.OrdinalIgnoreCase));
1313

1414
/// <summary>
@@ -33,6 +33,6 @@ public static Uri GetWebSocketUri(this Uri uri)
3333
else
3434
throw new NotSupportedException($"cannot infer websocket uri from uri scheme {uri.Scheme}");
3535

36-
return new UriBuilder(uri){Scheme = webSocketScheme}.Uri;
36+
return new UriBuilder(uri) { Scheme = webSocketScheme }.Uri;
3737
}
3838
}

0 commit comments

Comments
 (0)