Skip to content

Add CT0011: prevent suppressing MA0051 (method too long)#22

Merged
magesoe merged 2 commits intomasterfrom
copilot/add-helper-methods-rule
Mar 3, 2026
Merged

Add CT0011: prevent suppressing MA0051 (method too long)#22
magesoe merged 2 commits intomasterfrom
copilot/add-helper-methods-rule

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

Suppressing MA0051 via #pragma warning disable MA0051 hides overly long methods instead of fixing them. CT0011 flags any such suppression and directs the developer to split the method into smaller helpers.

Changes

  • PragmaWarningDisableMA0051Analyzer — new analyzer registered on PragmaWarningDirectiveTrivia; triggers only on disable (not restore) directives containing MA0051
  • Resources — CT0011 title, message, and description strings added to Resources.resx / Resources.Designer.cs
  • Tests — covers single disable, disable alongside other codes, restore (no trigger), unrelated warning (no trigger), and multiple occurrences

Example

// CT0011: Do not suppress MA0051. Split the method into smaller helper methods instead.
#pragma warning disable MA0051
public void Execute() { /* 60+ lines */ }
#pragma warning restore MA0051
Original prompt

This section details on the original issue you should resolve

<issue_title>Prevent disabling method too long</issue_title>
<issue_description>This is always a good idea, an AI is lazy. I want another rule that says you can split the method with helper methods whenever someone writes

#pragma warning disable MA0051
```</issue_description>

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

<comments>
</comments>


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

Co-authored-by: magesoe <8904582+magesoe@users.noreply.github.com>
Copilot AI changed the title [WIP] Add rule to prevent disabling method too long Add CT0011: prevent suppressing MA0051 (method too long) Mar 2, 2026
@magesoe magesoe marked this pull request as ready for review March 3, 2026 08:05
@magesoe magesoe merged commit 15bbf7c into master Mar 3, 2026
1 check passed
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.

Prevent disabling method too long

2 participants