Skip to content

Add MA0048 option for file-name prefix matching#1105

Merged
meziantou merged 8 commits intomainfrom
meziantou/ma0048-prefix-option
Apr 28, 2026
Merged

Add MA0048 option for file-name prefix matching#1105
meziantou merged 8 commits intomainfrom
meziantou/ma0048-prefix-option

Conversation

@meziantou
Copy link
Copy Markdown
Owner

Why

MA0048 currently requires an exact type/file-name match (with existing generic exceptions), which makes common patterns like Perk.cs plus PerkQuery or PerkHandler noisy. 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

  • Added a new analyzer option: MA0048.allow_type_name_prefix (default: false).
  • Updated MA0048 logic to accept top-level types whose names start with the file name when the option is enabled.
  • Added tests to cover both behaviors:
    • default behavior still reports PerkQuery in Perk.cs
    • configured behavior allows PerkQuery, PerkResponse, PerkHandler in Perk.cs and still reports DummyHandler
  • Updated docs/Rules/MA0048.md with examples and configuration documentation for the new option.

Validation

  • Ran FileNameMustMatchTypeNameAnalyzerTests on default Roslyn.
  • Ran FileNameMustMatchTypeNameAnalyzerTests with /p:RoslynVersion=roslyn4.2 and /p:RoslynVersion=roslyn4.14.
  • Ran dotnet run --project src/DocumentationGenerator and confirmed no additional generated doc changes were required.

meziantou and others added 8 commits April 27, 2026 12:46
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>
@meziantou meziantou merged commit d4b27d2 into main Apr 28, 2026
13 checks passed
@meziantou meziantou deleted the meziantou/ma0048-prefix-option branch April 28, 2026 00:47
This was referenced Apr 28, 2026
This was referenced May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant