Skip to content

Commit d8d95f9

Browse files
authored
Updated code to remove unnecessary conditional access (#8339)
1 parent 0f027f9 commit d8d95f9

File tree

66 files changed

+111
-125
lines changed

Some content is hidden

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

66 files changed

+111
-125
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ dotnet_diagnostic.RCS1251.severity = warning
190190
# Add/remove trailing comma.
191191
dotnet_diagnostic.RCS1260.severity = warning
192192
roslynator_trailing_comma_style = omit
193+
# Unnecessary conditional access.
194+
dotnet_diagnostic.RCS9003.severity = warning
193195

194196
# netstandard2.0
195197
[src/HotChocolate/{Core/src/Types.Analyzers,Language}/**/*.cs]

src/GreenDonut/src/GreenDonut.Data/Extensions/GreenDonutQueryableExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public static IQueryable<T> With<T>(
314314
if(modifySortDefinition is not null)
315315
{
316316
sorting ??= SortDefinition<T>.Empty;
317-
sorting = modifySortDefinition?.Invoke(sorting);
317+
sorting = modifySortDefinition(sorting);
318318
}
319319

320320
if (queryContext.Predicate is not null)

src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/Subscriptions/Apollo/SubscriptionTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected async Task<WebSocket> ConnectToServerAsync(
9797
await webSocket.SendConnectionInitializeAsync(cancellationToken);
9898
var message = await webSocket.ReceiveServerMessageAsync(cancellationToken);
9999
Assert.NotNull(message);
100-
Assert.Equal("connection_ack", message?[MessageProperties.Type]);
100+
Assert.Equal("connection_ack", message[MessageProperties.Type]);
101101
return webSocket;
102102
}
103103

src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/Subscriptions/GraphQLOverWebSocket/SubscriptionTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected async Task<WebSocket> ConnectToServerAsync(
9797
await webSocket.SendConnectionInitAsync(cancellationToken);
9898
var message = await webSocket.ReceiveServerMessageAsync(cancellationToken);
9999
Assert.NotNull(message);
100-
Assert.Equal("connection_ack", message?["type"]);
100+
Assert.Equal("connection_ack", message["type"]);
101101
return webSocket;
102102
}
103103

src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/TestServerFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public TestServer Create(
1818
.ConfigureServices(services =>
1919
{
2020
services.AddHttpContextAccessor();
21-
configureServices?.Invoke(services);
21+
configureServices(services);
2222
});
2323

2424
var server = new TestServer(builder);

src/HotChocolate/AzureFunctions/test/HotChocolate.AzureFunctions.Tests/Helpers/HttpContextExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static class HttpContextExtensions
2929

3030
public static async Task<string?> ReadResponseContentAsync(this HttpContext? httpContext)
3131
{
32-
var responseStream = httpContext?.Response?.Body;
32+
var responseStream = httpContext?.Response.Body;
3333
return responseStream != null
3434
? await responseStream.ReadStreamAsStringAsync().ConfigureAwait(false)
3535
: null;

src/HotChocolate/Caching/test/Caching.Tests/TestServerFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public TestServer Create(
1717
.Configure(configureApplication)
1818
.ConfigureServices(services =>
1919
{
20-
configureServices?.Invoke(services);
20+
configureServices(services);
2121
});
2222

2323
var server = new TestServer(builder);

src/HotChocolate/Core/src/Execution.Abstractions/GraphQLException.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ public GraphQLException(string message)
1818
/// </summary>
1919
/// <param name="error">The error.</param>
2020
public GraphQLException(IError error)
21-
: base(error?.Message)
21+
: base(error.Message)
2222
{
23-
Errors = error is null
24-
? Array.Empty<IError>()
25-
: [error];
23+
Errors = [error];
2624
}
2725

2826
/// <summary>

src/HotChocolate/Core/src/Types/Types/Extensions/DirectiveCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace HotChocolate.Types;
1111

1212
public static class DirectiveCollectionExtensions
1313
{
14-
public static T SingleOrDefault<T>(this DirectiveCollection directives) where T : notnull
14+
public static T? SingleOrDefault<T>(this DirectiveCollection directives) where T : notnull
1515
{
1616
foreach (var directive in directives)
1717
{
@@ -21,7 +21,7 @@ public static T SingleOrDefault<T>(this DirectiveCollection directives) where T
2121
}
2222
}
2323

24-
return default!;
24+
return default;
2525
}
2626

2727
internal static IValueNode? SkipValue(this IReadOnlyList<DirectiveNode> directives)

src/HotChocolate/Core/test/Types.Tests/Regressions/NestedOptionalInt_2114.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ mutation a($input: ButterPickleInput!)
9393
private static void Verify(ToppingInput? input)
9494
{
9595
Assert.NotNull(input);
96-
var pickle = input?.Pickles!.First()?.ButterPickle;
96+
var pickle = input.Pickles!.First().ButterPickle;
9797
Assert.NotNull(pickle);
98-
Assert.Equal(5, pickle?.Size);
99-
Assert.False(pickle?.Width.HasValue);
100-
Assert.False(pickle?.ComplexUnassigned.HasValue);
101-
Assert.True(pickle?.ComplexAssigned.HasValue);
102-
Assert.Equal(3, pickle?.ComplexAssigned.Value?.Value);
103-
Assert.True(pickle?.ComplexAssignedNull.HasValue);
104-
Assert.Null(pickle?.ComplexAssignedNull.Value);
105-
Assert.True(pickle?.ComplexList.HasValue);
106-
Assert.Equal(2, pickle?.ComplexList.Value?.First().Value);
98+
Assert.Equal(5, pickle.Size.Value);
99+
Assert.False(pickle.Width.HasValue);
100+
Assert.False(pickle.ComplexUnassigned.HasValue);
101+
Assert.True(pickle.ComplexAssigned.HasValue);
102+
Assert.Equal(3, pickle.ComplexAssigned.Value?.Value);
103+
Assert.True(pickle.ComplexAssignedNull.HasValue);
104+
Assert.Null(pickle.ComplexAssignedNull.Value);
105+
Assert.True(pickle.ComplexList.HasValue);
106+
Assert.Equal(2, pickle.ComplexList.Value?.First().Value);
107107
}
108108

109109
private static IRequestExecutor CreateExecutor(Func<ToppingInput, bool>? onEat = null)

0 commit comments

Comments
 (0)