Skip to content

Commit

Permalink
cleanup collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Meir017 committed Dec 10, 2023
1 parent fde81f1 commit ec4b5b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<FluentAssertionsCSharpSyntaxVisitor> Visitors
{
get
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ec4b5b4

Please sign in to comment.