Add MA0048 option for file-name prefix matching#1105
Merged
Conversation
Add a new MA0048.allow_type_name_prefix configuration option to allow top-level type names that start with the file name (for example, Perk.cs allowing PerkQuery/PerkResponse/PerkHandler). Include tests for default behavior and the new configured behavior, and document the option in MA0048 rule docs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Introduce MA0048.use_longest_type_name_prefix to make prefix-based matching require the file name to equal the longest common prefix of top-level type names in the file. Keep existing behavior as the default, add focused tests, and document the new option in MA0048 docs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace multiple MA0048 prefix-related options with a single enum-like MA0048.mode option (Exact, Prefix, LongestPrefix). Keep backward compatibility for legacy allow_type_name_prefix and use_longest_type_name_prefix settings, and update tests/docs accordingly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use LongestCommonPrefix as the only long-prefix mode value for MA0048.mode and remove the temporary LongestPrefix alias. Update tests and MA0048 documentation to reflect the new mode name while keeping existing legacy boolean option compatibility. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Include expected file-name information in MA0048 diagnostics so violations clearly indicate what file name is expected for exact, prefix, and longest-common-prefix modes. Update MA0048 tests and documentation message examples to match the new diagnostic output. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Refresh MA0048 diagnostic message examples and document full legacy compatibility mapping to mode values. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Apr 28, 2026
Closed
Closed
Closed
This was referenced May 4, 2026
Merged
Merged
Merged
Merged
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
MA0048 currently requires an exact type/file-name match (with existing generic exceptions), which makes common patterns like
Perk.csplusPerkQueryorPerkHandlernoisy. This change adds an opt-in configuration so teams can keep strict matching by default while allowing a file-name prefix convention when desired.What changed
MA0048.allow_type_name_prefix(default:false).PerkQueryinPerk.csPerkQuery,PerkResponse,PerkHandlerinPerk.csand still reportsDummyHandlerdocs/Rules/MA0048.mdwith examples and configuration documentation for the new option.Validation
FileNameMustMatchTypeNameAnalyzerTestson default Roslyn.FileNameMustMatchTypeNameAnalyzerTestswith/p:RoslynVersion=roslyn4.2and/p:RoslynVersion=roslyn4.14.dotnet run --project src/DocumentationGeneratorand confirmed no additional generated doc changes were required.