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

Add rule for proper indentation with preconfigured number of spaces #227

Closed
Johennes opened this issue Nov 22, 2015 · 15 comments
Closed

Add rule for proper indentation with preconfigured number of spaces #227

Johennes opened this issue Nov 22, 2015 · 15 comments
Labels
rule-request Requests for a new rules.

Comments

@Johennes
Copy link

It would be great to check for a consistent indentation using e.g. 2 or 4 space for each level of nesting. Here are some violating examples:

class Foo {
let bar: String
}
class Foo {
    func bar() {
      return "foo"
    }
}

In addition, it'll also be nice to check for a consistent indentation of multi-line array/dictionary or string constructs. Violating examples:

let a = ["foo",
"foo",
"foo"]
let a = "foo"
+ "bar"
+ "foobar"
@jpsim jpsim added the rule-request Requests for a new rules. label Nov 23, 2015
@ecnepsnai
Copy link

Any update on this @jpsim ? Would really value this rule.

@jpsim
Copy link
Collaborator

jpsim commented Mar 18, 2016

It's up for grabs, no one has started work on this as far as I know.

@arsonik
Copy link

arsonik commented May 19, 2016

+1

@qasim
Copy link

qasim commented Jul 14, 2016

Working on this over at master...qasim:qasim/add-indentation. ☺️

@rudolf-adamkovic
Copy link

@qasim Any updates on this one?

@ldiqual
Copy link

ldiqual commented Nov 28, 2016

@Johennes @salutis @ecnepsnai I've created a PR addressing the first part of this issue. Please feel free to 👍 if you'd like to express interest! #873

@fredpi
Copy link
Collaborator

fredpi commented Jan 6, 2020

The new indentation_width opt-in rule is now available (see #2765), so maybe we can close this issue? Or should we wait until there's also a more advanced / flexible indentation rule?

@jpsim
Copy link
Collaborator

jpsim commented Jan 6, 2020

Let's close this. Anyone should feel empowered to file new, more specific issues about further enhancements. Thanks @fredpi!

@jpsim jpsim closed this as completed Jan 6, 2020
@keith
Copy link
Collaborator

keith commented Jan 8, 2020

FYI it looks like this rule is incompatible with this style:

        XCTAssertEqual(foo,
                       "blah")

which we use when the first line would overflow our column length limit

@fredpi
Copy link
Collaborator

fredpi commented Jan 8, 2020

@keith That's by design, as the rule suggests the following style in case of overflow:

XCTAssertEqual(
   foo,
   "blah"
)

@jpsim
Copy link
Collaborator

jpsim commented Jan 8, 2020

It' be awesome to add a configuration option to support the first style too.

@ptrkstr
Copy link

ptrkstr commented Aug 9, 2020

@fredpi @jpsim was support added for the first style?
It'd be useful for instances like:

[textField,
 callButton].forEach(addSubview)

@fredpi
Copy link
Collaborator

fredpi commented Aug 10, 2020

@patrickBDev Unfortunately, that's not yet available and currently, I don't have the time to implement it 🙁 Feel free though to open a new issue specifically explaining the desired changes!

@hisavali
Copy link

In my swiftlint.yml

there is entry

opt_in_rules:
  - indentation_width

When I run 👇 on terminal,

> echo "foo(top: "top", 
bottom: ."bottom", title: "hello world")" | swiftlint lint --no-cache --use-stdin --enable-all-rules

swiftlint prints violation warning:

<nopath>:2:1: warning: Indentation Width Violation: Code should be indented using one tab or 4 spaces. (indentation_width)
Done linting! Found 1 violation, 0 serious in 1 file.

However, when I run swift autocorrect, correction is not made.
Has anyone noticed something similar?

@fredpi
Copy link
Collaborator

fredpi commented Aug 26, 2020

@hisavali This is expected behavior, as autocorrection is not yet available for the indentation_width rule. Feel free to open a dedicated issue to track progress on such a feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule-request Requests for a new rules.
Projects
None yet
Development

Successfully merging a pull request may close this issue.