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

ktlintFormat causes lint error for max line length rule #637

Closed
donaldchen opened this issue Nov 6, 2019 · 0 comments · Fixed by #643
Closed

ktlintFormat causes lint error for max line length rule #637

donaldchen opened this issue Nov 6, 2019 · 0 comments · Fixed by #643
Labels

Comments

@donaldchen
Copy link

Steps to reproduce

  1. Add this line to any Kotlin file in your project:
    fun myExampleMethodWithAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName(): () -> Unit =
      { System.out.println("Hello World!") }

With the default max line length of 100 characters, this code does not exceed the max line length.
2. Save the file, and commit the change with git.
3. Run the ktlint format task with ktlint version 0.35.0.
4. Run git diff.

Expected behavior
The example method should either be unchanged, or it should at least not get reformatted to exceed the max line length.

Actual behavior
The method gets reformatted to exceed the max line length which causes a lint error. git diff shows the following change:

-    fun myExampleMethodWithAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName(): () -> Unit =
-      { System.out.println("Hello World!") }
+    fun myExampleMethodWithAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName(): () -> Unit = { System.out.println("Hello World!") }

I would like to enable the max line length lint rule and then auto-format my entire project using Android Studio 3.5.1's max-line-length code styles that wrap long lines. However, whether I fix the max-line-length violations manually or with the IDE, I can't enable the lint rule because ktlint's autoformatter will cause lint errors. Is there a known version of ktlint where the auto-formatter does not cause this max line length error? Thanks!

@donaldchen donaldchen changed the title ktlintFormat causes lint error for max line length violation ktlintFormat causes lint error for max line length rule Nov 6, 2019
@Tapchicoma Tapchicoma added the bug label Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants