Repository navigation
SA1137: Choose common indentation for type members - #4301
Merged
Merged
Conversation
Use the most common indentation among a type's non-attribute members so one outlier does not force the rest of the class to move. Preserve first-member behavior when the counts tie. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Interleaved indentation counts can violate the documented first-member tie-break behavior.
1 open finding
What changed in this PR
Updates SA1137 to select the most common type-member indentation instead of anchoring on the first member.
Changes:
- Adds majority-indentation selection with first-member tie-breaking.
- Adds regression and tie-break tests.
- Updates all localized rule documentation.
| File | Description |
|---|---|
SA1137ElementsShouldHaveTheSameIndentation.cs |
Implements majority selection. |
SA1137UnitTests.cs |
Adds regression coverage. |
documentation/SA1137.md |
Documents behavior. |
documentation/cs-cz/SA1137.md |
Updates Czech documentation. |
documentation/ru-ru/SA1137.md |
Updates Russian documentation. |
documentation/zh-cn/SA1137.md |
Updates Chinese documentation. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Choose the first indentation level after all type-member counts are known so an interleaved final tie does not select whichever indentation reached the maximum earlier. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use majority selection for enum members too, and cover outlier enum indentation plus attribute lists outnumbering type members. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…g-starting-indentation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4301 +/- ##
==========================================
- Coverage 97.63% 97.63% -0.01%
==========================================
Files 1307 1307
Lines 141288 141516 +228
Branches 4677 4693 +16
==========================================
+ Hits 137944 138166 +222
- Misses 2134 2137 +3
- Partials 1210 1213 +3 🚀 New features to boost your workflow:
|
AArnott
marked this pull request as draft
October 14, 2026 15:46
auto-merge was automatically disabled
October 14, 2026 15:46
Pull request was converted to draft
Use the first attribute list when cleanup leaves no independently positioned members, as documented. Add class and enum code-fix regressions for indentation levels 2, 4, 4. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This was referenced Nov 11, 2026
This was referenced Nov 22, 2026
Open
[DPDBT] Bump Microsoft.CodeAnalysis.Analyzers and 6 others
sergey-rybalkin/CommandLine.Generators#63
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.


Fixes #3874
When the first type member is the sole indentation outlier, SA1137 previously used it as the anchor and the code fix moved the other members to match. Choose the most common indentation among non-attribute type members instead; when counts tie, retain first-member precedence. The test reproducing #3874 failed on master with the code fix changing the correctly indented members, then passed with this change.
Added regression coverage for the reported outlier and the tie-break behavior. The SA1137 suite passes on the C# 6 and C# 15 test projects (62 and 99 tests). Updated the rule documentation and existing translations.
Performance: no new callbacks or semantic analysis. A small indentation-count dictionary is allocated only when a type's member indentation is inconsistent. The rule now intentionally selects the majority indentation for type members; it does not use
.editorconfigindent_size.