Report MA0051 on expression bodies of properties, indexers, and operators - #1517
Merged
Merged
Conversation
…tors MA0051 only looked at the accessor list of a property, so an expression-bodied property such as `int P => /* 80 lines */;` was never counted, while the same body on a method was reported. Indexers, operators, conversion operators, and events were not registered at all, so no body on those members was counted. Pass `PropertyDeclarationSyntax.ExpressionBody` to the analysis, register the missing member kinds, and share the accessor loop between properties, indexers, and events.
This was referenced Sep 12, 2026
Closed
This was referenced Sep 26, 2026
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.
What
MA0051 (Method is too long) never reported some member bodies:
PropertyDeclarationSyntax.ExpressionBodywas never passed to the analysis. Only the accessor list was inspected, soint P => /* 80 lines */;was invisible to the rule while the very same body on a method was reported.IndexerDeclaration,OperatorDeclaration,ConversionOperatorDeclarationandEventDeclarationwere not registered inInitialize, so no body on those members was counted at all.Changes
PropertyDeclarationSyntax: analyzenode.ExpressionBody, reported on the property identifier.this, plus the accessors;+,-, …);implicit/explicitkeyword;add/removeaccessors.AnalyzeAccessorshelper shared by properties, indexers, and events.docs/Rules/MA0051.md.Notes for reviewers
Testing
MethodShouldNotBeTooLongAnalyzerTestscovering property expression bodies (reporting and non-reporting), indexer expression bodies and accessors, event accessors, and operator / conversion-operator block and expression bodies.dotnet build: succeeds, 0 warnings.MethodShouldNotBeTooLongAnalyzerTests: 24/24 pass on Roslyn 4.8, 4.14, 5.0, 5.6 and 5.9 (15 tests before the change).dotnet run --project src/DocumentationGenerator: exits 0, no generated markdown changed.