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

Annotation rule throws IllegalStateException #490

Closed
zsavely opened this issue Jun 14, 2019 · 5 comments · Fixed by #509
Closed

Annotation rule throws IllegalStateException #490

zsavely opened this issue Jun 14, 2019 · 5 comments · Fixed by #509

Comments

@zsavely
Copy link

zsavely commented Jun 14, 2019

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()
    )
}
@sowmyav24
Copy link
Contributor

Included the above two examples in the AnnotationRuleTest in the PR

arturbosch added a commit to detekt/detekt that referenced this issue Jun 29, 2019
* Wrap two new KtLint rules

* Add new rules to KtLint provider

* Add test cases for new rules

* Distinguish between test files for KtLint integration tests

* Generate documentation for new rules

* Disable AnnotationOnSeparateLine and SpacingAroundDot by default due to false positives and exceptions

* Make sure ChainWrapping works fine when running in single mode

All KtLint rules together have problems with function chains.

* Remove active state from indentation rule as it is experimental in ktlint

* Wrap MultiLineIfElse and SpacingAroundUnaryOperators rules

* Suppress KtLint false positives

* Disable AnnotationOnSeparateLine rule due to known excptions

pinterest/ktlint#490

* Use braces in if statements for readability

* Remove formatting integration test

It basically tested if KtLint is doing the right thing.
We don't want to duplicate their tests.
Running this rule set on our CI is enough integration for detekt.
@sowmyav24
Copy link
Contributor

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 ?

@shashachu
Copy link
Contributor

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

@sowmyav24
Copy link
Contributor

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

@shashachu
Copy link
Contributor

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.

shashachu added a commit to shashachu/ktlint that referenced this issue Jul 3, 2019
* Return if there's no annotations found instead of throwing an exception
* Fies pinterest#490
shashachu added a commit to shashachu/ktlint that referenced this issue Jul 3, 2019
    * Return if there's no annotations found instead of throwing an exception
    * Fies pinterest#490
shashachu added a commit to shashachu/ktlint that referenced this issue Jul 5, 2019
    * Return if there's no annotations found instead of throwing an exception
    * Fies pinterest#490
shashachu added a commit to shashachu/ktlint that referenced this issue Jul 5, 2019
    * Return if there's no annotations found instead of throwing an exception
    * Fies pinterest#490
shashachu added a commit that referenced this issue Jul 5, 2019
* Fix AnnotationRule exception
    * Return if there's no annotations found instead of throwing an exception
    * Fixes #490 and #502
    * Re-enable rule in standard ruleset
sowmyav24 pushed a commit to sowmyav24/ktlint that referenced this issue Jul 18, 2019
* Fix AnnotationRule exception
    * Return if there's no annotations found instead of throwing an exception
    * Fixes pinterest#490 and pinterest#502
    * Re-enable rule in standard ruleset
orchestr7 pushed a commit to saveourtool/diktat that referenced this issue Jun 29, 2020
* Fix AnnotationRule exception
    * Return if there's no annotations found instead of throwing an exception
    * Fixes pinterest/ktlint#490 and pinterest/ktlint#502
    * Re-enable rule in standard ruleset
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants