Skip to content

Commit b9f16b0

Browse files
authored
chore: format namespace (#237)
1 parent 0441304 commit b9f16b0

File tree

121 files changed

+3941
-4062
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+3941
-4062
lines changed

src/FluentAssertions.Analyzers/Constants.cs

Lines changed: 134 additions & 135 deletions
Large diffs are not rendered by default.

src/FluentAssertions.Analyzers/Tips/AsyncVoid.cs

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,74 +9,73 @@
99
using System.Linq;
1010
using System.Threading.Tasks;
1111

12-
namespace FluentAssertions.Analyzers
12+
namespace FluentAssertions.Analyzers;
13+
14+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
15+
public class AsyncVoidAnalyzer : DiagnosticAnalyzer
1316
{
14-
[DiagnosticAnalyzer(LanguageNames.CSharp)]
15-
public class AsyncVoidAnalyzer : DiagnosticAnalyzer
16-
{
17-
public const string DiagnosticId = Constants.CodeSmell.AsyncVoid;
18-
public const string Title = "Code Smell";
19-
public const string Message = "The assertions might not be executed when assigning an async void lambda to a Action";
17+
public const string DiagnosticId = Constants.CodeSmell.AsyncVoid;
18+
public const string Title = "Code Smell";
19+
public const string Message = "The assertions might not be executed when assigning an async void lambda to a Action";
2020

21-
public static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Title, Message, Constants.CodeSmell.Category, DiagnosticSeverity.Warning, true);
21+
public static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Title, Message, Constants.CodeSmell.Category, DiagnosticSeverity.Warning, true);
2222

23-
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);
23+
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);
2424

25-
public sealed override void Initialize(AnalysisContext context)
26-
{
27-
context.EnableConcurrentExecution();
28-
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
29-
context.RegisterCodeBlockAction(AnalyzeCodeBlock);
30-
}
25+
public sealed override void Initialize(AnalysisContext context)
26+
{
27+
context.EnableConcurrentExecution();
28+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
29+
context.RegisterCodeBlockAction(AnalyzeCodeBlock);
30+
}
3131

32-
private void AnalyzeCodeBlock(CodeBlockAnalysisContext context)
33-
{
34-
var method = context.CodeBlock as MethodDeclarationSyntax;
35-
if (method == null) return;
32+
private void AnalyzeCodeBlock(CodeBlockAnalysisContext context)
33+
{
34+
var method = context.CodeBlock as MethodDeclarationSyntax;
35+
if (method == null) return;
3636

37-
if (method.Body != null)
37+
if (method.Body != null)
38+
{
39+
foreach (var statement in method.Body.Statements.OfType<LocalDeclarationStatementSyntax>())
3840
{
39-
foreach (var statement in method.Body.Statements.OfType<LocalDeclarationStatementSyntax>())
40-
{
4141

42-
var diagnostic = AnalyzeStatement(context.SemanticModel, statement);
43-
if (diagnostic != null)
44-
{
45-
context.ReportDiagnostic(diagnostic);
46-
}
42+
var diagnostic = AnalyzeStatement(context.SemanticModel, statement);
43+
if (diagnostic != null)
44+
{
45+
context.ReportDiagnostic(diagnostic);
4746
}
48-
return;
4947
}
48+
return;
5049
}
50+
}
5151

52-
protected virtual Diagnostic AnalyzeStatement(SemanticModel semanticModel, LocalDeclarationStatementSyntax statement)
53-
{
54-
var symbolInfo = semanticModel.GetSymbolInfo(statement.Declaration.Type);
55-
if (symbolInfo.Symbol?.Name != nameof(Action)) return null;
52+
protected virtual Diagnostic AnalyzeStatement(SemanticModel semanticModel, LocalDeclarationStatementSyntax statement)
53+
{
54+
var symbolInfo = semanticModel.GetSymbolInfo(statement.Declaration.Type);
55+
if (symbolInfo.Symbol?.Name != nameof(Action)) return null;
5656

57-
foreach (var variable in statement.Declaration.Variables)
58-
{
59-
if (variable.Initializer == null) continue;
57+
foreach (var variable in statement.Declaration.Variables)
58+
{
59+
if (variable.Initializer == null) continue;
6060

61-
if (!(variable.Initializer.Value is ParenthesizedLambdaExpressionSyntax lambda)) continue;
61+
if (!(variable.Initializer.Value is ParenthesizedLambdaExpressionSyntax lambda)) continue;
6262

63-
if (lambda.AsyncKeyword.IsKind(SyntaxKind.AsyncKeyword))
64-
{
65-
return Diagnostic.Create(descriptor: Rule, location: statement.GetLocation());
66-
}
63+
if (lambda.AsyncKeyword.IsKind(SyntaxKind.AsyncKeyword))
64+
{
65+
return Diagnostic.Create(descriptor: Rule, location: statement.GetLocation());
6766
}
68-
69-
return null;
7067
}
68+
69+
return null;
7170
}
71+
}
7272

73-
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AsyncVoidCodeFix)), Shared]
74-
public class AsyncVoidCodeFix : CodeFixProvider
73+
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AsyncVoidCodeFix)), Shared]
74+
public class AsyncVoidCodeFix : CodeFixProvider
75+
{
76+
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(AsyncVoidAnalyzer.DiagnosticId);
77+
public override Task RegisterCodeFixesAsync(CodeFixContext context)
7578
{
76-
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(AsyncVoidAnalyzer.DiagnosticId);
77-
public override Task RegisterCodeFixesAsync(CodeFixContext context)
78-
{
79-
return Task.CompletedTask;
80-
}
79+
return Task.CompletedTask;
8180
}
8281
}
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
using FluentAssertions.Analyzers.Utilities;
22
using Microsoft.CodeAnalysis;
33

4-
namespace FluentAssertions.Analyzers
4+
namespace FluentAssertions.Analyzers;
5+
6+
public abstract class CollectionAnalyzer : FluentAssertionsAnalyzer
57
{
6-
public abstract class CollectionAnalyzer : FluentAssertionsAnalyzer
8+
protected override bool ShouldAnalyzeVariableNamedType(INamedTypeSymbol type, SemanticModel semanticModel)
79
{
8-
protected override bool ShouldAnalyzeVariableNamedType(INamedTypeSymbol type, SemanticModel semanticModel)
9-
{
10-
return type.SpecialType != SpecialType.System_String
11-
&& type.IsTypeOrConstructedFromTypeOrImplementsType(SpecialType.System_Collections_Generic_IEnumerable_T);
12-
}
13-
14-
override protected bool ShouldAnalyzeVariableType(ITypeSymbol type, SemanticModel semanticModel)
15-
{
16-
return type.SpecialType != SpecialType.System_String
17-
&& type.IsTypeOrConstructedFromTypeOrImplementsType(SpecialType.System_Collections_Generic_IEnumerable_T);
18-
}
10+
return type.SpecialType != SpecialType.System_String
11+
&& type.IsTypeOrConstructedFromTypeOrImplementsType(SpecialType.System_Collections_Generic_IEnumerable_T);
12+
}
1913

14+
override protected bool ShouldAnalyzeVariableType(ITypeSymbol type, SemanticModel semanticModel)
15+
{
16+
return type.SpecialType != SpecialType.System_String
17+
&& type.IsTypeOrConstructedFromTypeOrImplementsType(SpecialType.System_Collections_Generic_IEnumerable_T);
2018
}
19+
2120
}

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

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,83 +7,82 @@
77
using System.Collections.Immutable;
88
using System.Composition;
99

10-
namespace FluentAssertions.Analyzers
10+
namespace FluentAssertions.Analyzers;
11+
12+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
13+
public class CollectionShouldBeEmptyAnalyzer : CollectionAnalyzer
1114
{
12-
[DiagnosticAnalyzer(LanguageNames.CSharp)]
13-
public class CollectionShouldBeEmptyAnalyzer : CollectionAnalyzer
14-
{
15-
public const string DiagnosticId = Constants.Tips.Collections.CollectionsShouldBeEmpty;
16-
public const string Category = Constants.Tips.Category;
15+
public const string DiagnosticId = Constants.Tips.Collections.CollectionsShouldBeEmpty;
16+
public const string Category = Constants.Tips.Category;
1717

18-
public const string Message = "Use .Should().BeEmpty() instead.";
18+
public const string Message = "Use .Should().BeEmpty() instead.";
1919

20-
protected override DiagnosticDescriptor Rule => new DiagnosticDescriptor(DiagnosticId, Title, Message, Category, DiagnosticSeverity.Info, true);
21-
protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors
20+
protected override DiagnosticDescriptor Rule => new DiagnosticDescriptor(DiagnosticId, Title, Message, Category, DiagnosticSeverity.Info, true);
21+
protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors
22+
{
23+
get
2224
{
23-
get
24-
{
25-
yield return new AnyShouldBeFalseSyntaxVisitor();
26-
yield return new ShouldHaveCount0SyntaxVisitor();
27-
}
25+
yield return new AnyShouldBeFalseSyntaxVisitor();
26+
yield return new ShouldHaveCount0SyntaxVisitor();
2827
}
28+
}
2929

30-
public class AnyShouldBeFalseSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor
30+
public class AnyShouldBeFalseSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor
31+
{
32+
public AnyShouldBeFalseSyntaxVisitor() : base(MemberValidator.MethodNotContainingLambda("Any"), MemberValidator.Should, new MemberValidator("BeFalse"))
3133
{
32-
public AnyShouldBeFalseSyntaxVisitor() : base(MemberValidator.MethodNotContainingLambda("Any"), MemberValidator.Should, new MemberValidator("BeFalse"))
33-
{
34-
}
3534
}
35+
}
3636

37-
public class ShouldHaveCount0SyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor
37+
public class ShouldHaveCount0SyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor
38+
{
39+
public ShouldHaveCount0SyntaxVisitor() : base(MemberValidator.Should, new MemberValidator("HaveCount", HaveCountArgumentsValidator))
3840
{
39-
public ShouldHaveCount0SyntaxVisitor() : base(MemberValidator.Should, new MemberValidator("HaveCount", HaveCountArgumentsValidator))
40-
{
41-
}
41+
}
4242

43-
private static bool HaveCountArgumentsValidator(SeparatedSyntaxList<ArgumentSyntax> arguments, SemanticModel semanticModel)
44-
{
45-
if (!arguments.Any()) return false;
43+
private static bool HaveCountArgumentsValidator(SeparatedSyntaxList<ArgumentSyntax> arguments, SemanticModel semanticModel)
44+
{
45+
if (!arguments.Any()) return false;
4646

47-
return arguments[0].Expression is LiteralExpressionSyntax literal
48-
&& literal.Token.Value is int argument
49-
&& argument == 0;
50-
}
47+
return arguments[0].Expression is LiteralExpressionSyntax literal
48+
&& literal.Token.Value is int argument
49+
&& argument == 0;
5150
}
5251
}
52+
}
5353

54-
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(CollectionShouldBeEmptyCodeFix)), Shared]
55-
public class CollectionShouldBeEmptyCodeFix : FluentAssertionsCodeFixProvider
56-
{
57-
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(CollectionShouldBeEmptyAnalyzer.DiagnosticId);
54+
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(CollectionShouldBeEmptyCodeFix)), Shared]
55+
public class CollectionShouldBeEmptyCodeFix : FluentAssertionsCodeFixProvider
56+
{
57+
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(CollectionShouldBeEmptyAnalyzer.DiagnosticId);
5858

59-
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
59+
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
60+
{
61+
switch (properties.VisitorName)
6062
{
61-
switch (properties.VisitorName)
62-
{
63-
case nameof(CollectionShouldBeEmptyAnalyzer.AnyShouldBeFalseSyntaxVisitor):
64-
return GetNewExpression(expression, NodeReplacement.Remove("Any"), NodeReplacement.Rename("BeFalse", "BeEmpty"));
65-
case nameof(CollectionShouldBeEmptyAnalyzer.ShouldHaveCount0SyntaxVisitor):
66-
return GetNewExpression(expression, new HaveCountNodeReplacement());
67-
default:
68-
throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}");
69-
}
63+
case nameof(CollectionShouldBeEmptyAnalyzer.AnyShouldBeFalseSyntaxVisitor):
64+
return GetNewExpression(expression, NodeReplacement.Remove("Any"), NodeReplacement.Rename("BeFalse", "BeEmpty"));
65+
case nameof(CollectionShouldBeEmptyAnalyzer.ShouldHaveCount0SyntaxVisitor):
66+
return GetNewExpression(expression, new HaveCountNodeReplacement());
67+
default:
68+
throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}");
7069
}
70+
}
7171

72-
private class HaveCountNodeReplacement : NodeReplacement
72+
private class HaveCountNodeReplacement : NodeReplacement
73+
{
74+
public override bool IsValidNode(LinkedListNode<MemberAccessExpressionSyntax> listNode) => listNode.Value.Name.Identifier.Text == "HaveCount";
75+
public override SyntaxNode ComputeOld(LinkedListNode<MemberAccessExpressionSyntax> listNode) => listNode.Value.Parent;
76+
public override SyntaxNode ComputeNew(LinkedListNode<MemberAccessExpressionSyntax> listNode)
7377
{
74-
public override bool IsValidNode(LinkedListNode<MemberAccessExpressionSyntax> listNode) => listNode.Value.Name.Identifier.Text == "HaveCount";
75-
public override SyntaxNode ComputeOld(LinkedListNode<MemberAccessExpressionSyntax> listNode) => listNode.Value.Parent;
76-
public override SyntaxNode ComputeNew(LinkedListNode<MemberAccessExpressionSyntax> listNode)
77-
{
78-
var invocation = (InvocationExpressionSyntax)listNode.Value.Parent;
78+
var invocation = (InvocationExpressionSyntax)listNode.Value.Parent;
7979

80-
invocation = invocation.ReplaceNode(listNode.Value, listNode.Value.WithName(SyntaxFactory.IdentifierName("BeEmpty")));
80+
invocation = invocation.ReplaceNode(listNode.Value, listNode.Value.WithName(SyntaxFactory.IdentifierName("BeEmpty")));
8181

82-
// remove the 0 argument
83-
var arguments = invocation.ArgumentList.Arguments.RemoveAt(0);
82+
// remove the 0 argument
83+
var arguments = invocation.ArgumentList.Arguments.RemoveAt(0);
8484

85-
return invocation.WithArgumentList(invocation.ArgumentList.WithArguments(arguments));
86-
}
85+
return invocation.WithArgumentList(invocation.ArgumentList.WithArguments(arguments));
8786
}
8887
}
8988
}

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

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,45 @@
66
using System.Collections.Immutable;
77
using System.Composition;
88

9-
namespace FluentAssertions.Analyzers
9+
namespace FluentAssertions.Analyzers;
10+
11+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
12+
public class CollectionShouldBeInAscendingOrderAnalyzer : CollectionAnalyzer
1013
{
11-
[DiagnosticAnalyzer(LanguageNames.CSharp)]
12-
public class CollectionShouldBeInAscendingOrderAnalyzer : CollectionAnalyzer
13-
{
14-
public const string DiagnosticId = Constants.Tips.Collections.CollectionShouldBeInAscendingOrder;
15-
public const string Category = Constants.Tips.Category;
14+
public const string DiagnosticId = Constants.Tips.Collections.CollectionShouldBeInAscendingOrder;
15+
public const string Category = Constants.Tips.Category;
1616

17-
public const string Message = "Use .Should().BeInAscendingOrder() instead.";
17+
public const string Message = "Use .Should().BeInAscendingOrder() instead.";
1818

19-
protected override DiagnosticDescriptor Rule => new DiagnosticDescriptor(DiagnosticId, Title, Message, Category, DiagnosticSeverity.Info, true);
20-
protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors
19+
protected override DiagnosticDescriptor Rule => new DiagnosticDescriptor(DiagnosticId, Title, Message, Category, DiagnosticSeverity.Info, true);
20+
protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors
21+
{
22+
get
2123
{
22-
get
23-
{
24-
yield return new OrderByShouldEqualSyntaxVisitor();
25-
}
24+
yield return new OrderByShouldEqualSyntaxVisitor();
2625
}
26+
}
2727

28-
public class OrderByShouldEqualSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor
28+
public class OrderByShouldEqualSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor
29+
{
30+
public OrderByShouldEqualSyntaxVisitor() : base(MemberValidator.MethodContainingLambda("OrderBy"), MemberValidator.Should, MemberValidator.ArgumentIsVariable("Equal"))
2931
{
30-
public OrderByShouldEqualSyntaxVisitor() : base(MemberValidator.MethodContainingLambda("OrderBy"), MemberValidator.Should, MemberValidator.ArgumentIsVariable("Equal"))
31-
{
32-
}
3332
}
3433
}
34+
}
3535

36-
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(CollectionShouldBeInAscendingOrderCodeFix)), Shared]
37-
public class CollectionShouldBeInAscendingOrderCodeFix : FluentAssertionsCodeFixProvider
38-
{
39-
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(CollectionShouldBeInAscendingOrderAnalyzer.DiagnosticId);
36+
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(CollectionShouldBeInAscendingOrderCodeFix)), Shared]
37+
public class CollectionShouldBeInAscendingOrderCodeFix : FluentAssertionsCodeFixProvider
38+
{
39+
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(CollectionShouldBeInAscendingOrderAnalyzer.DiagnosticId);
4040

41-
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
42-
{
43-
var remove = NodeReplacement.RemoveAndExtractArguments("OrderBy");
44-
var newExpression = GetNewExpression(expression, remove);
41+
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties)
42+
{
43+
var remove = NodeReplacement.RemoveAndExtractArguments("OrderBy");
44+
var newExpression = GetNewExpression(expression, remove);
4545

46-
newExpression = GetNewExpression(newExpression, NodeReplacement.RenameAndRemoveFirstArgument("Equal", "BeInAscendingOrder"));
46+
newExpression = GetNewExpression(newExpression, NodeReplacement.RenameAndRemoveFirstArgument("Equal", "BeInAscendingOrder"));
4747

48-
return GetNewExpression(newExpression, NodeReplacement.PrependArguments("BeInAscendingOrder", remove.Arguments));
49-
}
48+
return GetNewExpression(newExpression, NodeReplacement.PrependArguments("BeInAscendingOrder", remove.Arguments));
5049
}
5150
}

0 commit comments

Comments
 (0)