docs(Moq1300): add guidance for generic type parameter scenarios#762
docs(Moq1300): add guidance for generic type parameter scenarios#762
Conversation
…eters and workarounds
…e parameters and suppression guidance
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughAdded an "Advanced Scenarios: Generic Type Parameters" subsection to docs/rules/Moq1300.md explaining Moq1300 behavior for generic type parameters constrained to interfaces, expanded suppression guidance (source-file and config options) with a pragma example, and referenced the linked issue. No API changes. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (1)
Comment |
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the Moq1300 analyzer documentation to address a specific scenario where the diagnostic fires for generic type parameters constrained to interfaces, even when the constraint should theoretically ensure safety.
- Adds comprehensive guidance for handling generic type parameters in Moq1300 scenarios
- Explains the C# language limitation that prevents "interface-only" constraints
- Provides clear criteria for when diagnostic suppression is appropriate vs. when to avoid it
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
docs/rules/Moq1300.md(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.md
📄 CodeRabbit inference engine (CONTRIBUTING.md)
All documentation and markdown reports must pass formatting checks. Use a markdown linter if available.
**/*.md: The generated Explainer/PRD must follow a specific Markdown structure with sections: Introduction/Overview, Goals, Non-Goals, User Stories, Functional Requirements, Design Considerations (Optional), Technical Considerations (Optional), Success Metrics, and Open Questions.
All user stories included in the Explainer/PRD must be validated for compliance with the INVEST mnemonic; if not compliant, the AI must rewrite them or ask the user for clarification.
The Explainer/PRD must be written for a junior developer audience, using explicit, unambiguous language, avoiding jargon, and targeting a grade 9 reading level.
The Explainer/PRD must explicitly list any open questions or assumptions at the end of the document; if there are none, it must state 'None'.
The Explainer/PRD must be formatted in Markdown (.md).The generated task list must be in Markdown format (.md)
When editing documentation, read markdown.instructions.md before proceeding
**/*.md: Read this instruction file before editing any Markdown (.md) file
Cross-reference related instruction files (csharp.instructions.md, project.instructions.md, text.instructions.md) before making Markdown changes
Complete the Validation Checklist before submitting Markdown changes
Stop and request help if uncertain about any Markdown requirement
Validate all links in Markdown before committing
Update the table of contents in Markdown when adding new sections
Ensure Markdown formatting and linting requirements are met (use a markdown linter if available)
Use clear, unambiguous language in all Markdown documentation
Provide concrete examples in Markdown for concepts and procedures
Create step-by-step guides in Markdown for complex processes
Include troubleshooting sections in Markdown documentation
Use consistent formatting across all Markdown documentation
Address and resolve all automated formatting/linting bot...
Files:
docs/rules/Moq1300.md
docs/rules/**/*.md
📄 CodeRabbit inference engine (CONTRIBUTING.md)
All documentation updates for analyzers must update
docs/rules/.For a new analyzer or code fix, add or modify rule documentation under docs/rules/
Update rule documentation under docs/rules/ for analyzer changes
Files:
docs/rules/Moq1300.md
⚙️ CodeRabbit configuration file
Evaluate the markdown files against the standards for Roslyn Code Analysis rules
Files:
docs/rules/Moq1300.md
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: rjmurillo/moq.analyzers#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-25T12:42:47.111Z
Learning: If a Moq feature has known limitations or edge cases (e.g., explicit interface implementation, event setup), document this in the test or analyzer code.
📚 Learning: 2025-08-04T08:54:29.141Z
Learnt from: CR
PR: rjmurillo/moq.analyzers#0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-08-04T08:54:29.141Z
Learning: Applies to tests/**/*.cs : Setups for explicit interface implementations must use the correct cast syntax in Moq analyzer tests.
Applied to files:
docs/rules/Moq1300.md
📚 Learning: 2025-07-26T15:57:15.819Z
Learnt from: rjmurillo
PR: rjmurillo/moq.analyzers#580
File: tests/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.cs:116-116
Timestamp: 2025-07-26T15:57:15.819Z
Learning: The CallbackSignatureShouldMatchMockedMethodAnalyzer (Moq1100) currently has a gap where it does not validate generic .Callback<T>() type parameters against the mocked method signature. This can lead to runtime errors when generic callback types don't match the expected method parameters, documented in CallbackSignatureShouldMatchMockedMethodAnalyzerTests.GenericCallbackValidation_CurrentLimitation_IsDocumented(). According to Moq documentation, .Callback<T> should provide compile-time type safety where T must match the argument type of the mocked method.
Applied to files:
docs/rules/Moq1300.md
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: build (ubuntu-24.04-arm)
- GitHub Check: build (windows-11-arm)
…e and advanced scenarios
Summary
Enhances the Moq1300 documentation to provide clear guidance for handling generic type parameters constrained to interfaces, addressing the scenario reported in #756.
Changes
Documentation Updates
docs/rules/Moq1300.mdKey Improvements
where T : IFooallows both interfaces and classes implementingIFoo, which creates the diagnostic scenarioRationale
This documentation-first approach was chosen over implementing a separate diagnostic due to:
Closes #756
CC @andrewimcclement
Summary by CodeRabbit