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

'If' should force curly braces #174

Closed
jasondhl opened this issue Mar 14, 2018 · 10 comments · Fixed by #727
Closed

'If' should force curly braces #174

jasondhl opened this issue Mar 14, 2018 · 10 comments · Fixed by #727

Comments

@jasondhl
Copy link

jasondhl commented Mar 14, 2018

As stated in the Android Kotlin Style Guide under Formatting, even if an If statement have only one line, it should be surrounded by a curly brace.

In my project, my code:

if (foo)
    bar = "hello world"

was deemed acceptable by ktlint. Is there anything I can do short of writing my own rule? Thanks in advance.

@shyiko
Copy link
Collaborator

shyiko commented Mar 14, 2018

Hi @jasondhl.
Unfortunately this is not enforced at the moment.
PR is welcome, though.

@jasondhl
Copy link
Author

Thanks for the prompt reply @shyiko ! Not very sure how to go about adding this Rule, but I'll check it out.

@jasondhl jasondhl reopened this Mar 15, 2018
@shyiko
Copy link
Collaborator

shyiko commented Mar 15, 2018

@jasondhl take a look inside https://github.com/shyiko/ktlint/tree/master/ktlint-ruleset-standard and https://github.com/shyiko/ktlint#ast (that's more or less all there is to it).

@jkaan
Copy link

jkaan commented May 31, 2018

@jasondhl @shyiko I could have a swing at this, I've implemented this exact rule for Detekt so I have some experience with this :). What do you guys think?

@shyiko
Copy link
Collaborator

shyiko commented May 31, 2018

@jkaan that would be great!

@shyiko
Copy link
Collaborator

shyiko commented Jun 23, 2018

This rule was contributed by @yokotaso (thank you, Tomoya!). It will be included in the next release.

@shyiko
Copy link
Collaborator

shyiko commented Jul 25, 2018

I'm reopening the issue as auto-correction isn't quite there yet.

@AleksandrSl
Copy link
Contributor

I can try to add auto-correction

@shyiko
Copy link
Collaborator

shyiko commented Oct 14, 2018

@AleksandrSl that would be awesome! (here is a little bit of context)

@AleksandrSl
Copy link
Contributor

Can I rely on IndentationRule to be run after other rules, or this rule should generate properly indented code?

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 a pull request may close this issue.

4 participants