Skip to content

Commit 2862028

Browse files
authored
Bump up warning level for CA1822 (#39436)
Contributes to #24055
1 parent cf2679d commit 2862028

File tree

169 files changed

+428
-440
lines changed

Some content is hidden

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

169 files changed

+428
-440
lines changed

.editorconfig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ dotnet_diagnostic.CA1810.severity = suggestion
105105
dotnet_diagnostic.CA1821.severity = warning
106106

107107
# CA1822: Make member static
108-
dotnet_diagnostic.CA1822.severity = suggestion
108+
dotnet_diagnostic.CA1822.severity = warning
109+
dotnet_code_quality.CA1822.api_surface = private, internal
109110

110111
# CA1823: Avoid unused private fields
111112
dotnet_diagnostic.CA1823.severity = warning
@@ -239,6 +240,8 @@ dotnet_diagnostic.CA1507.severity = suggestion
239240
dotnet_diagnostic.CA1802.severity = suggestion
240241
# CA1805: Do not initialize unnecessarily
241242
dotnet_diagnostic.CA1805.severity = suggestion
243+
# CA1822: Make member static
244+
dotnet_diagnostic.CA1822.severity = suggestion
242245
# CA1823: Avoid zero-length array allocations
243246
dotnet_diagnostic.CA1825.severity = suggestion
244247
# CA1826: Do not use Enumerable methods on indexable collections. Instead use the collection directly
@@ -278,6 +281,8 @@ dotnet_diagnostic.CA2016.severity = suggestion
278281
# Defaults for content in the shared src/ and shared runtime dir
279282

280283
[{**/Shared/runtime/**.{cs,vb},src/Shared/test/Shared.Tests/runtime/**.{cs,vb},**/microsoft.extensions.hostfactoryresolver.sources/**.{cs,vb}}]
284+
# CA1822: Make member static
285+
dotnet_diagnostic.CA1822.severity = silent
281286
# IDE0011: Use braces
282287
dotnet_diagnostic.IDE0011.severity = silent
283288
# IDE0055: Fix formatting

src/Caching/SqlServer/src/DatabaseOperations.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public virtual void SetCacheItem(string key, byte[] value, DistributedCacheEntry
120120
{
121121
var utcNow = SystemClock.UtcNow;
122122

123-
var absoluteExpiration = GetAbsoluteExpiration(utcNow, options);
124-
ValidateOptions(options.SlidingExpiration, absoluteExpiration);
123+
var absoluteExpiration = DatabaseOperations.GetAbsoluteExpiration(utcNow, options);
124+
DatabaseOperations.ValidateOptions(options.SlidingExpiration, absoluteExpiration);
125125

126126
using (var connection = new SqlConnection(ConnectionString))
127127
using (var upsertCommand = new SqlCommand(SqlQueries.SetCacheItem, connection))
@@ -141,7 +141,7 @@ public virtual void SetCacheItem(string key, byte[] value, DistributedCacheEntry
141141
}
142142
catch (SqlException ex)
143143
{
144-
if (IsDuplicateKeyException(ex))
144+
if (DatabaseOperations.IsDuplicateKeyException(ex))
145145
{
146146
// There is a possibility that multiple requests can try to add the same item to the cache, in
147147
// which case we receive a 'duplicate key' exception on the primary key column.
@@ -160,8 +160,8 @@ public virtual void SetCacheItem(string key, byte[] value, DistributedCacheEntry
160160

161161
var utcNow = SystemClock.UtcNow;
162162

163-
var absoluteExpiration = GetAbsoluteExpiration(utcNow, options);
164-
ValidateOptions(options.SlidingExpiration, absoluteExpiration);
163+
var absoluteExpiration = DatabaseOperations.GetAbsoluteExpiration(utcNow, options);
164+
DatabaseOperations.ValidateOptions(options.SlidingExpiration, absoluteExpiration);
165165

166166
using (var connection = new SqlConnection(ConnectionString))
167167
using (var upsertCommand = new SqlCommand(SqlQueries.SetCacheItem, connection))
@@ -181,7 +181,7 @@ public virtual void SetCacheItem(string key, byte[] value, DistributedCacheEntry
181181
}
182182
catch (SqlException ex)
183183
{
184-
if (IsDuplicateKeyException(ex))
184+
if (DatabaseOperations.IsDuplicateKeyException(ex))
185185
{
186186
// There is a possibility that multiple requests can try to add the same item to the cache, in
187187
// which case we receive a 'duplicate key' exception on the primary key column.
@@ -285,7 +285,7 @@ protected virtual byte[] GetCacheItem(string key, bool includeValue)
285285
return value;
286286
}
287287

288-
protected bool IsDuplicateKeyException(SqlException ex)
288+
protected static bool IsDuplicateKeyException(SqlException ex)
289289
{
290290
if (ex.Errors != null)
291291
{
@@ -294,7 +294,7 @@ protected bool IsDuplicateKeyException(SqlException ex)
294294
return false;
295295
}
296296

297-
protected DateTimeOffset? GetAbsoluteExpiration(DateTimeOffset utcNow, DistributedCacheEntryOptions options)
297+
protected static DateTimeOffset? GetAbsoluteExpiration(DateTimeOffset utcNow, DistributedCacheEntryOptions options)
298298
{
299299
// calculate absolute expiration
300300
DateTimeOffset? absoluteExpiration = null;
@@ -314,7 +314,7 @@ protected bool IsDuplicateKeyException(SqlException ex)
314314
return absoluteExpiration;
315315
}
316316

317-
protected void ValidateOptions(TimeSpan? slidingExpiration, DateTimeOffset? absoluteExpiration)
317+
protected static void ValidateOptions(TimeSpan? slidingExpiration, DateTimeOffset? absoluteExpiration)
318318
{
319319
if (!slidingExpiration.HasValue && !absoluteExpiration.HasValue)
320320
{

src/Caching/SqlServer/src/MonoDatabaseOperations.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ public override void SetCacheItem(string key, byte[] value, DistributedCacheEntr
110110
{
111111
var utcNow = SystemClock.UtcNow;
112112

113-
var absoluteExpiration = GetAbsoluteExpiration(utcNow, options);
114-
ValidateOptions(options.SlidingExpiration, absoluteExpiration);
113+
var absoluteExpiration = DatabaseOperations.GetAbsoluteExpiration(utcNow, options);
114+
DatabaseOperations.ValidateOptions(options.SlidingExpiration, absoluteExpiration);
115115

116116
using (var connection = new SqlConnection(ConnectionString))
117117
{
@@ -131,7 +131,7 @@ public override void SetCacheItem(string key, byte[] value, DistributedCacheEntr
131131
}
132132
catch (SqlException ex)
133133
{
134-
if (IsDuplicateKeyException(ex))
134+
if (DatabaseOperations.IsDuplicateKeyException(ex))
135135
{
136136
// There is a possibility that multiple requests can try to add the same item to the cache, in
137137
// which case we receive a 'duplicate key' exception on the primary key column.
@@ -150,8 +150,8 @@ public override void SetCacheItem(string key, byte[] value, DistributedCacheEntr
150150

151151
var utcNow = SystemClock.UtcNow;
152152

153-
var absoluteExpiration = GetAbsoluteExpiration(utcNow, options);
154-
ValidateOptions(options.SlidingExpiration, absoluteExpiration);
153+
var absoluteExpiration = DatabaseOperations.GetAbsoluteExpiration(utcNow, options);
154+
DatabaseOperations.ValidateOptions(options.SlidingExpiration, absoluteExpiration);
155155

156156
using (var connection = new SqlConnection(ConnectionString))
157157
{
@@ -171,7 +171,7 @@ public override void SetCacheItem(string key, byte[] value, DistributedCacheEntr
171171
}
172172
catch (SqlException ex)
173173
{
174-
if (IsDuplicateKeyException(ex))
174+
if (DatabaseOperations.IsDuplicateKeyException(ex))
175175
{
176176
// There is a possibility that multiple requests can try to add the same item to the cache, in
177177
// which case we receive a 'duplicate key' exception on the primary key column.

src/Caching/SqlServer/src/SqlQueries.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ public SqlQueries(string schemaName, string tableName)
8282
public string DeleteExpiredCacheItems { get; }
8383

8484
// From EF's SqlServerQuerySqlGenerator
85-
private string DelimitIdentifier(string identifier)
85+
private static string DelimitIdentifier(string identifier)
8686
{
8787
return "[" + identifier.Replace("]", "]]") + "]";
8888
}
8989

90-
private string EscapeLiteral(string literal)
90+
private static string EscapeLiteral(string literal)
9191
{
9292
return literal.Replace("'", "''");
9393
}

src/Caching/StackExchangeRedis/src/RedisCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public void Remove(string key)
406406
// TODO: Error handling
407407
}
408408

409-
private void MapMetadata(RedisValue[] results, out DateTimeOffset? absoluteExpiration, out TimeSpan? slidingExpiration)
409+
private static void MapMetadata(RedisValue[] results, out DateTimeOffset? absoluteExpiration, out TimeSpan? slidingExpiration)
410410
{
411411
absoluteExpiration = null;
412412
slidingExpiration = null;

src/Components/Analyzers/src/ComponentParametersShouldBePublicCodeFixProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
4747
diagnostic);
4848
}
4949

50-
private Task<Document> GetTransformedDocumentAsync(
50+
private static Task<Document> GetTransformedDocumentAsync(
5151
Document document,
5252
SyntaxNode root,
5353
PropertyDeclarationSyntax declarationNode)
@@ -57,7 +57,7 @@ private Task<Document> GetTransformedDocumentAsync(
5757
return Task.FromResult(document.WithSyntaxRoot(newSyntaxRoot));
5858
}
5959

60-
private SyntaxNode HandlePropertyDeclaration(PropertyDeclarationSyntax node)
60+
private static SyntaxNode HandlePropertyDeclaration(PropertyDeclarationSyntax node)
6161
{
6262
TypeSyntax type = node.Type;
6363
if (type == null || type.IsMissing)

src/Components/Components/src/EventCallbackFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ public EventCallback<TValue> CreateInferred<TValue>(object receiver, Func<TValue
226226
return Create(receiver, callback);
227227
}
228228

229-
private EventCallback CreateCore(object receiver, MulticastDelegate callback)
229+
private static EventCallback CreateCore(object receiver, MulticastDelegate callback)
230230
{
231231
return new EventCallback(callback?.Target as IHandleEvent ?? receiver as IHandleEvent, callback);
232232
}
233233

234-
private EventCallback<TValue> CreateCore<TValue>(object receiver, MulticastDelegate callback)
234+
private static EventCallback<TValue> CreateCore<TValue>(object receiver, MulticastDelegate callback)
235235
{
236236
return new EventCallback<TValue>(callback?.Target as IHandleEvent ?? receiver as IHandleEvent, callback);
237237
}

src/Components/Components/src/Routing/RouteEntry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ internal void Match(RouteContext context)
124124
}
125125
}
126126

127-
private void AddDefaultValues(Dictionary<string, object> parameters, int templateIndex, TemplateSegment[] segments)
127+
private static void AddDefaultValues(Dictionary<string, object> parameters, int templateIndex, TemplateSegment[] segments)
128128
{
129129
for (var i = templateIndex; i < segments.Length; i++)
130130
{
@@ -133,7 +133,7 @@ private void AddDefaultValues(Dictionary<string, object> parameters, int templat
133133
}
134134
}
135135

136-
private bool RemainingSegmentsAreOptional(int index, TemplateSegment[] segments)
136+
private static bool RemainingSegmentsAreOptional(int index, TemplateSegment[] segments)
137137
{
138138
for (var i = index; index < segments.Length - 1; index++)
139139
{

src/Components/Web/src/Forms/InputBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ private void UpdateAdditionalValidationAttributes()
272272
/// Returns a dictionary with the same values as the specified <paramref name="source"/>.
273273
/// </summary>
274274
/// <returns>true, if a new dictrionary with copied values was created. false - otherwise.</returns>
275-
private bool ConvertToDictionary(IReadOnlyDictionary<string, object>? source, out Dictionary<string, object> result)
275+
private static bool ConvertToDictionary(IReadOnlyDictionary<string, object>? source, out Dictionary<string, object> result)
276276
{
277277
var newDictionaryCreated = true;
278278
if (source == null)

src/Components/Web/src/Routing/NavLink.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
168168
builder.CloseElement();
169169
}
170170

171-
private string? CombineWithSpace(string? str1, string str2)
171+
private static string? CombineWithSpace(string? str1, string str2)
172172
=> str1 == null ? str2 : $"{str1} {str2}";
173173

174174
private static bool IsStrictlyPrefixWithSeparator(string value, string prefix)

0 commit comments

Comments
 (0)