Skip to content

Commit

Permalink
Excluding the keyword data from annotation rule (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
sowmyav24 authored and shashachu committed Jun 26, 2019
1 parent a726c87 commit 64f3269
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AnnotationRule : Rule("annotation") {
"Multiple annotations should not be placed on the same line as the annotated construct"
const val annotationsWithParametersAreNotOnSeparateLinesErrorMessage =
"Annotations with parameters should all be placed on separate lines prior to the annotated construct"
const val DATA_KEYWORD = "data"
}

override fun visit(
Expand All @@ -23,7 +24,7 @@ class AnnotationRule : Rule("annotation") {
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
) {
val root =
node.children().firstOrNull { it.elementType == MODIFIER_LIST }
node.children().firstOrNull { it.elementType == MODIFIER_LIST && it.text != DATA_KEYWORD }
?: return

val annotations =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,30 @@ class AnnotationRuleTest {
""".trimIndent()
)
}

@Test
fun `no annotation present for data class passes`() {
val code =
"""
package com.example.application.a.b
data class FileModel(val uri: String, val name: String)
""".trimIndent()
assertThat(AnnotationRule().format(code)).isEqualTo(code)
}

@Test
fun `no annotation present succeeds for class`() {
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(code)
}
}

0 comments on commit 64f3269

Please # to comment.