Ktlint: Poll: Should we support 2 spaces indentation?

Created on 27 May 2017  路  10Comments  路  Source: pinterest/ktlint

While official stance of JetBrains (citation needed) is 4 it's seems like we're alienating considerable chunk of the community (Square, Trello, etc.) by not allowing indentation with 2 spaces.

So the question is: should we allow 2 spaces for indentation or adhere to the official recommendation?

Most helpful comment

@joshfriend @scottmeschke @tedyoung @fwilhe @PaulWoitaschek @mttmllns I'm happy to announce that this issue is effectively resolved. Starting from 0.8.0 ktlint checks .editorconfig for indent_size:

# within project's root directory
printf '[*.{kt,kts}]\nindent_size=2' >> .editorconfig
ktlint

:balloon:

P.S. Recommendation is still to use 4 spaces for indentation. Official position has not changed :wink:

All 10 comments

Can't you add a config file where you specify stuff like that?

I could but that would be against the "no configuration" policy and we would be back in checkstyle territory. If there is a config file then why not to allow user to configure every aspect of ktlint? I mean, it requires minuscule amount of code and little effort, so why not?

The thing is, I want to keep ktlint simple for the user, keep it a "drop in" solution. You just add it and forget it (you can turn auto-correction (-F flag) on by default (as part of mvn verify / gradle check; or bind it to a commit hook) so that ktlint would do its job without bothering you too much).

Now, if there is a huge demand for 2 space indentation (and it seems like this is the case) - one way to tackle the problem is to have 2 ktlint artifacts (which have exactly the same set of rules with 1 distinction - indentation rule): ktlint (standard, 4 spaces indentation) and say ktlint-indent2 (2 spaces indentation adopted by Square). This is similar to standard vs semistandard.

Another option: get the value from .editorconfig :tada:

Read from .editorconfig if present and otherwise allow 2 or 4 spaces seems legit to me.

I really like that idea with editor config. It's zero config drop in but respects the project settings.

@joshfriend @scottmeschke @tedyoung @fwilhe @PaulWoitaschek @mttmllns I'm happy to announce that this issue is effectively resolved. Starting from 0.8.0 ktlint checks .editorconfig for indent_size:

# within project's root directory
printf '[*.{kt,kts}]\nindent_size=2' >> .editorconfig
ktlint

:balloon:

P.S. Recommendation is still to use 4 spaces for indentation. Official position has not changed :wink:

Do you account the intendation intent too?

@PaulWoitaschek if you mean continuation_indent_size then no - not yet. Right now ktlint does a very basic check - "is indentation multiple of indent_size or not?".

you forgot about Google - they're 2 spaces too.

Tbh, 2 spaces is so much better than 4, but we all have AOSP to thank for that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Tapchicoma picture Tapchicoma  路  3Comments

tonilopezmr picture tonilopezmr  路  4Comments

chao2zhang picture chao2zhang  路  4Comments

jbarr21 picture jbarr21  路  5Comments

artnc picture artnc  路  3Comments