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()
)
}
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.
Most helpful comment
Included the above two examples in the
AnnotationRuleTestin the PR