Skip to content

Commit 03c3475

Browse files
authored
Merge pull request #44463 from mavasani/EnforceCA1822
[Dogfooding] Enforce "Make member static" for IDE projects
2 parents b3c0515 + 61170c7 commit 03c3475

File tree

598 files changed

+1770
-1761
lines changed

Some content is hidden

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

598 files changed

+1770
-1761
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,6 @@ dotnet_diagnostic.IDE0059.severity = warning
261261

262262
# IDE0060: Remove unused parameter
263263
dotnet_diagnostic.IDE0060.severity = warning
264+
265+
# CA1822: Make member static
266+
dotnet_diagnostic.CA1822.severity = warning

src/Analyzers/CSharp/Analyzers/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersDiagnosticAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public CSharpAddAccessibilityModifiersDiagnosticAnalyzer()
2020
{
2121
}
2222

23-
private CSharpSyntaxFacts SyntaxFacts => CSharpSyntaxFacts.Instance;
23+
private static CSharpSyntaxFacts SyntaxFacts => CSharpSyntaxFacts.Instance;
2424

2525
protected override void ProcessCompilationUnit(
2626
SyntaxTreeAnalysisContext context,

src/Analyzers/CSharp/Analyzers/InlineDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context, INamedTypeSymb
237237
properties: null));
238238
}
239239

240-
private bool WouldCauseDefiniteAssignmentErrors(
240+
private static bool WouldCauseDefiniteAssignmentErrors(
241241
SemanticModel semanticModel,
242242
LocalDeclarationStatementSyntax localStatement,
243243
BlockSyntax enclosingBlock,
@@ -260,7 +260,7 @@ private bool WouldCauseDefiniteAssignmentErrors(
260260
return dataFlow.DataFlowsIn.Contains(outLocalSymbol);
261261
}
262262

263-
private SyntaxNode GetOutArgumentScope(SyntaxNode argumentExpression)
263+
private static SyntaxNode GetOutArgumentScope(SyntaxNode argumentExpression)
264264
{
265265
for (var current = argumentExpression; current != null; current = current.Parent)
266266
{
@@ -312,7 +312,7 @@ private SyntaxNode GetOutArgumentScope(SyntaxNode argumentExpression)
312312
return null;
313313
}
314314

315-
private bool IsAccessed(
315+
private static bool IsAccessed(
316316
SemanticModel semanticModel,
317317
ISymbol outSymbol,
318318
BlockSyntax enclosingBlockOfLocalStatement,

src/Analyzers/CSharp/Analyzers/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private bool TryCheckVariableAndIfStatementForm(
305305
return true;
306306
}
307307

308-
private bool IsNullCheckExpression(ExpressionSyntax left, ExpressionSyntax right) =>
308+
private static bool IsNullCheckExpression(ExpressionSyntax left, ExpressionSyntax right) =>
309309
left.IsKind(SyntaxKind.IdentifierName) && right.IsKind(SyntaxKind.NullLiteralExpression);
310310

311311
public override DiagnosticAnalyzerCategory GetAnalyzerCategory()

src/Analyzers/CSharp/Analyzers/QualifyMemberAccess/CSharpQualifyMemberAccessDiagnosticAnalyzer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ protected override bool CanMemberAccessBeQualified(ISymbol containingSymbol, Syn
4242
IsInPropertyOrFieldInitialization(containingSymbol, node));
4343
}
4444

45-
private bool IsInPropertyOrFieldInitialization(ISymbol containingSymbol, SyntaxNode node)
45+
private static bool IsInPropertyOrFieldInitialization(ISymbol containingSymbol, SyntaxNode node)
4646
{
4747
return (containingSymbol.Kind == SymbolKind.Field || containingSymbol.Kind == SymbolKind.Property) &&
4848
containingSymbol.DeclaringSyntaxReferences
4949
.Select(declaringSyntaxReferences => declaringSyntaxReferences.GetSyntax())
5050
.Any(declaringSyntax => IsInPropertyInitialization(declaringSyntax, node) || IsInFieldInitialization(declaringSyntax, node));
5151
}
5252

53-
private bool IsInPropertyInitialization(SyntaxNode declarationSyntax, SyntaxNode node)
53+
private static bool IsInPropertyInitialization(SyntaxNode declarationSyntax, SyntaxNode node)
5454
=> declarationSyntax.IsKind(SyntaxKind.PropertyDeclaration) && declarationSyntax.Contains(node);
5555

56-
private bool IsInFieldInitialization(SyntaxNode declarationSyntax, SyntaxNode node)
56+
private static bool IsInFieldInitialization(SyntaxNode declarationSyntax, SyntaxNode node)
5757
=> declarationSyntax.GetAncestorsOrThis(n => n.IsKind(SyntaxKind.FieldDeclaration) && n.Contains(node)).Any();
5858

5959
protected override Location GetLocation(IOperation operation) => operation.Syntax.GetLocation();

src/Analyzers/CSharp/Analyzers/UseAutoProperty/CSharpUseAutoPropertyAnalyzer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void AddIneligibleField(ISymbol symbol)
118118
}
119119
}
120120

121-
private bool CheckExpressionSyntactically(ExpressionSyntax expression)
121+
private static bool CheckExpressionSyntactically(ExpressionSyntax expression)
122122
{
123123
if (expression.IsKind(SyntaxKind.SimpleMemberAccessExpression, out MemberAccessExpressionSyntax memberAccessExpression))
124124
{
@@ -152,7 +152,7 @@ protected override ExpressionSyntax GetGetterExpression(IMethodSymbol getMethod,
152152
return CheckExpressionSyntactically(expr) ? expr : null;
153153
}
154154

155-
private ExpressionSyntax GetGetterExpressionFromSymbol(IMethodSymbol getMethod, CancellationToken cancellationToken)
155+
private static ExpressionSyntax GetGetterExpressionFromSymbol(IMethodSymbol getMethod, CancellationToken cancellationToken)
156156
{
157157
var declaration = getMethod.DeclaringSyntaxReferences[0].GetSyntax(cancellationToken);
158158
switch (declaration)
@@ -167,7 +167,7 @@ private ExpressionSyntax GetGetterExpressionFromSymbol(IMethodSymbol getMethod,
167167
}
168168
}
169169

170-
private T GetSingleStatementFromAccessor<T>(AccessorDeclarationSyntax accessorDeclaration) where T : StatementSyntax
170+
private static T GetSingleStatementFromAccessor<T>(AccessorDeclarationSyntax accessorDeclaration) where T : StatementSyntax
171171
{
172172
var statements = accessorDeclaration?.Body?.Statements;
173173
if (statements?.Count == 1)
@@ -203,7 +203,7 @@ protected override ExpressionSyntax GetSetterExpression(
203203
return null;
204204
}
205205

206-
private ExpressionSyntax GetExpressionFromSetter(AccessorDeclarationSyntax setAccessor)
206+
private static ExpressionSyntax GetExpressionFromSetter(AccessorDeclarationSyntax setAccessor)
207207
=> setAccessor?.ExpressionBody?.Expression ??
208208
GetSingleStatementFromAccessor<ExpressionStatementSyntax>(setAccessor)?.Expression;
209209

src/Analyzers/CSharp/Analyzers/UseExpressionBody/UseExpressionBodyDiagnosticAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
8888
}
8989
}
9090

91-
private Diagnostic AnalyzeSyntax(
91+
private static Diagnostic AnalyzeSyntax(
9292
OptionSet optionSet, SyntaxNode declaration, UseExpressionBodyHelper helper)
9393
{
9494
var preferExpressionBodiedOption = optionSet.GetOption(helper.Option);

src/Analyzers/CSharp/Analyzers/UseImplicitOrExplicitType/CSharpTypeStyleDiagnosticAnalyzerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void HandleVariableDeclaration(SyntaxNodeAnalysisContext context)
7575
context.ReportDiagnostic(CreateDiagnostic(descriptor, declarationStatement, declaredType.StripRefIfNeeded().Span, typeStyle.Severity));
7676
}
7777

78-
private Diagnostic CreateDiagnostic(DiagnosticDescriptor descriptor, SyntaxNode declaration, TextSpan diagnosticSpan, ReportDiagnostic severity)
78+
private static Diagnostic CreateDiagnostic(DiagnosticDescriptor descriptor, SyntaxNode declaration, TextSpan diagnosticSpan, ReportDiagnostic severity)
7979
=> DiagnosticHelper.Create(descriptor, declaration.SyntaxTree.GetLocation(diagnosticSpan), severity, additionalLocations: null, properties: null);
8080
}
8181
}

src/Analyzers/CSharp/Analyzers/UseIndexOrRangeOperator/CSharpUseIndexOperatorDiagnosticAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private void AnalyzeInvokedMember(
220220
ImmutableDictionary<string, string>.Empty));
221221
}
222222

223-
private IPropertySymbol TryGetLengthLikeProperty(InfoCache infoCache, IMethodSymbol targetMethodOpt)
223+
private static IPropertySymbol TryGetLengthLikeProperty(InfoCache infoCache, IMethodSymbol targetMethodOpt)
224224
=> targetMethodOpt != null && infoCache.TryGetMemberInfo(targetMethodOpt, out var memberInfo)
225225
? memberInfo.LengthLikeProperty
226226
: null;

src/Analyzers/CSharp/Analyzers/UseIndexOrRangeOperator/CSharpUseRangeOperatorDiagnosticAnalyzer.InfoCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public InfoCache(Compilation compilation)
5151
}
5252
}
5353

54-
private IMethodSymbol GetSliceLikeMethod(INamedTypeSymbol namedType)
54+
private static IMethodSymbol GetSliceLikeMethod(INamedTypeSymbol namedType)
5555
=> namedType.GetMembers()
5656
.OfType<IMethodSymbol>()
5757
.Where(m => IsSliceLikeMethod(m))

0 commit comments

Comments
 (0)