Skip to content

Commit be5ba49

Browse files
authored
Enable CA1805 diagnostics (dotnet#32893)
* Enable CA1805 diagnostics
1 parent 2216583 commit be5ba49

File tree

74 files changed

+138
-140
lines changed

Some content is hidden

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

74 files changed

+138
-140
lines changed

.editorconfig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ dotnet_diagnostic.CA1507.severity = warning
8585
# CA1725: Parameter names should match base declaration
8686
dotnet_diagnostic.CA1725.severity = suggestion
8787

88-
# CA1823: Use literals where appropriate
88+
# CA1802: Use literals where appropriate
8989
dotnet_diagnostic.CA1802.severity = warning
9090

91+
# CA1805: Do not initialize unnecessarily
92+
dotnet_diagnostic.CA1805.severity = warning
93+
9194
# CA1823: Avoid unused private fields
9295
dotnet_diagnostic.CA1823.severity = warning
9396

@@ -98,12 +101,14 @@ dotnet_diagnostic.CA2012.severity = warning
98101
# CA1823: Use literals where appropriate
99102
dotnet_diagnostic.CA1802.severity = suggestion
100103

101-
[**/{test,perf}/**.{cs,vb}]
104+
[**/{test,samples,perf}/**.{cs,vb}]
102105
# CA1018: Mark attributes with AttributeUsageAttribute
103106
dotnet_diagnostic.CA1018.severity = suggestion
104107
# CA1507: Use nameof to express symbol names
105108
dotnet_diagnostic.CA1507.severity = suggestion
106-
# CA1823: Use literals where appropriate
109+
# CA1802: Use literals where appropriate
107110
dotnet_diagnostic.CA1802.severity = suggestion
111+
# CA1805: Do not initialize unnecessarily
112+
dotnet_diagnostic.CA1805.severity = suggestion
108113
# CA2012: Use ValueTask correctly
109114
dotnet_diagnostic.CA2012.severity = suggestion

src/Components/Components/src/RenderTree/Renderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public abstract partial class Renderer : IDisposable, IAsyncDisposable
3737
private readonly ComponentFactory _componentFactory;
3838
private List<(ComponentState, ParameterView)>? _rootComponents;
3939

40-
private int _nextComponentId = 0;
40+
private int _nextComponentId;
4141
private bool _isBatchInProgress;
4242
private ulong _lastEventHandlerId;
4343
private List<Task>? _pendingTasks;

src/Components/Components/src/Rendering/ParameterViewLifetime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal readonly struct ParameterViewLifetime
1010
private readonly RenderBatchBuilder _owner;
1111
private readonly int _stamp;
1212

13-
public static readonly ParameterViewLifetime Unbound = default;
13+
public static readonly ParameterViewLifetime Unbound;
1414

1515
public ParameterViewLifetime(RenderBatchBuilder owner)
1616
{

src/Components/Components/src/Routing/Router.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static readonly IReadOnlyDictionary<string, object> _emptyParametersDictionary
3636

3737
private RouteKey _routeTableLastBuiltForRouteKey;
3838

39-
private bool _onNavigateCalled = false;
39+
private bool _onNavigateCalled;
4040

4141
[Inject] private NavigationManager NavigationManager { get; set; }
4242

src/Components/Server/src/BlazorPack/SequenceOfT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Sequence(ArrayPool<T> arrayPool)
8484
/// in which case the higher of the two minimums dictate the minimum array size that will be allocated.
8585
/// </para>
8686
/// </remarks>
87-
public int MinimumSpanLength { get; set; } = 0;
87+
public int MinimumSpanLength { get; set; }
8888

8989
/// <summary>
9090
/// Gets this sequence expressed as a <see cref="ReadOnlySequence{T}"/>.

src/Components/Server/src/Circuits/RemoteRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal class RemoteRenderer : Microsoft.AspNetCore.Components.RenderTree.Rende
2222
private readonly ILogger _logger;
2323
internal readonly ConcurrentQueue<UnacknowledgedRenderBatch> _unacknowledgedRenderBatches = new ConcurrentQueue<UnacknowledgedRenderBatch>();
2424
private long _nextRenderId = 1;
25-
private bool _disposing = false;
25+
private bool _disposing;
2626

2727
/// <summary>
2828
/// Notifies when a rendering exception occurred.

src/Components/WebAssembly/Authentication.Msal/src/Models/MsalAuthenticationOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class MsalAuthenticationOptions
4848
/// <summary>
4949
/// Gets or sets whether or not to navigate to the login request url after a successful login.
5050
/// </summary>
51-
public bool NavigateToLoginRequestUrl { get; set; } = false;
51+
public bool NavigateToLoginRequestUrl { get; set; }
5252

5353
/// <summary>
5454
/// Gets or sets the set of known authority host names for the application.

src/Components/WebAssembly/WebAssembly.Authentication/src/Services/RemoteAuthenticationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class RemoteAuthenticationService<TRemoteAuthenticationState, [Dynamicall
2727
where TAccount : RemoteUserAccount
2828
{
2929
private static readonly TimeSpan _userCacheRefreshInterval = TimeSpan.FromSeconds(60);
30-
private bool _initialized = false;
30+
private bool _initialized;
3131

3232
// This defaults to 1/1/1970
3333
private DateTimeOffset _userLastCheck = DateTimeOffset.FromUnixTimeSeconds(0);

src/DataProtection/DataProtection/src/EphemeralDataProtectionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public EphemeralKeyRing(ILoggerFactory loggerFactory)
8686

8787
public IAuthenticatedEncryptor? DefaultAuthenticatedEncryptor { get; }
8888

89-
public Guid DefaultKeyId { get; } = default(Guid);
89+
public Guid DefaultKeyId { get; }
9090

9191
public IAuthenticatedEncryptor? GetAuthenticatedEncryptorByKeyId(Guid keyId, out bool isRevoked)
9292
{

src/Features/JsonPatch/src/Internal/ParsedPath.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ namespace Microsoft.AspNetCore.JsonPatch.Internal
1414
/// </summary>
1515
public readonly struct ParsedPath
1616
{
17-
private static readonly string[] Empty = null;
18-
1917
private readonly string[] _segments;
2018

2119
public ParsedPath(string path)
@@ -41,7 +39,7 @@ public string LastSegment
4139
}
4240
}
4341

44-
public IReadOnlyList<string> Segments => _segments ?? Empty;
42+
public IReadOnlyList<string> Segments => _segments;
4543

4644
private static string[] ParsePath(string path)
4745
{

0 commit comments

Comments
 (0)