Skip to content

Commit 765cffc

Browse files
Hook up option
1 parent 8f7b161 commit 765cffc

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/Analyzers/Core/Analyzers/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.Linq;
1111
using System.Runtime.CompilerServices;
1212
using System.Threading;
13-
using Microsoft.CodeAnalysis.CodeQuality;
1413
using Microsoft.CodeAnalysis.CodeStyle;
1514
using Microsoft.CodeAnalysis.Diagnostics;
1615
using Microsoft.CodeAnalysis.LanguageService;
@@ -27,10 +26,9 @@ internal abstract class AbstractRemoveUnusedMembersDiagnosticAnalyzer<
2726
TIdentifierNameSyntax,
2827
TTypeDeclarationSyntax,
2928
TMemberDeclarationSyntax>()
30-
: AbstractCodeQualityDiagnosticAnalyzer(
29+
: AbstractBuiltInUnnecessaryCodeStyleDiagnosticAnalyzer(
3130
[s_removeUnusedMembersRule, s_removeUnreadMembersRule],
32-
// We want to analyze references in generated code, but not report unused members in generated code.
33-
GeneratedCodeAnalysisFlags.Analyze)
31+
FadingOptions.FadeOutUnusedMembers)
3432
where TDocumentationCommentTriviaSyntax : SyntaxNode
3533
where TIdentifierNameSyntax : SyntaxNode
3634
where TTypeDeclarationSyntax : TMemberDeclarationSyntax
@@ -44,35 +42,43 @@ internal abstract class AbstractRemoveUnusedMembersDiagnosticAnalyzer<
4442
memberOptions: SymbolDisplayMemberOptions.IncludeContainingType);
4543

4644
// IDE0051: "Remove unused members" (Symbol is declared but never referenced)
47-
private static readonly DiagnosticDescriptor s_removeUnusedMembersRule = CreateDescriptor(
45+
private static readonly DiagnosticDescriptor s_removeUnusedMembersRule = CreateDescriptorWithId(
4846
IDEDiagnosticIds.RemoveUnusedMembersDiagnosticId,
4947
EnforceOnBuildValues.RemoveUnusedMembers,
48+
hasAnyCodeStyleOption: false,
5049
new LocalizableResourceString(nameof(AnalyzersResources.Remove_unused_private_members), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)),
5150
new LocalizableResourceString(nameof(AnalyzersResources.Private_member_0_is_unused), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)),
52-
hasAnyCodeStyleOption: false, isUnnecessary: true);
51+
isUnnecessary: true);
5352

5453
// IDE0052: "Remove unread members" (Value is written and/or symbol is referenced, but the assigned value is never read)
5554
// Internal for testing
56-
internal static readonly DiagnosticDescriptor s_removeUnreadMembersRule = CreateDescriptor(
55+
internal static readonly DiagnosticDescriptor s_removeUnreadMembersRule = CreateDescriptorWithId(
5756
IDEDiagnosticIds.RemoveUnreadMembersDiagnosticId,
5857
EnforceOnBuildValues.RemoveUnreadMembers,
58+
hasAnyCodeStyleOption: false,
5959
new LocalizableResourceString(nameof(AnalyzersResources.Remove_unread_private_members), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)),
6060
new LocalizableResourceString(nameof(AnalyzersResources.Private_member_0_can_be_removed_as_the_value_assigned_to_it_is_never_read), AnalyzersResources.ResourceManager, typeof(AnalyzersResources)),
61-
hasAnyCodeStyleOption: false, isUnnecessary: true);
61+
isUnnecessary: true);
6262

6363
protected abstract ISemanticFacts SemanticFacts { get; }
6464

6565
protected abstract IEnumerable<TTypeDeclarationSyntax> GetTypeDeclarations(INamedTypeSymbol namedType, CancellationToken cancellationToken);
6666
protected abstract SyntaxList<TMemberDeclarationSyntax> GetMembers(TTypeDeclarationSyntax typeDeclaration);
6767
protected abstract SyntaxNode GetParentIfSoleDeclarator(SyntaxNode declaration);
6868

69-
// We need to analyze the whole document even for edits within a method body,
70-
// because we might add or remove references to members in executable code.
71-
// For example, if we had an unused field with no references, then editing any single method body
72-
// to reference this field should clear the unused field diagnostic.
73-
// Hence, we need to re-analyze the declarations in the whole file for any edits within the document.
69+
/// <summary>
70+
/// We need to analyze the whole document even for edits within a method body, because we might add or remove
71+
/// references to members in executable code. For example, if we had an unused field with no references, then
72+
/// editing any single method body to reference this field should clear the unused field diagnostic. Hence, we need
73+
/// to re-analyze the declarations in the whole file for any edits within the document.
74+
/// </summary>
7475
public override DiagnosticAnalyzerCategory GetAnalyzerCategory() => DiagnosticAnalyzerCategory.SemanticDocumentAnalysis;
7576

77+
/// <summary>
78+
/// We want to analyze references in generated code, but not report unused members in generated code.
79+
/// </summary>
80+
protected override GeneratedCodeAnalysisFlags GeneratedCodeAnalysisFlags => GeneratedCodeAnalysisFlags.Analyze;
81+
7682
protected sealed override void InitializeWorker(AnalysisContext context)
7783
=> context.RegisterCompilationStartAction(compilationStartContext
7884
=> CompilationAnalyzer.CreateAndRegisterActions(compilationStartContext, this));

0 commit comments

Comments
 (0)