This document provides context for the Gemini Code Assistant to understand the project structure, conventions, and tasks.
This project implements Roslyn analyzers for the ErrorOr<T> type to enforce safe access patterns.
- Goal: This project implements Roslyn analyzers for the
ErrorOr<T>type to enforce safe access patterns. - Key Files:
- Analyzers are located in
src/Result.Analyzers/Diagnostics/ErrorOr/. - Unit tests are in
tests/Result.Analyzers.Tests/. - A real-world sample project for observing analyzer behavior is in
tests/Result.Analyzers.Sample/.
- Analyzers are located in
- Testing Framework: The project uses
TUnitwithMicrosoft.Testing.Platform. Every piece of code we write, should be covered by a unit test. - Primary Test Command: To run the full suite, use the command:
dotnet run
- Important Limitation: The test runner configuration does not support the standard
dotnet test --filtercommand. To validate specific scenarios, you may need to run the full suite or temporarily disable other tests.
- Validation Scope: When implementing a new validation check (e.g., for a C# operator or pattern), the logic must be applied consistently to all relevant
ErrorOr<T>properties:.Value,.FirstError, and.Errors. The sharedResultAccessAnalyzerBaseclass should be used to facilitate this. - Sample Project Scenarios: The
tests/Result.Analyzers.Sample/Program.csfile contains important real-world test cases. These should be referenced to understand and replicate specific bugs or desired behaviors. For example,EAT5andEAT6are specific ternary operator test cases which are expected not to warn as they represent safe access patterns within the sample. - Analyzer Best Practices:
RS1038: Do not referenceMicrosoft.CodeAnalysis.Workspacespackages in the analyzer project (Result.Analyzers.csproj).RS1030: Avoid callingcompilation.GetSemanticModel()repeatedly. Instead, get theSemanticModelonce from theOperationAnalysisContext(context.Operation.SemanticModel) at the beginning of the analysis and pass it to helper methods.
- Test Refactoring: The test project currently uses
partialclasses. This is a temporary state and should be refactored into single, consolidated files when possible (Task noted inTodo.md).
The Todo.md file outlines a comprehensive roadmap for the project, including:
- v1.1 - v1.5: Additional property tracking, pattern matching support, ternary/conditional operators, variable state tracking, and advanced control flow.
- v1.G: General tasks like removing partial classes from tests.
- v1.6: Additional code fixes.
- v2.0 - v2.1: Custom attributes support and interprocedural analysis.
- v3.0: Multi-library support.
- Performance & Optimization: Benchmarking, profiling, and optimizations.
- Developer Experience: Improved diagnostic messages, tooltips, and configuration.
- Testing: Increased test coverage, integration tests, and performance regression tests.
- Documentation: Wiki, migration guide, best practices, and tutorials.
- Community & Ecosystem: Collaboration with other projects and community engagement.