Skip to content

Commit

Permalink
Convert '== null' and '!= null'
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Dec 9, 2023
1 parent cf8a4b7 commit f25646f
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static IEnumerable<SyntaxNode> GetLambdaStatements(SimpleLambdaExpressionSyntax
{
if (lambdaExpression.ExpressionBody is InvocationExpressionSyntax lambdaBody)
yield return ExpressionStatement(lambdaBody).WithAdditionalAnnotations(Formatter.Annotation, Simplifier.Annotation);
else if (lambdaExpression.Block != null && lambdaExpression.Block.Statements.Count != 0)
else if (lambdaExpression.Block is not null && lambdaExpression.Block.Statements.Count != 0)
foreach (var statement in lambdaExpression.Block.Statements)
yield return statement.WithAdditionalAnnotations(Formatter.Annotation, Simplifier.Annotation);
}
Expand Down Expand Up @@ -116,7 +116,7 @@ static async Task<Document> UseSingleMethod(
invocation.ArgumentList.Arguments[0].Expression is IdentifierNameSyntax collectionVariable)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
if (semanticModel != null && invocation.Parent != null)
if (semanticModel is not null && invocation.Parent is not null)
{
var statements = new List<SyntaxNode>();
var startLocation = invocation.GetLocation().SourceSpan.Start;
Expand Down
2 changes: 1 addition & 1 deletion src/xunit.analyzers/Utility/CodeAnalysisExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static bool IsInTestMethod(
if (semanticModel is null)
return false;

for (var parent = operation.Parent; parent != null; parent = parent.Parent)
for (var parent = operation.Parent; parent is not null; parent = parent.Parent)
{
if (parent is not IMethodBodyOperation methodBodyOperation)
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ static bool WrappedInContinueWith(
INamedTypeSymbol taskType,
XunitContext xunitContext)
{
for (; operation != null; operation = operation.Parent)
for (; operation is not null; operation = operation.Parent)
{
if (operation is not IInvocationOperation invocation)
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/xunit.analyzers/X1000/EnsureFixturesHaveASource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override void AnalyzeCompilation(

// Add types from IClassFixture<> and ICollectionFixture<> on the collection definition
var collectionFixtureTypes = ImmutableHashSet<INamedTypeSymbol>.Empty;
if (collectionDefinitionName != null)
if (collectionDefinitionName is not null)
{
var collectionDefinitionAttributeType = xunitContext.Core.CollectionDefinitionAttributeType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public override void AnalyzeCompilation(
: null;

// For params array of object, just consume everything that's left
if (paramsElementType != null
if (paramsElementType is not null
&& SymbolEqualityComparer.Default.Equals(paramsElementType, compilation.ObjectType)
&& paramsElementType.NullableAnnotation != NullableAnnotation.NotAnnotated)
{
Expand All @@ -124,12 +124,12 @@ public override void AnalyzeCompilation(
if (value.IsNull)
{
var isValueTypeParam =
paramsElementType != null
paramsElementType is not null
? paramsElementType.IsValueType && paramsElementType.OriginalDefinition.SpecialType != SpecialType.System_Nullable_T
: parameter.Type.IsValueType && parameter.Type.OriginalDefinition.SpecialType != SpecialType.System_Nullable_T;

var isNonNullableReferenceTypeParam =
paramsElementType != null
paramsElementType is not null
? paramsElementType.IsReferenceType && paramsElementType.NullableAnnotation == NullableAnnotation.NotAnnotated
: parameter.Type.IsReferenceType && parameter.Type.NullableAnnotation == NullableAnnotation.NotAnnotated;

Expand All @@ -156,7 +156,7 @@ public override void AnalyzeCompilation(
continue;

var isCompatible = ConversionChecker.IsConvertible(compilation, value.Type, parameter.Type, xunitContext);
if (!isCompatible && paramsElementType != null)
if (!isCompatible && paramsElementType is not null)
isCompatible = ConversionChecker.IsConvertible(compilation, value.Type, paramsElementType, xunitContext);

if (!isCompatible)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ static void VerifyDataMethodParameterUsage(
: null;

// For params array of object, just consume everything that's left
if (paramsElementType != null
if (paramsElementType is not null
&& SymbolEqualityComparer.Default.Equals(paramsElementType, compilation.ObjectType)
&& paramsElementType.NullableAnnotation != NullableAnnotation.NotAnnotated)
{
Expand All @@ -591,12 +591,12 @@ static void VerifyDataMethodParameterUsage(
if (!value.HasValue || value.Value is null)
{
var isValueTypeParam =
paramsElementType != null
paramsElementType is not null
? paramsElementType.IsValueType && paramsElementType.OriginalDefinition.SpecialType != SpecialType.System_Nullable_T
: parameter.Type.IsValueType && parameter.Type.OriginalDefinition.SpecialType != SpecialType.System_Nullable_T;

var isNonNullableReferenceTypeParam =
paramsElementType != null
paramsElementType is not null
? paramsElementType.IsReferenceType && paramsElementType.NullableAnnotation == NullableAnnotation.NotAnnotated
: parameter.Type.IsReferenceType && parameter.Type.NullableAnnotation == NullableAnnotation.NotAnnotated;

Expand All @@ -617,7 +617,7 @@ static void VerifyDataMethodParameterUsage(
continue;

var isCompatible = ConversionChecker.IsConvertible(compilation, valueType, parameter.Type, xunitContext);
if (!isCompatible && paramsElementType != null)
if (!isCompatible && paramsElementType is not null)
isCompatible = ConversionChecker.IsConvertible(compilation, valueType, paramsElementType, xunitContext);

if (!isCompatible)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void AnalyzeCompilation(
foreach (var attribute in symbol.GetAttributes())
{
var attributeType = attribute.AttributeClass;
if (attributeType != null && xunitContext.Core.FactAttributeType.IsAssignableFrom(attributeType))
if (attributeType is not null && xunitContext.Core.FactAttributeType.IsAssignableFrom(attributeType))
{
attributeTypes.Add(attributeType);
count++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void AnalyzeCompilation(
return;

var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodSyntax);
if (methodSymbol == null)
if (methodSymbol is null)
return;

var attributes = methodSymbol.GetAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ static bool IsCountPropertyOf(
INamedTypeSymbol? collectionType,
ISymbol symbol)
{
if (collectionType == null)
if (collectionType is null)
return false;

var memberSymbol = symbol;
var containingType = memberSymbol.ContainingType;
var countSymbol = collectionType.GetMember(nameof(ICollection.Count));
if (countSymbol == null)
if (countSymbol is null)
return false;

if (SymbolEqualityComparer.Default.Equals(countSymbol, symbol))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override void AnalyzeInvocation(
if (type.TypeKind == TypeKind.Interface)
{
var allInterfaces = (type as INamedTypeSymbol)?.AllInterfaces;
if (allInterfaces != null)
if (allInterfaces is not null)
{
var allMembers =
allInterfaces
Expand Down

0 comments on commit f25646f

Please sign in to comment.