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

try-catch comment causing red code on format #2427

Closed
TWiStErRob opened this issue Dec 10, 2023 · 2 comments · Fixed by #2432
Closed

try-catch comment causing red code on format #2427

TWiStErRob opened this issue Dec 10, 2023 · 2 comments · Fixed by #2432
Milestone

Comments

@TWiStErRob
Copy link
Contributor

Expected Behavior

Unsure, but definitely still compiling.

Observed Behavior

fun f() {
    try {
        something()
    } // Blah blah about exception handling. catch (e: IOException) {
        handle(e, 1)
    } catch (e: RuntimeException) {
        handle(e, 2)
    }
}

Steps to Reproduce

ktlint --format f.kt

fun f() {
    try {
        something()
    } // Blah blah about exception handling.
    catch (e: IOException) {
        handle(e, 1)
    } catch (e: RuntimeException) {
        handle(e, 2)
    }
}

Your Environment

  • Version of ktlint used: 1.0.1
  • Relevant parts of the .editorconfig settings: none
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): ktlint CLI
  • Version of Gradle used (if applicable): N/A
  • Operating System and version: Windows 10
TWiStErRob added a commit to TWiStErRob/paparazzi that referenced this issue Dec 10, 2023
@paul-dingemans
Copy link
Collaborator

The comment // Blah blah about exception handling. should be moved inside the try or in the catch as it is unclear from the AST structure where it refers. In this case, based on the comment text itself it is clear that it does not belong in the try. But, it is still unclear whether it refers to a single catch or to all catches. So this actually needs to be forbidden.

Ktlint definitely makes your code sample not compiling anymore. Will be fixed in next release.

@paul-dingemans paul-dingemans added this to the 1.1 milestone Dec 10, 2023
@TWiStErRob
Copy link
Contributor Author

Yep, that's what I did. In the real case (see linked right above your comment) it was actually referring to one of the catch clauses. Note that the linked code went through a J2K auto-conversion, here's the original code for reference which actually shows that it was meant for a subset of catchs.

https://android.googlesource.com/platform/tools/base/+/6c21fa43c56804ab5f4d3a3fc59b5c1158750fa6/resource-repository/main/java/com/android/resources/base/RepositoryLoader.java#545

jrodbx pushed a commit to cashapp/paparazzi that referenced this issue Jan 9, 2024
Squashed commit of the following:

commit 2ec7cf497dc1a46ba2f6acc6e08542d106f57281
Author: John Rodriguez <jrod@squareup.com>
Date:   Tue Jan 9 15:47:28 2024 -0500

    Apply suggested feedback

commit 54d7dea41d9842e1481ebc0e14864b7016c407ee
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 12:38:29 2023 +0000

    partial `gradlew spotlessApply`

commit 6ee72c30511fa6dde5cbe47d932d73d73d364eea
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 13:06:19 2023 +0000

    Move comment to relevant block to prevent pinterest/ktlint#2427

commit 12ee79b1cc6e2094cc576fe490a03b4994a65846
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 12:41:33 2023 +0000

    > Task :paparazzi-gradle-plugin:spotlessKotlin FAILED
    Step 'ktlint' found problem in 'src\test\projects\lifecycle-usages\src\test\java\app\cash\paparazzi\plugin\test\LifecycleUsageTest.kt':
    Error on line: 21, column: 13
    rule: standard:function-naming
    Function name should start with a lowercase letter (except factory methods) and use camel case

commit cb2baf39f369a12ca851f871197c4b65c1a1893e
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 15:18:37 2023 +0000

    > Task :paparazzi:spotlessKotlin FAILED
    Step 'ktlint' found problem in 'src\main\java\app\cash\paparazzi\internal\interceptors\MatrixMatrixMultiplicationInterceptor.kt':
    Error on line: 38, column: 15
    rule: standard:function-naming
    Function name should start with a lowercase letter (except factory methods) and use camel case

commit b95e5ba475bfcee65827d9e5c337fe53faee5d13
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 13:07:39 2023 +0000

    > Task :paparazzi:spotlessKotlin FAILED
    Step 'ktlint' found problem in 'src\test\java\app\cash\paparazzi\internal\resources\PseudolocaleGeneratorTest.kt':
    Error on line: 85, column: 1
    rule: standard:max-line-length
    Exceeded max line length (140)

commit 06c514f94bc0575c459939ca3cefef4be1ee6653
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 11:32:42 2023 +0000

    > Task :paparazzi:spotlessKotlin FAILED
    Step 'ktlint' found problem in 'src\main\java\app\cash\paparazzi\internal\resources\Pseudolocalizer.kt':
    Error on line: 22, column: 1
    rule: standard:no-consecutive-comments
    an EOL comment may not be preceded by a KDoc. Reversed order is allowed though when separated by a newline.

commit edebb8a65c641499a5455fea95a3afd8fc10366b
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 11:23:48 2023 +0000

    > Task :paparazzi:spotlessKotlin FAILED
    Step 'ktlint' found problem in 'src\main\java\app\cash\paparazzi\internal\interceptors\MatrixVectorMultiplicationInterceptor.kt':
    Error on line: 23, column: 2
    rule: standard:max-line-length
    Exceeded max line length (140)

commit 308931cfb70ce22523d1efd444d5863aaa7f4f01
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 11:11:42 2023 +0000

    > Task :paparazzi:spotlessKotlin FAILED
    Step 'ktlint' found problem in 'src\main\java\app\cash\paparazzi\internal\resources\RepositoryLoader.kt':
    Error on line: 124, column: 15
    rule: standard:property-naming
    Property name should start with a lowercase letter and use camel case

commit f1eab7e9b97f1bb2a906a6c9683439ef282e254e
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 11:08:38 2023 +0000

    > Task :paparazzi:spotlessKotlin FAILED
    Step 'ktlint' found problem in 'src\main\java\app\cash\paparazzi\internal\resources\Pseudolocalizer.kt':
    Error on line: 351, column: 15
    rule: standard:property-naming
    Property name should start with a lowercase letter and use camel case

commit cacd26ca7d5904467c74ddcb8f427e8c6cf95c4e
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 11:02:24 2023 +0000

    > Task :paparazzi:spotlessKotlin FAILED
    Step 'ktlint' found problem in 'src\main\java\app\cash\paparazzi\internal\interceptors\MatrixMatrixMultiplicationInterceptor.kt':
    Error on line: 19, column: 11
    rule: standard:property-naming
    Property name should start with a lowercase letter and use camel case

commit 1272b12f2038105c4eb0c02bd7fbe278ce543e62
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 11:35:39 2023 +0000

    > Task :sample:spotlessKotlin FAILED
    Step 'ktlint' found problem in 'src\test\java\app\cash\paparazzi\sample\ComposeA11yTest.kt':
    Error on line: 56, column: 39
    rule: standard:discouraged-comment-location
    A comment in a 'value_argument_list' is only allowed when placed on a separate line

commit ef0b4d3a38450d66ee103a68fcb5bd49a83e5c2d
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 11:00:47 2023 +0000

    > Task :sample:spotlessKotlin FAILED
    Step 'ktlint' found problem in 'src\main\java\app\cash\paparazzi\sample\ResourcesDemo.kt':
    Error on line: 27, column: 11
    rule: standard:property-naming
    Property name should use the screaming snake case notation when the value can not be changed

commit be7a21181f3bc6634005b3908a491a0567142dfc
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 11:04:34 2023 +0000

    > Task :sample:spotlessKotlin FAILED
    Step 'ktlint' found problem in 'src\main\java\app\cash\paparazzi\sample\ResourcesDemo.kt':
    Error on line: 31, column: 5
    rule: standard:function-naming
    Function name should start with a lowercase letter (except factory methods) and use camel case

commit 91736c125f223dae1c7d0d25e1e14938a9e47ac6
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 12:55:26 2023 +0000

    Help IDEA indent correctly when user has tabs enabled.

commit 4d9b80514da232747e3069aad2744cf38f5059f2
Author: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
Date:   Sun Dec 10 11:16:29 2023 +0000

    Sync up spotless.kotlin.ktlint config overrides with .editorconfig and use a single source of truth.
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.

2 participants