Skip to content

Commit 2ce8bb2

Browse files
committed
Remove unnecessary RegisterSyntaxNodeActionHonorExclusions helpers
1 parent 6905b08 commit 2ce8bb2

5 files changed

Lines changed: 17 additions & 66 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers/AnalyzerExtensions.cs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,6 @@ public static ConcurrentDictionary<SyntaxTree, bool> GetOrCreateGeneratedDocumen
9292
return headerCache.Item2;
9393
}
9494

95-
/// <summary>
96-
/// Register an action to be executed at completion of semantic analysis of a <see cref="SyntaxNode"/> with an
97-
/// appropriate kind. A syntax node action can report diagnostics about a <see cref="SyntaxNode"/>, and can also
98-
/// collect state information to be used by other syntax node actions or code block end actions.
99-
/// </summary>
100-
/// <remarks>This method honors exclusions.</remarks>
101-
/// <param name="context">Action will be executed only if the kind of a <see cref="SyntaxNode"/> matches
102-
/// <paramref name="syntaxKind"/>.</param>
103-
/// <param name="action">Action to be executed at completion of semantic analysis of a
104-
/// <see cref="SyntaxNode"/>.</param>
105-
/// <param name="syntaxKind">The kind of syntax that should be analyzed.</param>
106-
/// <typeparam name="TLanguageKindEnum">Enum type giving the syntax node kinds of the source language for which
107-
/// the action applies.</typeparam>
108-
public static void RegisterSyntaxNodeActionHonorExclusions<TLanguageKindEnum>(this CompilationStartAnalysisContext context, Action<SyntaxNodeAnalysisContext> action, TLanguageKindEnum syntaxKind)
109-
where TLanguageKindEnum : struct
110-
{
111-
context.RegisterSyntaxNodeActionHonorExclusions(action, LanguageKindArrays<TLanguageKindEnum>.GetOrCreateArray(syntaxKind));
112-
}
113-
11495
/// <summary>
11596
/// Register an action to be executed at completion of semantic analysis of a <see cref="SyntaxNode"/> with an
11697
/// appropriate kind. A syntax node action can report diagnostics about a <see cref="SyntaxNode"/>, and can also
@@ -130,42 +111,6 @@ public static void RegisterSyntaxNodeActionHonorExclusions<TLanguageKindEnum>(th
130111
context.RegisterSyntaxNodeActionHonorExclusions(action, LanguageKindArrays<TLanguageKindEnum>.GetOrCreateArray(syntaxKind));
131112
}
132113

133-
/// <summary>
134-
/// Register an action to be executed at completion of semantic analysis of a <see cref="SyntaxNode"/> with an
135-
/// appropriate kind. A syntax node action can report diagnostics about a <see cref="SyntaxNode"/>, and can also
136-
/// collect state information to be used by other syntax node actions or code block end actions.
137-
/// </summary>
138-
/// <remarks>This method honors exclusions.</remarks>
139-
/// <param name="context">Action will be executed only if the kind of a <see cref="SyntaxNode"/> matches one of
140-
/// the <paramref name="syntaxKinds"/> values.</param>
141-
/// <param name="action">Action to be executed at completion of semantic analysis of a
142-
/// <see cref="SyntaxNode"/>.</param>
143-
/// <param name="syntaxKinds">The kinds of syntax that should be analyzed.</param>
144-
/// <typeparam name="TLanguageKindEnum">Enum type giving the syntax node kinds of the source language for which
145-
/// the action applies.</typeparam>
146-
public static void RegisterSyntaxNodeActionHonorExclusions<TLanguageKindEnum>(this CompilationStartAnalysisContext context, Action<SyntaxNodeAnalysisContext> action, ImmutableArray<TLanguageKindEnum> syntaxKinds)
147-
where TLanguageKindEnum : struct
148-
{
149-
Compilation compilation = context.Compilation;
150-
ConcurrentDictionary<SyntaxTree, bool> cache = GetOrCreateGeneratedDocumentCache(compilation);
151-
152-
context.RegisterSyntaxNodeAction(
153-
c =>
154-
{
155-
if (c.IsGenerated(cache))
156-
{
157-
return;
158-
}
159-
160-
// Honor the containing document item's ExcludeFromStylecop=True
161-
// MSBuild metadata, if analyzers have access to it.
162-
//// TODO: code here
163-
164-
action(c);
165-
},
166-
syntaxKinds);
167-
}
168-
169114
/// <summary>
170115
/// Register an action to be executed at completion of semantic analysis of a <see cref="SyntaxNode"/> with an
171116
/// appropriate kind. A syntax node action can report diagnostics about a <see cref="SyntaxNode"/>, and can also

StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1501StatementMustNotBeOnASingleLine.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ private static void HandleCompilationStart(CompilationStartAnalysisContext conte
7777
// If SA1503 is suppressed, we need to handle compound blocks as well.
7878
if (context.IsAnalyzerSuppressed(SA1503BracesMustNotBeOmitted.DiagnosticId))
7979
{
80-
context.RegisterSyntaxNodeActionHonorExclusions(HandleIfStatement, SyntaxKind.IfStatement);
81-
context.RegisterSyntaxNodeActionHonorExclusions(ctx => CheckChildStatement(ctx, ctx.Node, ((DoStatementSyntax)ctx.Node).Statement), SyntaxKind.DoStatement);
82-
context.RegisterSyntaxNodeActionHonorExclusions(ctx => CheckChildStatement(ctx, ctx.Node, ((WhileStatementSyntax)ctx.Node).Statement), SyntaxKind.WhileStatement);
83-
context.RegisterSyntaxNodeActionHonorExclusions(ctx => CheckChildStatement(ctx, ctx.Node, ((ForStatementSyntax)ctx.Node).Statement), SyntaxKind.ForStatement);
84-
context.RegisterSyntaxNodeActionHonorExclusions(ctx => CheckChildStatement(ctx, ctx.Node, ((ForEachStatementSyntax)ctx.Node).Statement), SyntaxKind.ForEachStatement);
85-
context.RegisterSyntaxNodeActionHonorExclusions(ctx => CheckChildStatement(ctx, ctx.Node, ((LockStatementSyntax)ctx.Node).Statement), SyntaxKind.LockStatement);
86-
context.RegisterSyntaxNodeActionHonorExclusions(ctx => CheckChildStatement(ctx, ctx.Node, ((UsingStatementSyntax)ctx.Node).Statement), SyntaxKind.UsingStatement);
87-
context.RegisterSyntaxNodeActionHonorExclusions(ctx => CheckChildStatement(ctx, ctx.Node, ((FixedStatementSyntax)ctx.Node).Statement), SyntaxKind.FixedStatement);
80+
context.RegisterSyntaxNodeAction(HandleIfStatement, SyntaxKind.IfStatement);
81+
context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((DoStatementSyntax)ctx.Node).Statement), SyntaxKind.DoStatement);
82+
context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((WhileStatementSyntax)ctx.Node).Statement), SyntaxKind.WhileStatement);
83+
context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((ForStatementSyntax)ctx.Node).Statement), SyntaxKind.ForStatement);
84+
context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((ForEachStatementSyntax)ctx.Node).Statement), SyntaxKind.ForEachStatement);
85+
context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((LockStatementSyntax)ctx.Node).Statement), SyntaxKind.LockStatement);
86+
context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((UsingStatementSyntax)ctx.Node).Statement), SyntaxKind.UsingStatement);
87+
context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ctx.Node, ((FixedStatementSyntax)ctx.Node).Statement), SyntaxKind.FixedStatement);
8888
}
8989
}
9090

StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ internal class SA1119StatementMustNotUseUnnecessaryParenthesis : DiagnosticAnaly
7676
/// <inheritdoc/>
7777
public override void Initialize(AnalysisContext context)
7878
{
79+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
80+
7981
context.RegisterCompilationStartAction(CompilationStartAction);
8082
}
8183

@@ -86,7 +88,7 @@ private static void HandleCompilationStart(CompilationStartAnalysisContext conte
8688
// is disabled
8789
if (context.Compilation.Options.SpecificDiagnosticOptions.GetValueOrDefault(Descriptor.Id) != Microsoft.CodeAnalysis.ReportDiagnostic.Suppress)
8890
{
89-
context.RegisterSyntaxNodeActionHonorExclusions(ParenthesizedExpressionAction, SyntaxKind.ParenthesizedExpression);
91+
context.RegisterSyntaxNodeAction(ParenthesizedExpressionAction, SyntaxKind.ParenthesizedExpression);
9092
}
9193
}
9294

StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1404CodeAnalysisSuppressionMustHaveJustification.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ internal class SA1404CodeAnalysisSuppressionMustHaveJustification : DiagnosticAn
5959
/// <inheritdoc/>
6060
public override void Initialize(AnalysisContext context)
6161
{
62+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
63+
6264
context.RegisterCompilationStartAction(CompilationStartAction);
6365
}
6466

6567
private static void HandleCompilationStart(CompilationStartAnalysisContext context)
6668
{
6769
AnalyzerInstance instance = new AnalyzerInstance(context.Compilation.GetOrCreateUsingAliasCache());
68-
context.RegisterSyntaxNodeActionHonorExclusions(instance.HandleAttributeNode, SyntaxKind.Attribute);
70+
context.RegisterSyntaxNodeAction(instance.HandleAttributeNode, SyntaxKind.Attribute);
6971
}
7072

7173
/// <summary>

StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1121UseBuiltInTypeAlias.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,15 @@ internal class SA1121UseBuiltInTypeAlias : DiagnosticAnalyzer
142142
/// <inheritdoc/>
143143
public override void Initialize(AnalysisContext context)
144144
{
145+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
146+
145147
context.RegisterCompilationStartAction(CompilationStartAction);
146148
}
147149

148150
private static void HandleCompilationStart(CompilationStartAnalysisContext context)
149151
{
150152
Analyzer analyzer = new Analyzer(context.Compilation.GetOrCreateUsingAliasCache());
151-
context.RegisterSyntaxNodeActionHonorExclusions(analyzer.HandleIdentifierNameSyntax, SyntaxKind.IdentifierName);
153+
context.RegisterSyntaxNodeAction(analyzer.HandleIdentifierNameSyntax, SyntaxKind.IdentifierName);
152154
}
153155

154156
private sealed class Analyzer

0 commit comments

Comments
 (0)