-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor collection intersection code
- Loading branch information
Showing
5 changed files
with
47 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 3 additions & 40 deletions
43
src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldIntersectWith.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,11 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CodeFixes; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
namespace FluentAssertions.Analyzers; | ||
|
||
namespace FluentAssertions.Analyzers; | ||
|
||
[DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
public class CollectionShouldIntersectWithAnalyzer : CollectionAnalyzer | ||
public static class CollectionShouldIntersectWith | ||
{ | ||
public const string DiagnosticId = Constants.Tips.Collections.CollectionShouldIntersectWith; | ||
public const string Category = Constants.Tips.Category; | ||
|
||
public const string Message = "Use .Should().IntersectWith() instead."; | ||
|
||
protected override DiagnosticDescriptor Rule => new DiagnosticDescriptor(DiagnosticId, Title, Message, Category, DiagnosticSeverity.Info, true); | ||
protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors | ||
{ | ||
get | ||
{ | ||
yield return new IntersectShouldNotBeEmptySyntaxVisitor(); | ||
} | ||
} | ||
|
||
public class IntersectShouldNotBeEmptySyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor | ||
{ | ||
public IntersectShouldNotBeEmptySyntaxVisitor() : base(MemberValidator.HasArguments("Intersect"), MemberValidator.Should, new MemberValidator("NotBeEmpty")) | ||
{ | ||
} | ||
} | ||
} | ||
|
||
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(CollectionShouldIntersectWithCodeFix)), Shared] | ||
public class CollectionShouldIntersectWithCodeFix : FluentAssertionsCodeFixProvider | ||
{ | ||
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(CollectionShouldIntersectWithAnalyzer.DiagnosticId); | ||
|
||
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties) | ||
{ | ||
var remove = NodeReplacement.RemoveAndExtractArguments("Intersect"); | ||
var newExpression = GetNewExpression(expression, remove); | ||
|
||
return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("NotBeEmpty", "IntersectWith", remove.Arguments)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters