diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionAnalyzer.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionAnalyzer.cs index 8752cedc..9b715ac0 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionAnalyzer.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionAnalyzer.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; -using FluentAssertions.Analyzers.Utilities; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -10,25 +9,13 @@ namespace FluentAssertions.Analyzers; [DiagnosticAnalyzer(LanguageNames.CSharp)] -public class CollectionAnalyzer : FluentAssertionsAnalyzer +public class CollectionAnalyzer : CollectionBaseAnalyzer { public const string DiagnosticId = "FAA0001"; public const string Message = "Clean up FluentAssertion usage."; protected override DiagnosticDescriptor Rule => new DiagnosticDescriptor(DiagnosticId, Title, Message, Constants.Tips.Category, DiagnosticSeverity.Info, true); - protected override bool ShouldAnalyzeVariableNamedType(INamedTypeSymbol type, SemanticModel semanticModel) - { - return type.SpecialType != SpecialType.System_String - && type.IsTypeOrConstructedFromTypeOrImplementsType(SpecialType.System_Collections_Generic_IEnumerable_T); - } - - protected override bool ShouldAnalyzeVariableType(ITypeSymbol type, SemanticModel semanticModel) - { - return type.SpecialType != SpecialType.System_String - && type.IsTypeOrConstructedFromTypeOrImplementsType(SpecialType.System_Collections_Generic_IEnumerable_T); - } - protected override IEnumerable Visitors { get diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionBaseAnalyzer.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionBaseAnalyzer.cs new file mode 100644 index 00000000..ecd23cbd --- /dev/null +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionBaseAnalyzer.cs @@ -0,0 +1,19 @@ +using FluentAssertions.Analyzers.Utilities; +using Microsoft.CodeAnalysis; + +namespace FluentAssertions.Analyzers; + +public abstract class CollectionBaseAnalyzer : FluentAssertionsAnalyzer +{ + protected override bool ShouldAnalyzeVariableNamedType(INamedTypeSymbol type, SemanticModel semanticModel) + { + return type.SpecialType != SpecialType.System_String + && type.IsTypeOrConstructedFromTypeOrImplementsType(SpecialType.System_Collections_Generic_IEnumerable_T); + } + + protected override bool ShouldAnalyzeVariableType(ITypeSymbol type, SemanticModel semanticModel) + { + return type.SpecialType != SpecialType.System_String + && type.IsTypeOrConstructedFromTypeOrImplementsType(SpecialType.System_Collections_Generic_IEnumerable_T); + } +} diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveElementAt.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveElementAt.cs index e0c14b92..833f7b07 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveElementAt.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveElementAt.cs @@ -10,7 +10,7 @@ namespace FluentAssertions.Analyzers; [DiagnosticAnalyzer(LanguageNames.CSharp)] -public class CollectionShouldHaveElementAtAnalyzer : CollectionAnalyzer +public class CollectionShouldHaveElementAtAnalyzer : CollectionBaseAnalyzer { public const string DiagnosticId = Constants.Tips.Collections.CollectionShouldHaveElementAt; public const string Category = Constants.Tips.Category; diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeNullOrEmpty.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeNullOrEmpty.cs index 55f383d8..9c760916 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeNullOrEmpty.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeNullOrEmpty.cs @@ -10,7 +10,7 @@ namespace FluentAssertions.Analyzers; [DiagnosticAnalyzer(LanguageNames.CSharp)] -public class CollectionShouldNotBeNullOrEmptyAnalyzer : CollectionAnalyzer +public class CollectionShouldNotBeNullOrEmptyAnalyzer : CollectionBaseAnalyzer { public const string DiagnosticId = Constants.Tips.Collections.CollectionShouldNotBeNullOrEmpty; public const string Category = Constants.Tips.Category;