fix: align diagnostic categories with Usage, Correctness, and Best Practice#1087
fix: align diagnostic categories with Usage, Correctness, and Best Practice#1087
Conversation
…actice (#944) Add Correctness and BestPractice constants to DiagnosticCategory. Update 12 analyzers from Usage to Correctness (Moq1100-1210). Update 3 analyzers from Usage to Best Practice (Moq1400, Moq1410, Moq1500). Update AnalyzerReleases.Unshipped.md with Changed Rules section. Fix README.md categories for Moq1101 and Moq1420. Add 24 data-driven tests verifying each analyzer reports the correct category. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds two diagnostic category constants (Correctness, Best Practice), updates many analyzers' DiagnosticDescriptor Category values, adjusts release/docs entries, and introduces tests that validate each analyzer's reported category. Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the clarity and organization of Moq analyzers by introducing dedicated Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| C# | Mar 15, 2026 10:11p.m. | Review ↗ |
There was a problem hiding this comment.
Code Review
This pull request effectively realigns diagnostic categories to be more descriptive (Usage, Correctness, Best Practice), which improves clarity for users of the analyzers. The changes are consistently applied across all relevant analyzer definitions, documentation in README.md, and release notes. The addition of comprehensive, data-driven tests in DiagnosticCategoryTests.cs is an excellent measure to ensure these categories remain correct and prevent future regressions. I have one minor suggestion for consistency in DiagnosticCategory.cs.
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 |
Fix Moq1101 category from Usage to Correctness and Moq1420 category from Best Practice to Usage to match actual DiagnosticCategory values. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds AllAnalyzers_ShouldHaveCategoryTest which uses reflection to discover every concrete DiagnosticAnalyzer in the Analyzers assembly and asserts that each diagnostic ID is covered by one of the three existing theory data sets. This prevents new analyzers from silently missing a category test. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
Pull request overview
This PR aligns analyzer DiagnosticDescriptor.Category values with the documented category groups (Usage / Correctness / Best Practice), updates release notes and docs to match, and adds a dedicated test suite to prevent category regressions.
Changes:
- Added
CorrectnessandBestPracticecategory constants and migrated affected analyzers offUsage. - Updated release notes + docs tables to reflect the new categories.
- Added category verification tests for all analyzers/rules.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Moq.Analyzers.Test/DiagnosticCategoryTests.cs | Adds tests intended to validate per-rule diagnostic categories and enforce coverage for all analyzers. |
| src/Common/DiagnosticCategory.cs | Adds Correctness and BestPractice category constants for consistent reuse. |
| src/Analyzers/CallbackSignatureShouldMatchMockedMethodAnalyzer.cs | Migrates rule category to Correctness. |
| src/Analyzers/NoMethodsInPropertySetupAnalyzer.cs | Migrates rule category to Correctness. |
| src/Analyzers/SetupShouldBeUsedOnlyForOverridableMembersAnalyzer.cs | Migrates rule category to Correctness. |
| src/Analyzers/SetupShouldNotIncludeAsyncResultAnalyzer.cs | Migrates rule category to Correctness. |
| src/Analyzers/RaiseEventArgumentsShouldMatchEventSignatureAnalyzer.cs | Migrates rule category to Correctness. |
| src/Analyzers/RaisesEventArgumentsShouldMatchEventSignatureAnalyzer.cs | Migrates rule category to Correctness. |
| src/Analyzers/MethodSetupShouldSpecifyReturnValueAnalyzer.cs | Migrates rule category to Correctness. |
| src/Analyzers/EventSetupHandlerShouldMatchEventTypeAnalyzer.cs | Migrates rule category to Correctness. |
| src/Analyzers/ReturnsAsyncShouldBeUsedForAsyncMethodsAnalyzer.cs | Migrates rule category to Correctness. |
| src/Analyzers/ReturnsDelegateShouldReturnTaskAnalyzer.cs | Migrates rule category to Correctness. |
| src/Analyzers/SetupSequenceShouldBeUsedOnlyForOverridableMembersAnalyzer.cs | Migrates rule category to Correctness. |
| src/Analyzers/VerifyShouldBeUsedOnlyForOverridableMembersAnalyzer.cs | Migrates rule category to Correctness. |
| src/Analyzers/SetExplicitMockBehaviorAnalyzer.cs | Migrates rule category to Best Practice. |
| src/Analyzers/SetStrictMockBehaviorAnalyzer.cs | Migrates rule category to Best Practice. |
| src/Analyzers/MockRepositoryVerifyAnalyzer.cs | Migrates rule category to Best Practice. |
| src/Analyzers/AnalyzerReleases.Unshipped.md | Updates category for Moq1208 and introduces a “Changed Rules” section to track migrations. |
| docs/rules/README.md | Updates the rules index table to match the new categories. |
| README.md | Updates the top-level rules table to match the new categories. |
You can also share your feedback on Copilot code review. Take the survey.
| public static TheoryData<DiagnosticAnalyzer, string, string> UsageAnalyzers => | ||
| new() | ||
| { | ||
| { new NoSealedClassMocksAnalyzer(), "Moq1000", DiagnosticCategory.Usage }, | ||
| { new ConstructorArgumentsShouldMatchAnalyzer(), "Moq1001", DiagnosticCategory.Usage }, | ||
| { new ConstructorArgumentsShouldMatchAnalyzer(), "Moq1002", DiagnosticCategory.Usage }, | ||
| { new InternalTypeMustHaveInternalsVisibleToAnalyzer(), "Moq1003", DiagnosticCategory.Usage }, | ||
| { new NoMockOfLoggerAnalyzer(), "Moq1004", DiagnosticCategory.Usage }, | ||
| { new AsShouldBeUsedOnlyForInterfaceAnalyzer(), "Moq1300", DiagnosticCategory.Usage }, | ||
| { new MockGetShouldNotTakeLiteralsAnalyzer(), "Moq1301", DiagnosticCategory.Usage }, | ||
| { new LinqToMocksExpressionShouldBeValidAnalyzer(), "Moq1302", DiagnosticCategory.Usage }, | ||
| { new RedundantTimesSpecificationAnalyzer(), "Moq1420", DiagnosticCategory.Usage }, | ||
| }; |
|
|
||
| ### Changed Rules | ||
|
|
||
| Rule ID | New Category | New Severity | Old Category | Old Severity | Notes | ||
| --------|--------------|--------------|--------------|--------------|------- | ||
| Moq1100 | Correctness | Warning | Usage | Warning | CallbackSignatureShouldMatchMockedMethodAnalyzer | ||
| Moq1101 | Correctness | Warning | Usage | Warning | NoMethodsInPropertySetupAnalyzer | ||
| Moq1200 | Correctness | Error | Usage | Error | SetupShouldBeUsedOnlyForOverridableMembersAnalyzer | ||
| Moq1201 | Correctness | Error | Usage | Error | SetupShouldNotIncludeAsyncResultAnalyzer | ||
| Moq1202 | Correctness | Warning | Usage | Warning | RaiseEventArgumentsShouldMatchEventSignatureAnalyzer | ||
| Moq1203 | Correctness | Warning | Usage | Warning | MethodSetupShouldSpecifyReturnValueAnalyzer | ||
| Moq1204 | Correctness | Warning | Usage | Warning | RaisesEventArgumentsShouldMatchEventSignatureAnalyzer | ||
| Moq1205 | Correctness | Warning | Usage | Warning | EventSetupHandlerShouldMatchEventTypeAnalyzer | ||
| Moq1206 | Correctness | Warning | Usage | Warning | ReturnsAsyncShouldBeUsedForAsyncMethodsAnalyzer | ||
| Moq1207 | Correctness | Error | Usage | Error | SetupSequenceShouldBeUsedOnlyForOverridableMembersAnalyzer | ||
| Moq1210 | Correctness | Error | Usage | Error | VerifyShouldBeUsedOnlyForOverridableMembersAnalyzer | ||
| Moq1400 | Best Practice | Warning | Usage | Warning | SetExplicitMockBehaviorAnalyzer | ||
| Moq1410 | Best Practice | Info | Usage | Info | SetStrictMockBehaviorAnalyzer | ||
| Moq1500 | Best Practice | Warning | Usage | Warning | MockRepositoryVerifyAnalyzer |
Summary
Closes #944
CorrectnessandBestPracticeconstants toDiagnosticCategory.csAnalyzerReleases.Unshipped.mdwith Changed Rules section tracking all category migrationsBreaking Change
This is a breaking change for users who filter diagnostics by category in
.editorconfigorDirectory.Build.props.Affected rules: Moq1100, Moq1101, Moq1200-Moq1210, Moq1400, Moq1410, Moq1500
These rules previously reported category
Usage. They now reportCorrectnessorBest Practice.Migration: If you suppress or configure these rules by category, update your configuration:
Per-rule suppression (e.g.,
dotnet_diagnostic.Moq1100.severity = none) is unaffected.Category Mapping
Test plan
PedanticMode=true(0 warnings, 0 errors)DiagnosticCategoryTestsverifies each analyzer reports the correct categoryAnalyzerReleases.Unshipped.mdcategories matchDiagnosticDescriptorvalues🤖 Generated with Claude Code
Summary by CodeRabbit