Skip to content

Fix SA1134 code fix indentation on property accessors - #4262

Merged
AArnott merged 2 commits into
masterfrom
aarnott-sa1134-property-code-fix
Oct 13, 2026
Merged

AArnott merged 2 commits into
masterfrom
aarnott-sa1134-property-code-fix

Conversation

@AArnott

@AArnott AArnott commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1938
Closes #3728

Motivation

When attributes are placed on accessors in multi-line properties, the SA1134 code fix previously placed the attribute or accessor at an incorrect indentation level (under-indented by one or two indentation steps, e.g. 4 or 8 spaces instead of 12). In addition, PR #4260 exempted all bodyless property accessors from SA1134, which inadvertently suppressed diagnostics on multi-line auto-property accessors sharing lines.

Changes

  • Scoped the auto-property exemption in SA1134AttributesMustNotShareLine to single-line auto-properties where the accessor list braces are on the same line.
  • Added GetIndentationSteps in SA1134CodeFixProvider to calculate correct indentation for accessors (containing type + 2 steps) as well as member and type declarations.
  • Updated documentation in SA1134.md and ru-ru/SA1134.md to reflect the single-line auto-property exemption.
  • Added unit test coverage covering single-line auto-properties, multi-line auto-properties, non-auto properties, interfaces, nested classes, and K&R brace styles across C# 6 and C# 7 test suites.

…tion to single-line auto-properties

Fixes #1938
Closes #3728

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@AArnott
AArnott marked this pull request as ready for review October 13, 2026 02:35
Copilot AI balanced review requested due to automatic review settings October 13, 2026 02:36

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 new top-level and nested type indentation branches lack regression coverage.

1 open finding
What changed in this PR

Fixes SA1134 accessor indentation while preserving the exemption for single-line auto-properties.

Changes:

  • Restricts the auto-property exemption to single-line accessor lists.
  • Adds context-aware code-fix indentation.
  • Expands tests and updates English/Russian documentation.
File Description
test/​.../​SA1134UnitTests.cs Adds accessor regression tests.
test/​...CSharp7/​.../​SA1134CSharp7UnitTests.cs Tests single-line exemptions.
src/​.../​SA1134AttributesMustNotShareLine.cs Narrows the exemption.
src/​.../​SA1134CodeFixProvider.cs Corrects indentation calculation.
documentation/​SA1134.md Clarifies the exception.
documentation/​ru-ru/​SA1134.md Updates Russian documentation.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 13, 2026 02:42

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.

🔵 Needs a closer look

Top-level delegate attributes are still incorrectly indented by the new helper.

0 open findings

1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Top-level delegates receive incorrect attribute indentation

src/​StyleCop.Analyzers.CodeFixes/​ReadabilityRules/​SA1134CodeFixProvider.cs:139

This branch excludes DelegateDeclarationSyntax. A top-level delegate therefore falls through to the generic path, which derives CompilationUnit + 1 and inserts four spaces before a split attribute instead of keeping it at column 1. Handle delegates with the same containment-based path (and cover a top-level delegate fix) so all type declarations receive the corrected indentation.

🧠 Review effort: Balanced

@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.42209% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.62%. Comparing base (c819dec) to head (3f808ec).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #4262    +/-   ##
========================================
  Coverage   97.62%   97.62%            
========================================
  Files        1284     1284            
  Lines      136143   136648   +505     
  Branches     4370     4379     +9     
========================================
+ Hits       132907   133405   +498     
- Misses       2089     2092     +3     
- Partials     1147     1151     +4     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AArnott
AArnott merged commit 8697f5f into master Oct 13, 2026
30 checks passed
@AArnott
AArnott deleted the aarnott-sa1134-property-code-fix branch October 13, 2026 14:10
This was referenced Nov 11, 2026
This was referenced Nov 20, 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

2 participants