Skip to content

SA1137: Choose common indentation for type members - #4301

Merged
AArnott merged 5 commits into
masterfrom
aarnott-sa1137-wrong-starting-indentation
Oct 14, 2026
Merged

AArnott merged 5 commits into
masterfrom
aarnott-sa1137-wrong-starting-indentation

Conversation

@AArnott

@AArnott AArnott commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

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 .editorconfig indent_size.

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>
@AArnott
AArnott marked this pull request as ready for review October 14, 2026 14:04
Copilot AI balanced review requested due to automatic review settings October 14, 2026 14:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 14:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Enum members remain inconsistent with the documented scope, and attribute-exclusion behavior lacks effective regression coverage.

2 open findings
1 resolved since last review

🧠 Review effort: Balanced

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>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 14:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation matches the documented behavior and covers the reported case and key edge cases.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 14, 2026 15:29
@AArnott
AArnott enabled auto-merge (squash) October 14, 2026 15:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The all-inline-attribute case incorrectly uses majority indentation instead of the documented first-attribute fallback.

1 open finding

🧠 Review effort: Balanced

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.48954% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.63%. Comparing base (4609815) to head (df3809f).

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AArnott
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>
@AArnott
AArnott marked this pull request as ready for review October 14, 2026 16:08
Copilot AI balanced review requested due to automatic review settings October 14, 2026 16:08
@AArnott
AArnott merged commit a45ce5b into master Oct 14, 2026
29 checks passed
@AArnott
AArnott deleted the aarnott-sa1137-wrong-starting-indentation branch October 14, 2026 16:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved findings remain, and targeted regressions cover the reported failure, tie-breaking, enums, and attribute handling.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

This was referenced Nov 22, 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.

SA1137 picks the wrong starting indentation

2 participants