fluentassertions / fluentassertions/fluentassertions.analyzers
AD0001: InvalidOperationException on 2 rules
- Vorherrschende Sprache
- C#
- Sterne
- 131
- Forks
- 25
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
### Description
The rules `CollectionShouldContainSingleAnalyzer` and `CollectionShouldBeEmptyAnalyzer` throws `InvalidOperationException` with message `This operation does not apply to an empty instance`.
For some weird reason, the stack trace disappear every time I try to expand the issue, this one is the only one which remains:
```csharp
Severity Code Description Project File Line Category Suppression State Tool Detail Description
Warning AD0001 Analyzer 'FluentAssertions.Analyzers.CollectionShouldContainSingleAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'. SonarScanner.MSBuild.PreProcessor.Tests 1 Compiler Active FluentAssertions.Analyzers Analyzer 'FluentAssertions.Analyzers.CollectionShouldContainSingleAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: SonarScanner.MSBuild.PreProcessor.Tests
ISymbol: GetActiveRules_UseParamAsKey (Method)
SyntaxTree: C:\Src\SonarSource\scanner-msbuild\tests\SonarScanner.MSBuild.PreProcessor.Tests\SonarWebServiceTest.cs
SyntaxNode: [TestMethod] public void GetActiveRules_UseParamAsKey ... [MethodDeclarationSyntax]@[12810..14357) (264,8)-(305,9)
System.InvalidOperationException: This operation does not apply to an empty instance.
at System.Collections.Immutable.ImmutableStack`1.Peek()
at FluentAssertions.Analyzers.FluentAssertionsCSharpSyntaxVisitor.VisitElementAccessExpression(ElementAccessExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.ElementAccessExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.Visit(SyntaxNode node)
at FluentAssertions.Analyzers.FluentAssertionsCSharpSyntaxVisitor.VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.MemberAccessExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.Visit(SyntaxNode node)
at FluentAssertions.Analyzers.FluentAssertionsCSharpSyntaxVisitor.VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.MemberAccessExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.Visit(SyntaxNode node)
at FluentAssertions.Analyzers.FluentAssertionsCSharpSyntaxVisitor.VisitInvocationExpression(InvocationExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.Visit(SyntaxNode node)
at FluentAssertions.Analyzers.FluentAssertionsCSharpSyntaxVisitor.VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.MemberAccessExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.Visit(SyntaxNode node)
at FluentAssertions.Analyzers.FluentAssertionsCSharpSyntaxVisitor.VisitInvocationExpression(InvocationExpressionSyntax node)
at Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax.Accept(CSharpSyntaxVisitor visitor)
at FluentAssertions.Analyzers.FluentAssertionsAnalyzer`1.AnalyzeExpression(ExpressionSyntax expression, SemanticModel semanticModel)
at FluentAssertions.Analyzers.FluentAssertionsAnalyzer`1.AnalyzeCodeBlock(CodeBlockAnalysisContext context)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__49`2.b__49_0(ValueTuple`2 data)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
'.
```
### Complete minimal example reproducing the issue
My test project contains quite a lot of tests so it's quite hard to narrow down to the one failing but I hope that the stacktrace will help you understanding the failure.
### Versions
* Fluent Assertions Analyzers v0.11.4
* Fluent Assertions v5.5.3
* Targeting fwk 4.6.1
### Additional Information
Seems to be related to #78
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginne bei FluentAssertionsCSharpSyntaxVisitor.VisitElementAccessExpression, wo der Stacktrace zeigt, dass ImmutableStack.Peek() fehlschlägt, und reproduziere das Problem mit GetActiveRules_UseParamAsKey in SonarWebServiceTest.cs. Vergleiche die beiden betroffenen Analyzer und füge einen Regressionstest hinzu, der auf der gemeldeten Syntax basiert. Als abgeschlossen gilt die Arbeit, wenn keiner der beiden Analyzer für diesen Fall InvalidOperationException auslöst oder AD0001 ausgibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- csharp
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100