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

bugfix: Do not report fluentassertion diagnostic when there is a condition expression before the Should invocation #279

Merged
merged 1 commit into from
Jan 4, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 10 additions & 26 deletions src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public class OtherComponent
}

[TestMethod]
[NotImplemented(Reason = "https://github.com/fluentassertions/fluentassertions.analyzers/issues/276")]
[Implemented(Reason = "https://github.com/fluentassertions/fluentassertions.analyzers/issues/276")]
public void ShouldNotFailToAnalyze2()
{
const string source = @"
Expand All @@ -434,34 +434,18 @@ public class MyResponse
public IEnumerable<MyCollectionType>? MyCollection { get; set; }
}
public class MyCollectionType { }";
const string fixedSource = @"
#nullable enable
using FluentAssertions;
using FluentAssertions.Extensions;
using System.Linq;
using System.Collections.Generic;

public class TestClass
{
public static void Main()
{
var response = new MyResponse();
response.MyCollection?.Should().HaveCount(2);
}
}

public class MyResponse
{
public IEnumerable<MyCollectionType>? MyCollection { get; set; }
}
public class MyCollectionType { }";

DiagnosticVerifier.VerifyFix(new CodeFixVerifierArguments()
DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments()
.WithSources(source)
.WithFixedSources(fixedSource)
.WithDiagnosticAnalyzer<FluentAssertionsOperationAnalyzer>()
.WithCodeFixProvider<FluentAssertionsCodeFixProvider>()
.WithAllAnalyzers()
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)
.WithExpectedDiagnostics(new DiagnosticResult()
{
Id = NullConditionalAssertionAnalyzer.DiagnosticId,
Message = NullConditionalAssertionAnalyzer.Message,
Severity = DiagnosticSeverity.Warning,
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 13, 9) }
})
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public const string DiagnosticId = "FAA0001";
public const string Message = "Clean up FluentAssertion usage";

protected static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Title, Message, Constants.Tips.Category, DiagnosticSeverity.Info, true);

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / Performance regression check

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Release)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Release)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 20 in src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Enable analyzer release tracking for the analyzer project containing rule 'FAA0001' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule);

Expand Down Expand Up @@ -49,6 +49,11 @@
{
return;
}

if (assertion.Parent.Kind is OperationKind.ConditionalAccess)
{
return; // Handled by NullConditionalAssertionAnalyzer
}

var subject = invocation.Arguments[0].Value;

Expand Down
Loading