Ktlint: Annotation rule throws IllegalStateException

Created on 14 Jun 2019  路  5Comments  路  Source: pinterest/ktlint

Two tests added to the AnnotationRuleTest.kt. The first one failed, the second one succeeds.

com.pinterest.ktlint.core.RuleExecutionException: java.lang.IllegalStateException: Annotations list should not be empty

@Test
fun `no annotation present fails`() {
    val code =
        """
        package com.example.application.a.b

        data class FileModel(val uri: String, val name: String)
        """.trimIndent()
    assertThat(AnnotationRule().format(code)).isEqualTo(
        """
        package com.example.application.a.b

        data class FileModel(val uri: String, val name: String)
        """.trimIndent()
    )
}

@Test
fun `no annotation present succeeds`() {
    val code =
        """
        package com.example.application.a

        import android.os.Environment

        class PathProvider {
            fun gallery(): String = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).path
        }
        """.trimIndent()
    assertThat(AnnotationRule().format(code)).isEqualTo(
        """
        package com.example.application.a

        import android.os.Environment

        class PathProvider {
            fun gallery(): String = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).path
        }
        """.trimIndent()
    )
}

Most helpful comment

Included the above two examples in the AnnotationRuleTest in the PR

All 5 comments

Included the above two examples in the AnnotationRuleTest in the PR

The PR for this issue has been merged. But just now noticed that in the StandardRuleSetProvider, the rule is disabled due to this issue. Can the rule be re-enabled and this issue closed ?

Disabling that rule predates us taking over this project, but I can verify that all checks pass once it's re-enabled.

Sure ! Noticed all the rules disabled earlier have been re-enabled in this open PR.

It's a bit confusing - some of the disabled ones are still disabled, but the disabling is moved into the .editorconfig file. I'll add a comment into the StandardRulesetProvider in that PR to clarify.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZakTaccardi picture ZakTaccardi  路  3Comments

filipedelimabrito picture filipedelimabrito  路  3Comments

nokite picture nokite  路  4Comments

ZakTaccardi picture ZakTaccardi  路  4Comments

Tapchicoma picture Tapchicoma  路  3Comments