Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups #2081

Merged
merged 6 commits into from Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -11,7 +11,7 @@ public ParsingState Parse(char symbol, StringBuilder statement)
{
if (isCommentContext)
{
var isEndOfMultilineComment = symbol == '/' && commentContextPreviousChar == '*';
var isEndOfMultilineComment = symbol is '/' && commentContextPreviousChar is '*';
jnyrup marked this conversation as resolved.
Show resolved Hide resolved
if (isEndOfMultilineComment)
{
isCommentContext = false;
Expand All @@ -26,9 +26,9 @@ public ParsingState Parse(char symbol, StringBuilder statement)
}

var isStartOfMultilineComment =
symbol == '*'
symbol is '*'
&& statement.Length > 0
&& statement[statement.Length - 1] == '/';
&& statement[^1] is '/';
if (isStartOfMultilineComment)
{
statement.Remove(statement.Length - 1, 1);
Expand Down
19 changes: 4 additions & 15 deletions Src/FluentAssertions/CallerIdentification/QuotesParsingStrategy.cs
@@ -1,5 +1,4 @@
using System.Linq;
using System.Text;
using System.Text;

namespace FluentAssertions.CallerIdentification;

Expand All @@ -11,7 +10,7 @@ internal class QuotesParsingStrategy : IParsingStrategy

public ParsingState Parse(char symbol, StringBuilder statement)
{
if (symbol == '"')
if (symbol is '"')
{
if (isQuoteContext)
{
Expand Down Expand Up @@ -54,17 +53,7 @@ public void NotifyEndOfLineReached()

private bool IsVerbatim(StringBuilder statement)
{
return
statement.Length >= 1
&&
new[]
{
"$@",
"@$",
}
.Any(verbatimStringOpener =>
previousChar == verbatimStringOpener[1]
&& statement[statement.Length - 1] == verbatimStringOpener[1]
&& statement[statement.Length - 2] == verbatimStringOpener[0]);
return (previousChar is '@' && statement.Length >= 2 && statement[^2] is '$' && statement[^1] is '@')
|| (previousChar is '$' && statement.Length >= 2 && statement[^2] is '@' && statement[^1] is '$');
jnyrup marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Up @@ -6,7 +6,7 @@ internal class SemicolonParsingStrategy : IParsingStrategy
{
public ParsingState Parse(char symbol, StringBuilder statement)
{
if (symbol == ';')
if (symbol is ';')
{
statement.Clear();
return ParsingState.Done;
Expand Down
Expand Up @@ -13,7 +13,7 @@ public ParsingState Parse(char symbol, StringBuilder statement)
return ParsingState.GoToNextSymbol;
}

var doesSymbolStartComment = symbol == '/' && statement.Length > 0 && statement[statement.Length - 1] == '/';
var doesSymbolStartComment = symbol is '/' && statement.Length > 0 && statement[^1] is '/';
if (!doesSymbolStartComment)
{
return ParsingState.InProgress;
Expand Down
4 changes: 2 additions & 2 deletions Src/FluentAssertions/CallerIdentifier.cs
Expand Up @@ -71,7 +71,7 @@ public static string DetermineCallerIdentity()
return caller;
}

private class StackFrameReference : IDisposable
private sealed class StackFrameReference : IDisposable
{
public int SkipStackFrameCount { get; }

Expand Down Expand Up @@ -161,7 +161,7 @@ private static bool IsDotNet(StackFrame frame)

private static bool IsCompilerServices(StackFrame frame)
{
return frame.GetMethod()?.DeclaringType?.Namespace == "System.Runtime.CompilerServices";
return frame.GetMethod()?.DeclaringType?.Namespace is "System.Runtime.CompilerServices";
}

private static string ExtractVariableNameFrom(StackFrame frame)
Expand Down
Expand Up @@ -3246,7 +3246,7 @@ private static string GetExpressionOrderString<TSelector>(Expression<Func<T, TSe
{
string orderString = propertyExpression.GetMemberPath().ToString();

orderString = orderString == "\"\"" ? string.Empty : "by " + orderString;
orderString = orderString is "\"\"" ? string.Empty : "by " + orderString;

return orderString;
}
Expand Down
6 changes: 3 additions & 3 deletions Src/FluentAssertions/Common/TypeExtensions.cs
Expand Up @@ -507,7 +507,7 @@ public static bool IsUnderNamespace(this Type type, string @namespace)

bool IsGlobalNamespace() => @namespace is null;
bool IsExactNamespace() => IsNamespacePrefix() && type.Namespace.Length == @namespace.Length;
bool IsParentNamespace() => IsNamespacePrefix() && type.Namespace[@namespace.Length] == '.';
bool IsParentNamespace() => IsNamespacePrefix() && type.Namespace[@namespace.Length] is '.';
bool IsNamespacePrefix() => type.Namespace?.StartsWith(@namespace, StringComparison.Ordinal) == true;
}

Expand All @@ -520,14 +520,14 @@ public static bool IsSameOrInherits(this Type actualType, Type expectedType)
public static MethodInfo GetExplicitConversionOperator(this Type type, Type sourceType, Type targetType)
{
return type
.GetConversionOperators(sourceType, targetType, name => name == "op_Explicit")
.GetConversionOperators(sourceType, targetType, name => name is "op_Explicit")
.SingleOrDefault();
}

public static MethodInfo GetImplicitConversionOperator(this Type type, Type sourceType, Type targetType)
{
return type
.GetConversionOperators(sourceType, targetType, name => name == "op_Implicit")
.GetConversionOperators(sourceType, targetType, name => name is "op_Implicit")
.SingleOrDefault();
}

Expand Down
Expand Up @@ -13,7 +13,7 @@ internal class MultiDimensionalArrayEquivalencyStep : IEquivalencyStep
{
public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator)
{
if (comparands.Expectation is not Array expectationAsArray || expectationAsArray?.Rank == 1)
if (comparands.Expectation is not Array expectationAsArray || expectationAsArray.Rank == 1)
{
return EquivalencyResult.ContinueWithNext;
}
Expand Down
Expand Up @@ -7,11 +7,11 @@ internal class CollectionMemberObjectInfo : IObjectInfo
public CollectionMemberObjectInfo(IObjectInfo context)
{
Path = GetAdjustedPropertyPath(context.Path);

#pragma warning disable CS0618
Type = context.Type;
#pragma warning restore CS0618

ParentType = context.ParentType;
RuntimeType = context.RuntimeType;
CompileTimeType = context.CompileTimeType;
Expand All @@ -23,7 +23,7 @@ private static string GetAdjustedPropertyPath(string propertyPath)
}

public Type Type { get; }

public Type ParentType { get; }

public string Path { get; set; }
Expand Down
Expand Up @@ -10,7 +10,7 @@ namespace FluentAssertions.Formatting;
/// </summary>
public class PredicateLambdaExpressionValueFormatter : IValueFormatter
{
public bool CanHandle(object value) => value is LambdaExpression lambdaExpression;
public bool CanHandle(object value) => value is LambdaExpression;

public void Format(object value, FormattedObjectGraph formattedGraph, FormattingContext context, FormatChild formatChild)
{
Expand Down Expand Up @@ -57,7 +57,7 @@ private static IEnumerable<Expression> ExtractChainOfExpressionsJoinedWithAndOpe
/// <summary>
/// Expression visitor which can detect whether the expression depends on parameters.
/// </summary>
private class ParameterDetector : ExpressionVisitor
private sealed class ParameterDetector : ExpressionVisitor
{
public bool HasParameters { get; private set; }

Expand All @@ -77,7 +77,7 @@ protected override Expression VisitParameter(ParameterExpression node)
/// <summary>
/// Expression visitor which can replace constant sub-expressions with constant values.
/// </summary>
private class ConstantSubExpressionReductionVisitor : ExpressionVisitor
private sealed class ConstantSubExpressionReductionVisitor : ExpressionVisitor
{
public override Expression Visit(Expression node)
{
Expand Down Expand Up @@ -114,7 +114,7 @@ private static bool ExpressionIsConstant(Expression expression)
/// Expression visitor which can extract sub-expressions from an expression which has the following form:
/// (SubExpression1) AND (SubExpression2) ... AND (SubExpressionN)
/// </summary>
private class AndOperatorChainExtractor : ExpressionVisitor
private sealed class AndOperatorChainExtractor : ExpressionVisitor
{
public List<Expression> AndChain { get; } = new List<Expression>();

Expand Down
Expand Up @@ -140,7 +140,7 @@ public void When_a_matching_rule_is_added_it_should_appear_in_the_exception_mess

internal class ForeignKeyMatchingRule : IMemberMatchingRule
{
public IMember Match(IMember expectedMember, object subject, INode parent, IEquivalencyAssertionOptions config)
public IMember Match(IMember expectedMember, object subject, INode parent, IEquivalencyAssertionOptions options)
{
string name = expectedMember.Name;
if (name.EndsWith("Id", StringComparison.Ordinal))
Expand Down Expand Up @@ -191,7 +191,7 @@ public void When_an_ordering_rule_is_added_it_should_appear_in_the_exception_mes

internal class StrictOrderingRule : IOrderingRule
{
public OrderStrictness Evaluate(IObjectInfo memberInfo)
public OrderStrictness Evaluate(IObjectInfo objectInfo)
{
return OrderStrictness.Strict;
}
Expand Down Expand Up @@ -626,7 +626,7 @@ private class AlwaysFailOnDateTimesEquivalencyStep : IEquivalencyStep
{
public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator)
{
if (comparands.Expectation is DateTime time)
if (comparands.Expectation is DateTime)
{
throw new Exception("Failed");
}
Expand Down