Skip to content

Commit

Permalink
IDE 29, 30, 31 null!
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanConroy committed Oct 13, 2022
1 parent 0acb0e4 commit 17d0cad
Show file tree
Hide file tree
Showing 24 changed files with 47 additions and 107 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Expand Up @@ -232,6 +232,15 @@ dotnet_diagnostic.IDE0011.severity = warning
# IDE0020: Use pattern matching to avoid is check followed by a cast (with variable)
dotnet_diagnostic.IDE0020.severity = warning

# IDE0029: Use coalesce expression (non-nullable types)
dotnet_diagnostic.IDE0029.severity = warning

# IDE0030: Use coalesce expression (nullable types)
dotnet_diagnostic.IDE0030.severity = warning

# IDE0031: Use null propagation
dotnet_diagnostic.IDE0031.severity = warning

# IDE0035: Remove unreachable code
dotnet_diagnostic.IDE0035.severity = warning

Expand Down Expand Up @@ -331,6 +340,12 @@ dotnet_diagnostic.CA2249.severity = suggestion
dotnet_diagnostic.IDE0005.severity = suggestion
# IDE0020: Use pattern matching to avoid is check followed by a cast (with variable)
dotnet_diagnostic.IDE0020.severity = suggestion
# IDE0029: Use coalesce expression (non-nullable types)
dotnet_diagnostic.IDE0029.severity = suggestion
# IDE0030: Use coalesce expression (nullable types)
dotnet_diagnostic.IDE0030.severity = suggestion
# IDE0031: Use null propagation
dotnet_diagnostic.IDE0031.severity = suggestion
# IDE0038: Use pattern matching to avoid is check followed by a cast (without variable)
dotnet_diagnostic.IDE0038.severity = suggestion
# IDE0044: Make field readonly
Expand Down
Expand Up @@ -88,10 +88,7 @@ public void Dispose()
{
Disposed = true;

if (_jsRuntime != null)
{
_jsRuntime.ReleaseObjectReference(_objectId);
}
_jsRuntime?.ReleaseObjectReference(_objectId);
}
}

Expand Down
Expand Up @@ -504,10 +504,7 @@ private static void Rethrow(ActionExecutedContextSealed? context)
return;
}

if (context.ExceptionDispatchInfo != null)
{
context.ExceptionDispatchInfo.Throw();
}
context.ExceptionDispatchInfo?.Throw();

if (context.Exception != null)
{
Expand Down
15 changes: 3 additions & 12 deletions src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs
Expand Up @@ -1447,10 +1447,7 @@ private static void Rethrow(ResourceExecutedContextSealed context)
return;
}

if (context.ExceptionDispatchInfo != null)
{
context.ExceptionDispatchInfo.Throw();
}
context.ExceptionDispatchInfo?.Throw();

if (context.Exception != null)
{
Expand All @@ -1470,10 +1467,7 @@ private static void Rethrow(ExceptionContextSealed context)
return;
}

if (context.ExceptionDispatchInfo != null)
{
context.ExceptionDispatchInfo.Throw();
}
context.ExceptionDispatchInfo?.Throw();

if (context.Exception != null)
{
Expand All @@ -1493,10 +1487,7 @@ private static void Rethrow(ResultExecutedContextSealed context)
return;
}

if (context.ExceptionDispatchInfo != null)
{
context.ExceptionDispatchInfo.Throw();
}
context.ExceptionDispatchInfo?.Throw();

if (context.Exception != null)
{
Expand Down
Expand Up @@ -703,10 +703,7 @@ private static void Rethrow(PageHandlerExecutedContext? context)
return;
}

if (context.ExceptionDispatchInfo != null)
{
context.ExceptionDispatchInfo.Throw();
}
context.ExceptionDispatchInfo?.Throw();

if (context.Exception != null)
{
Expand Down
Expand Up @@ -104,9 +104,6 @@ public virtual Task ExecuteAsync(PageContext pageContext, PageResult result)
private static void OnExecuting(PageContext pageContext)
{
var viewDataValuesProvider = pageContext.HttpContext.Features.Get<IViewDataValuesProviderFeature>();
if (viewDataValuesProvider != null)
{
viewDataValuesProvider.ProvideViewDataValues(pageContext.ViewData);
}
viewDataValuesProvider?.ProvideViewDataValues(pageContext.ViewData);
}
}
5 changes: 1 addition & 4 deletions src/Mvc/Mvc.ViewFeatures/src/AttributeDictionary.cs
Expand Up @@ -154,10 +154,7 @@ private int Find(string key)
/// <inheritdoc />
public void Clear()
{
if (_items != null)
{
_items.Clear();
}
_items?.Clear();
}

/// <inheritdoc />
Expand Down
5 changes: 1 addition & 4 deletions src/Mvc/Mvc.ViewFeatures/src/ExpressionHelper.cs
Expand Up @@ -135,10 +135,7 @@ public static string GetExpressionText(LambdaExpression expression, ConcurrentDi
if (segmentCount == 0)
{
Debug.Assert(!doNotCache);
if (expressionTextCache != null)
{
expressionTextCache.TryAdd(expression, string.Empty);
}
expressionTextCache?.TryAdd(expression, string.Empty);

return string.Empty;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Mvc/Mvc.ViewFeatures/src/Rendering/TagBuilder.cs
Expand Up @@ -404,10 +404,7 @@ public void WriteTo(TextWriter writer, HtmlEncoder encoder)
writer.Write(tagBuilder.TagName);
tagBuilder.AppendAttributes(writer, encoder);
writer.Write(">");
if (tagBuilder._innerHtml != null)
{
tagBuilder._innerHtml.WriteTo(writer, encoder);
}
tagBuilder._innerHtml?.WriteTo(writer, encoder);
writer.Write("</");
writer.Write(tagBuilder.TagName);
writer.Write(">");
Expand Down
5 changes: 1 addition & 4 deletions src/Mvc/Mvc.ViewFeatures/src/ViewComponentResultExecutor.cs
Expand Up @@ -162,10 +162,7 @@ await using (var intermediateWriter = _writerFactory.CreateWriter(bufferingStrea
private static void OnExecuting(ViewContext viewContext)
{
var viewDataValuesProvider = viewContext.HttpContext.Features.Get<IViewDataValuesProviderFeature>();
if (viewDataValuesProvider != null)
{
viewDataValuesProvider.ProvideViewDataValues(viewContext.ViewData);
}
viewDataValuesProvider?.ProvideViewDataValues(viewContext.ViewData);
}

private static Task<IHtmlContent> GetViewComponentResult(IViewComponentHelper viewComponentHelper, ILogger logger, ViewComponentResult result)
Expand Down
5 changes: 1 addition & 4 deletions src/Mvc/Mvc.ViewFeatures/src/ViewExecutor.cs
Expand Up @@ -265,9 +265,6 @@ await using (var writer = WriterFactory.CreateWriter(response.Body, resolvedCont
private static void OnExecuting(ViewContext viewContext)
{
var viewDataValuesProvider = viewContext.HttpContext.Features.Get<IViewDataValuesProviderFeature>();
if (viewDataValuesProvider != null)
{
viewDataValuesProvider.ProvideViewDataValues(viewContext.ViewData);
}
viewDataValuesProvider?.ProvideViewDataValues(viewContext.ViewData);
}
}
Expand Up @@ -87,10 +87,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
}
}

if (_cache != null)
{
_cache.Put(Context, clientCertificate, result);
}
_cache?.Put(Context, clientCertificate, result);
return result;
}
catch (Exception ex)
Expand Down
10 changes: 2 additions & 8 deletions src/Servers/HttpSys/src/HttpSysOptions.cs
Expand Up @@ -152,10 +152,7 @@ public long RequestQueueLimit
throw new ArgumentOutOfRangeException(nameof(value), value, "The value must be greater than zero.");
}

if (_requestQueue != null)
{
_requestQueue.SetLengthLimit(_requestQueueLength);
}
_requestQueue?.SetLengthLimit(_requestQueueLength);
// Only store it if it succeeds or hasn't started yet
_requestQueueLength = value;
}
Expand Down Expand Up @@ -211,10 +208,7 @@ public Http503VerbosityLevel Http503Verbosity
throw new ArgumentOutOfRangeException(nameof(value), value, message);
}

if (_requestQueue != null)
{
_requestQueue.SetRejectionVerbosity(value);
}
_requestQueue?.SetRejectionVerbosity(value);
// Only store it if it succeeds or hasn't started yet
_rejectionVebosityLevel = value;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Servers/HttpSys/src/RequestProcessing/Request.cs
Expand Up @@ -386,10 +386,7 @@ private void GetTlsHandshakeResults()
}
catch (Exception)
{
if (certLoader != null)
{
certLoader.Dispose();
}
certLoader?.Dispose();
throw;
}
return _clientCert;
Expand Down
Expand Up @@ -150,10 +150,7 @@ private void Dispose(bool disposing)
{
if (disposing)
{
if (_overlapped != null)
{
_overlapped.Dispose();
}
_overlapped?.Dispose();
_cancellationRegistration.Dispose();
}
}
Expand Down
Expand Up @@ -316,14 +316,8 @@ public bool IsCompleted

public void Dispose()
{
if (_overlapped != null)
{
_overlapped.Dispose();
}
if (_fileStream != null)
{
_fileStream.Dispose();
}
_overlapped?.Dispose();
_fileStream?.Dispose();
_cancellationRegistration.Dispose();
}
}
10 changes: 2 additions & 8 deletions src/Servers/HttpSys/src/UrlPrefixCollection.cs
Expand Up @@ -67,10 +67,7 @@ public void Add(UrlPrefix item)
lock (_prefixes)
{
var id = _nextId++;
if (_urlGroup != null)
{
_urlGroup.RegisterPrefix(item.FullPrefix, id);
}
_urlGroup?.RegisterPrefix(item.FullPrefix, id);
_prefixes.Add(id, item);
}
}
Expand Down Expand Up @@ -157,10 +154,7 @@ public bool Remove(UrlPrefix item)
if (pair.Value.Equals(item))
{
id = pair.Key;
if (_urlGroup != null)
{
_urlGroup.UnregisterPrefix(pair.Value.FullPrefix);
}
_urlGroup?.UnregisterPrefix(pair.Value.FullPrefix);
}
}
if (id.HasValue)
Expand Down
Expand Up @@ -787,10 +787,7 @@ public CompletedBuffer(IMemoryOwner<byte>? owner, Memory<byte> buffer, int lengt

public void Return()
{
if (_memoryOwner != null)
{
_memoryOwner.Dispose();
}
_memoryOwner?.Dispose();
}
}
}
5 changes: 1 addition & 4 deletions src/Shared/Dictionary/AdaptiveCapacityDictionary.cs
Expand Up @@ -244,10 +244,7 @@ public void Add(TKey key, TValue value)
/// <inheritdoc />
public void Clear()
{
if (_dictionaryStorage != null)
{
_dictionaryStorage.Clear();
}
_dictionaryStorage?.Clear();

if (_count == 0)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Shared/Process/ProcessEx.cs
Expand Up @@ -167,10 +167,7 @@ private void OnOutputData(object sender, DataReceivedEventArgs e)
}
}

if (_stdoutLines != null)
{
_stdoutLines.Add(e.Data);
}
_stdoutLines?.Add(e.Data);
}

private void OnProcessExited(object sender, EventArgs e)
Expand Down
8 changes: 4 additions & 4 deletions src/Shared/PropertyAsParameterInfo.cs
Expand Up @@ -45,10 +45,10 @@ public PropertyAsParameterInfo(PropertyInfo property, ParameterInfo parameterInf
public override bool HasDefaultValue
=> _constructionParameterInfo is not null && _constructionParameterInfo.HasDefaultValue;
public override object? DefaultValue
=> _constructionParameterInfo is not null ? _constructionParameterInfo.DefaultValue : null;
=> _constructionParameterInfo?.DefaultValue;
public override int MetadataToken => _underlyingProperty.MetadataToken;
public override object? RawDefaultValue
=> _constructionParameterInfo is not null ? _constructionParameterInfo.RawDefaultValue : null;
=> _constructionParameterInfo?.RawDefaultValue;

/// <summary>
/// Unwraps all parameters that contains <see cref="AsParametersAttribute"/> and
Expand Down Expand Up @@ -120,9 +120,9 @@ public static ReadOnlySpan<ParameterInfo> Flatten(ParameterInfo[] parameters, Pa
}
}
}
else if (flattenedParameters is not null)
else
{
flattenedParameters.Add(parameters[i]);
flattenedParameters?.Add(parameters[i]);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/SignalR/server/Core/src/HubConnectionContext.cs
Expand Up @@ -729,9 +729,6 @@ internal void Cleanup()
_closedRequestedRegistration?.Dispose();

// Use _streamTracker to avoid lazy init from StreamTracker getter if it doesn't exist
if (_streamTracker != null)
{
_streamTracker.CompleteAll(new OperationCanceledException("The underlying connection was closed."));
}
_streamTracker?.CompleteAll(new OperationCanceledException("The underlying connection was closed."));
}
}
Expand Up @@ -27,7 +27,7 @@ public static void StreamingResult(ILogger logger, string invocationId, ObjectMe
{
if (logger.IsEnabled(LogLevel.Trace))
{
var resultType = objectMethodExecutor.AsyncResultType == null ? objectMethodExecutor.MethodReturnType : objectMethodExecutor.AsyncResultType;
var resultType = objectMethodExecutor.AsyncResultType ?? objectMethodExecutor.MethodReturnType;
StreamingResult(logger, invocationId, resultType.FullName);
}
}
Expand All @@ -39,7 +39,7 @@ public static void SendingResult(ILogger logger, string? invocationId, ObjectMet
{
if (logger.IsEnabled(LogLevel.Trace))
{
var resultType = objectMethodExecutor.AsyncResultType == null ? objectMethodExecutor.MethodReturnType : objectMethodExecutor.AsyncResultType;
var resultType = objectMethodExecutor.AsyncResultType ?? objectMethodExecutor.MethodReturnType;
SendingResult(logger, invocationId, resultType.FullName);
}
}
Expand Down
Expand Up @@ -78,7 +78,7 @@ public string SkipReason
{
get
{
var value = _currentValue == null ? "(null)" : _currentValue;
var value = _currentValue ?? "(null)";
return $"Test skipped on environment variable with name '{_variableName}' and value '{value}' " +
$"for the '{nameof(RunOnMatch)}' value of '{RunOnMatch}'.";
}
Expand Down

0 comments on commit 17d0cad

Please sign in to comment.