Skip to content

Add configuration option to allow OfT suffix for generic types with any arity#1004

Merged
meziantou merged 4 commits intomainfrom
copilot/enable-oft-for-arity-greater-than-1
Feb 13, 2026
Merged

Add configuration option to allow OfT suffix for generic types with any arity#1004
meziantou merged 4 commits intomainfrom
copilot/enable-oft-for-arity-greater-than-1

Conversation

Copy link
Contributor

Copilot AI commented Feb 13, 2026

  • Add a new configuration option MA0048.allow_oft_for_all_generic_types to support OfT suffix for generic types with any arity
  • Update the analyzer logic to check this configuration option
  • Add tests for the new configuration option (arity > 1 cases)
  • Update the documentation file to describe the new configuration option
  • Run documentation generator to update markdown files
  • Run code review and address feedback
  • Run CodeQL security check (no issues found)
  • Validate all builds and tests pass (2748 tests passed)
  • Fix test compatibility with Roslyn 3.8 by making record struct test conditional on C# 11
Original prompt

This section details on the original issue you should resolve

<issue_title>MA0048: Accept OfT also for classes with arity > 1</issue_title>
<issue_description>We have the convention to name files for generic classes with suffix OfT, independent of the number of generic parameters.

The following file raises an MA0048 diagnostic if named FooOfT.cs:

public record struct Foo<T1, T2>(T1 Key, T2 Value);

Would be nice, if this would also be accepted by the rule.</issue_description>

<agent_instructions>Can you enable this behind a configuration option?</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 13, 2026 16:11
Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Copilot AI changed the title [WIP] Update MA0048 to accept OfT for classes with arity greater than 1 Add configuration option to allow OfT suffix for generic types with any arity Feb 13, 2026
Copilot AI requested a review from meziantou February 13, 2026 16:20
@meziantou
Copy link
Owner

@copilot One test fails on Roslyn 3.8. Can you make the test conditional based on the C# version?

[xUnit.net 00:00:59.52]     Meziantou.Analyzer.Test.Rules.FileNameMustMatchTypeNameAnalyzerTests.DoesMatchFileName_RecordStructWithArityGreaterThan1UsingOfT_WithConfiguration [FAIL]
[xUnit.net 00:00:59.52]       The code doesn't compile.
[xUnit.net 00:00:59.52]       
[xUnit.net 00:00:59.52]       public record struct Foo<T1, T2>(T1 Key, T2 Value);              ^^^^^^ CS1001: Identifier expected
[xUnit.net 00:00:59.52]                     ^^^^^^ CS1514: { expected
[xUnit.net 00:00:59.52]                     ^^^^^^ CS1513: } expected
[xUnit.net 00:00:59.52]                                       ^ CS1514: { expected
[xUnit.net 00:00:59.52]                                       ^ CS1513: } expected
[xUnit.net 00:00:59.52]                                       ^^^^^^^^^^^^^^^^^^^ CS8803: Top-level statements must precede namespace and type declarations.
[xUnit.net 00:00:59.52]                                       ^^^^^^^^^^^^^^^^^^ CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
[xUnit.net 00:00:59.52]                                        ^^ CS0246: The type or namespace name 'T1' could not be found (are you missing a using directive or an assembly reference?)
[xUnit.net 00:00:59.53]                                        ^^^^^^ CS8185: A declaration is not allowed in this context.
[xUnit.net 00:00:59.53]                                                ^^ CS0246: The type or namespace name 'T2' could not be found (are you missing a using directive or an assembly reference?)
[xUnit.net 00:00:59.53]                                                ^^^^^^^^ CS8185: A declaration is not allowed in this context.
[xUnit.net 00:00:59.53]       
[xUnit.net 00:00:59.53]       Stack Trace:
[xUnit.net 00:00:59.53]         /_/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs(310,0): at TestHelper.ProjectBuilder.GetSortedDiagnosticsFromDocuments(IList`1 analyzers, Document[] documents, Boolean compileSolution)
[xUnit.net 00:00:59.53]         /_/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs(142,0): at TestHelper.ProjectBuilder.GetSortedDiagnostics(IList`1 analyzers)
[xUnit.net 00:00:59.53]         /_/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs(52,0): at TestHelper.ProjectBuilder.VerifyDiagnostics(IList`1 analyzers, IList`1 expected)
[xUnit.net 00:00:59.53]         /_/tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.Validation.cs(35,0): at TestHelper.ProjectBuilder.ValidateAsync()
[xUnit.net 00:00:59.53]         /_/tests/Meziantou.Analyzer.Test/Rules/FileNameMustMatchTypeNameAnalyzerTests.cs(120,0): at Meziantou.Analyzer.Test.Rules.FileNameMustMatchTypeNameAnalyzerTests.DoesMatchFileName_RecordStructWithArityGreaterThan1UsingOfT_WithConfiguration()
[xUnit.net 00:00:59.53]         --- End of stack trace from previous location ---

Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 13, 2026

@copilot One test fails on Roslyn 3.8. Can you make the test conditional based on the C# version?

...

Fixed in commit 97cf812. The test is now wrapped in #if CSHARP11_OR_GREATER and includes .WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp11) to ensure it only runs when record struct syntax is supported.

@meziantou meziantou marked this pull request as ready for review February 13, 2026 17:24
This was referenced Feb 16, 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.

MA0048: Accept OfT also for classes with arity > 1

2 participants