Skip to content

Commit f65050b

Browse files
authored
utilities cleanup (#60)
* cleanup * more cleanup
1 parent fd79ab0 commit f65050b

34 files changed

+445
-364
lines changed

src/FluentAssertions.Analyzers.Tests/Tips/ExceptionsTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using FluentAssertions.Analyzers.Tips.Exceptions;
2-
using Microsoft.CodeAnalysis;
1+
using Microsoft.CodeAnalysis;
32
using Microsoft.VisualStudio.TestTools.UnitTesting;
43

54
namespace FluentAssertions.Analyzers.Tests.Tips

src/FluentAssertions.Analyzers.Tests/Tips/NullConditionalAssertionTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using FluentAssertions.Analyzers.Tips;
2-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
32
using System.Text;
43

54
namespace FluentAssertions.Analyzers.Tests.Tips

src/FluentAssertions.Analyzers/Constants.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
namespace FluentAssertions.Analyzers
1+
namespace FluentAssertions.Analyzers
22
{
33
public static class Constants
44
{
55
public static class DiagnosticProperties
66
{
77
public const string Title = nameof(Title);
8-
public const string VariableName = nameof(VariableName);
9-
public const string LambdaString = nameof(LambdaString);
10-
public const string ExpectedItemString = nameof(ExpectedItemString);
11-
public const string UnexpectedItemString = nameof(UnexpectedItemString);
12-
public const string BecauseArgumentsString = nameof(BecauseArgumentsString);
13-
public const string ArgumentString = nameof(ArgumentString);
14-
158
public const string VisitorName = nameof(VisitorName);
169
}
1710

src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public class CollectionShouldContainItemCodeFix : FluentAssertionsCodeFixProvide
4141

4242
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
4343
{
44-
var remove = new NodeReplacement.RemoveAndExtractArgumentsNodeReplacement("Contains");
44+
var remove = NodeReplacement.RemoveAndExtractArguments("Contains");
4545
var newExpression = GetNewExpression(expression, remove);
4646

47-
return GetNewExpression(newExpression, new NodeReplacement.RenameAndPrependArgumentsNodeReplacement("BeTrue", "Contain", remove.Arguments));
47+
return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeTrue", "Contain", remove.Arguments));
4848
}
4949
}
5050
}

src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainProperty.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression
5050
{
5151
if (properties.VisitorName == nameof(CollectionShouldContainPropertyAnalyzer.AnyShouldBeTrueSyntaxVisitor))
5252
{
53-
var remove = new NodeReplacement.RemoveAndExtractArgumentsNodeReplacement("Any");
53+
var remove = NodeReplacement.RemoveAndExtractArguments("Any");
5454
var newExpression = GetNewExpression(expression, remove);
5555

56-
return GetNewExpression(newExpression, new NodeReplacement.RenameAndPrependArgumentsNodeReplacement("BeTrue", "Contain", remove.Arguments));
56+
return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeTrue", "Contain", remove.Arguments));
5757
}
5858
else if (properties.VisitorName == nameof(CollectionShouldContainPropertyAnalyzer.WhereShouldNotBeEmptySyntaxVisitor))
5959
{
60-
var remove = new NodeReplacement.RemoveAndExtractArgumentsNodeReplacement("Where");
60+
var remove = NodeReplacement.RemoveAndExtractArguments("Where");
6161
var newExpression = GetNewExpression(expression, remove);
6262

63-
return GetNewExpression(newExpression, new NodeReplacement.RenameAndPrependArgumentsNodeReplacement("NotBeEmpty", "Contain", remove.Arguments));
63+
return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("NotBeEmpty", "Contain", remove.Arguments));
6464
}
6565
throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}");
6666
}

src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveElementAt0Null.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
using Microsoft.CodeAnalysis.CodeFixes;
33
using Microsoft.CodeAnalysis.CSharp.Syntax;
44
using Microsoft.CodeAnalysis.Diagnostics;
5+
using System.Collections.Generic;
56
using System.Collections.Immutable;
67
using System.Composition;
8+
using System.Linq;
79

810
namespace FluentAssertions.Analyzers
911
{
@@ -15,8 +17,10 @@ public class CollectionShouldHaveElementAt0NullAnalyzer : CollectionAnalyzer
1517

1618
public const string Message = "TODO";
1719

20+
protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors { get; } = Enumerable.Empty<FluentAssertionsCSharpSyntaxVisitor>();
21+
1822
protected override DiagnosticDescriptor Rule => new DiagnosticDescriptor(DiagnosticId, Title, Message, Category, DiagnosticSeverity.Info, true);
19-
23+
2024
protected override Diagnostic AnalyzeExpression(ExpressionSyntax expression, SemanticModel semanticModel)
2125
{
2226
return null;

src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveSameCount.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class CollectionShouldHaveSameCountCodeFix : FluentAssertionsCodeFixProvi
5252

5353
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
5454
{
55-
return GetNewExpression(expression, new NodeReplacement.RenameAndRemoveInvocationOfMethodOnFirstArgumentNodeReplacement("HaveCount", "HaveSameCount"));
55+
return GetNewExpression(expression, NodeReplacement.RenameAndRemoveInvocationOfMethodOnFirstArgument("HaveCount", "HaveSameCount"));
5656
}
5757
}
5858
}

src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public class CollectionShouldNotContainItemCodeFix : FluentAssertionsCodeFixProv
4040

4141
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
4242
{
43-
var remove = new NodeReplacement.RemoveAndExtractArgumentsNodeReplacement("Contains");
43+
var remove = NodeReplacement.RemoveAndExtractArguments("Contains");
4444
var newExpression = GetNewExpression(expression, remove);
4545

46-
return GetNewExpression(newExpression, new NodeReplacement.RenameAndPrependArgumentsNodeReplacement("BeFalse", "NotContain", remove.Arguments));
46+
return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeFalse", "NotContain", remove.Arguments));
4747
}
4848
}
4949
}

src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainProperty.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression
5858
{
5959
if (properties.VisitorName == nameof(CollectionShouldNotContainPropertyAnalyzer.AnyShouldBeFalseSyntaxVisitor))
6060
{
61-
var remove = new NodeReplacement.RemoveAndExtractArgumentsNodeReplacement("Any");
61+
var remove = NodeReplacement.RemoveAndExtractArguments("Any");
6262
var newExpression = GetNewExpression(expression, remove);
6363

6464
return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeFalse", "NotContain", remove.Arguments));
6565
}
6666
else if (properties.VisitorName == nameof(CollectionShouldNotContainPropertyAnalyzer.WhereShouldBeEmptySyntaxVisitor))
6767
{
68-
var remove = new NodeReplacement.RemoveAndExtractArgumentsNodeReplacement("Where");
68+
var remove = NodeReplacement.RemoveAndExtractArguments("Where");
6969
var newExpression = GetNewExpression(expression, remove);
7070

7171
return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeEmpty", "NotContain", remove.Arguments));

src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveSameCount.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ private static bool HasArgumentInvokingCountMethod(SeparatedSyntaxList<ArgumentS
4949
public class CollectionShouldNotHaveSameCountCodeFix : FluentAssertionsCodeFixProvider
5050
{
5151
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(CollectionShouldNotHaveSameCountAnalyzer.DiagnosticId);
52-
52+
5353
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
5454
{
55-
return GetNewExpression(expression, NodeReplacement.Remove("Count"), new NodeReplacement.RenameAndRemoveInvocationOfMethodOnFirstArgumentNodeReplacement("NotBe", "NotHaveSameCount"));
55+
return GetNewExpression(expression,
56+
NodeReplacement.Remove("Count"),
57+
NodeReplacement.RenameAndRemoveInvocationOfMethodOnFirstArgument("NotBe", "NotHaveSameCount")
58+
);
5659
}
5760
}
5861
}

0 commit comments

Comments
 (0)