Skip to content
New issue

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

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

Already on GitHub? # to your account

ktlintFormat does not autoformat #129

Closed
vanniktech opened this issue Dec 16, 2017 · 12 comments
Closed

ktlintFormat does not autoformat #129

vanniktech opened this issue Dec 16, 2017 · 12 comments

Comments

@vanniktech
Copy link
Contributor

When I apply this section into my app/build.gradle file:

task ktlintFormat(type: JavaExec, group: "formatting") {
  description = "Fix Kotlin code style deviations."
  classpath = configurations.ktlint
  main = "com.github.shyiko.ktlint.Main"
  args "-F", "src/**/*.kt"
}

and I'm running it via ./gradlew ktlintFormat I'd expect to get auto corrected files. The only thing I'm seeing in the console is that the warnings are reported but nothing gets fixed. Is there any flag missing for the executable?

I'm using 0.14.0

@shyiko
Copy link
Collaborator

shyiko commented Dec 16, 2017

@vanniktech ktlint@0.14.0 --format reports errors which it cannot fix automatically. As of 0.14.0 this includes max-line-length, no-wildcard-imports and indent. If you are seeing a lint error outside of this list please let me know. 🙇‍♂️

@shyiko shyiko closed this as completed Dec 16, 2017
@vanniktech
Copy link
Contributor Author

Oh it's indent. Do we have an issue to autofix these?

@zkbpkp
Copy link

zkbpkp commented Dec 25, 2017

@shyiko I cannot make it even report indenting errors - it just ignores wrong indentation. Other types of errors (max line length, wildcard imports etc) are detected.

@zkbpkp
Copy link

zkbpkp commented Dec 25, 2017

And when do you plan to implement autoformatting in ktlint?

@shyiko
Copy link
Collaborator

shyiko commented Dec 25, 2017

@KolesnichenkoDS a week after the New Year Eve.

@zkbpkp
Copy link

zkbpkp commented Dec 27, 2017

@shyiko cool!

@dannyroa
Copy link

dannyroa commented Mar 9, 2018

Is indenting on autoformat working now? It's just getting reported when I tried it.

@shyiko
Copy link
Collaborator

shyiko commented Mar 9, 2018

@dannyroa partially: parameter list wrapping auto-correction included in 0.16.0+; general indentation is in the works.

@dannyroa
Copy link

@shyiko: Any way I can help build this feature? Thanks.

@shyiko
Copy link
Collaborator

shyiko commented Mar 13, 2018

@dannyroa That would be great!

@MyDogTom made a good progress in #137 (changes are in develop branch) but it needs more work;
(code indented like shown below is not corrected (at all))

fun a() {
class A() {
val a = 1
}
}

I feel like instead of calculating previous indent on each visit(...) we should iterate through AST once (on FILE) and report/correct wrong indents as we go (based on the nesting so far).

(current rule sources are here - https://github.com/shyiko/ktlint/blob/master/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRule.kt)

P.S. You might find https://github.com/shyiko/ktlint#ast helpful.

@MyDogTom
Copy link
Contributor

@shyiko Code you mentioned is not formatted, because rule is not strict enough. Violation is just not detected. I've explained it in details here. It's not related to the calculation of previous intent. Rule just should be more strict.
But I agree that instead of visiting each node, we could go through entire file only once and just persist previous indent. That should be more efficient.

@shyiko
Copy link
Collaborator

shyiko commented Mar 13, 2018

@MyDogTom #141 (comment) << right.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants