Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SA1138: Indent elements correctly #2025

Open
sharwell opened this issue Jan 5, 2016 · 9 comments · May be fixed by #2034
Open

Implement SA1138: Indent elements correctly #2025

sharwell opened this issue Jan 5, 2016 · 9 comments · May be fixed by #2034
Assignees

Comments

@sharwell
Copy link
Member

sharwell commented Jan 5, 2016

Category: Readability
Title: Indent elements correctly
Description: A line of code is not indented the correct amount, according to the currently applied style settings for the project.

This rule is intended to be a general rule which will eventually enforce indentation according to policies defined in stylecop.json. This rule works alongside SA1137 (#2023) to increase the overall consistency of indentation in the project. The initial implementation will consist of the following specific behaviors to match settings exposed in Visual Studio:

  1. CSharpFormattingOptions.IndentBlock (override with indentBlock option in stylecop.json)
  2. CSharpFormattingOptions.IndentSwitchSection (override with indentSwitchSection in stylecop.json)
  3. CSharpFormattingOptions.IndentSwitchCaseSection (override with indentSwitchCaseSection in stylecop.json)
  4. CSharpFormattingOptions.LabelPositioning (override with labelPositioning in stylecop.json)
@nbarbettini
Copy link
Contributor

I'm not completely clear on the relationship between this and #2023. Is this more specific than SA1137, or less?

@sharwell
Copy link
Member Author

sharwell commented Jan 6, 2016

@nbarbettini Theoretically this rule could become more specific than SA1137 in the future, but we're a long way from that. Right now the two rules only partially overlap. For example, SA1137 ensures that when wrapping a method invocation so each argument is on its own line, those arguments are indented the same amount. The rule proposed here does not examine arguments at all. The goal is to progressively build up a flexible solution for indentation as a series of smaller steps.

Right now I'm only planning to include two rules:

  1. SA1137: This checks relative indentation of elements within a single group in isolation. It probably won't need the ability to configure it, and I don't expect users to find it problematic.
  2. The rule proposed here: For supported elements, this checks the absolute indentation of the elements. It will require a fairly large number of options to support various indentation requirements of projects.

@nbarbettini
Copy link
Contributor

Makes perfect sense now. 👍 on this.

@Noryoko
Copy link
Contributor

Noryoko commented Jan 6, 2016

👍 From me. I'm particularly interested in items 2 and 3.

@vweijsters
Copy link
Contributor

👍

@sharwell sharwell changed the title New rule proposal: Indent elements correctly Implement SA1138: Indent elements correctly Jan 6, 2016
@sharwell
Copy link
Member Author

sharwell commented Jan 7, 2016

Well, we can't use or reference the predefined formatting options from the analyzer, since they are defined in the workspaces assembly that isn't available during analysis (only during code fixes). So the behavior of null for each of these properties is to simply ignore the indentation of that item relative to its parent.

@abhiyadav1323
Copy link

Is there any progress on this?

@zmarty
Copy link

zmarty commented May 28, 2020

We need this too :)

@samuel-knutson
Copy link

samuel-knutson commented Aug 13, 2021

Any update? Very much looking forward to this rule. Right now, StyleCop doesn't complain about code like this:

  public class DateTimeProvider : IDateTimeProvider
    {
          public DateTime Now()
                {
            return DateTime.Now;
            }
                    }

Thanks for all your work on this project BTW!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants