forked from detekt/detekt
/
RulesWhichCantBeCorrectedSpec.kt
93 lines (82 loc) · 3.35 KB
/
RulesWhichCantBeCorrectedSpec.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package io.gitlab.arturbosch.detekt.formatting
import io.gitlab.arturbosch.detekt.api.CodeSmell
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.formatting.wrappers.AnnotationOnSeparateLine
import io.gitlab.arturbosch.detekt.formatting.wrappers.EnumEntryNameCase
import io.gitlab.arturbosch.detekt.formatting.wrappers.Filename
import io.gitlab.arturbosch.detekt.formatting.wrappers.ImportOrdering
import io.gitlab.arturbosch.detekt.formatting.wrappers.Indentation
import io.gitlab.arturbosch.detekt.formatting.wrappers.MaximumLineLength
import io.gitlab.arturbosch.detekt.formatting.wrappers.NoWildcardImports
import io.gitlab.arturbosch.detekt.formatting.wrappers.PackageName
import io.gitlab.arturbosch.detekt.test.assertThat
import org.junit.jupiter.api.Test
class RulesWhichCantBeCorrectedSpec {
@Test
fun `Filename findings can't be corrected`() {
assertThat(Filename(Config.empty).lint("class NotTheFilename"))
.isNotEmpty
.hasExactlyElementsOfTypes(CodeSmell::class.java)
}
@Test
fun `PackageName findings can't be corrected`() {
assertThat(PackageName(Config.empty).lint("package under_score"))
.isNotEmpty
.hasExactlyElementsOfTypes(CodeSmell::class.java)
}
@Test
fun `ImportOrdering has a case with comments which is not correctable`() {
assertThat(
ImportOrdering(Config.empty).lint(
"""
import xyz.wrong_order
/*comment in between*/
import java.io.*
""".trimIndent()
)
).isNotEmpty
.hasExactlyElementsOfTypes(CodeSmell::class.java)
}
@Test
fun `NoWildcardImports can't be corrected`() {
assertThat(NoWildcardImports(Config.empty).lint("import java.io.*"))
.isNotEmpty
.hasExactlyElementsOfTypes(CodeSmell::class.java)
}
@Test
fun `MaximumLineLength can't be corrected`() {
assertThat(
MaximumLineLength(Config.empty).lint(
"""
class MaximumLeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeth
""".trimIndent()
)
).isNotEmpty
.hasExactlyElementsOfTypes(CodeSmell::class.java)
}
@Test
fun `EnumEntryNameCase can't be corrected`() {
assertThat(EnumEntryNameCase(Config.empty).lint("enum class Enum { violation_triggering_name }"))
.isNotEmpty
.hasExactlyElementsOfTypes(CodeSmell::class.java)
}
@Test
fun `Indentation finding inside string templates can't be corrected`() {
val multilineQuote = "${'"'}${'"'}${'"'}"
val code = """
val foo = $multilineQuote
line1
${'\t'}line2
$multilineQuote.trimIndent()
""".trimIndent()
assertThat(Indentation(Config.empty).lint(code))
.isNotEmpty
.hasExactlyElementsOfTypes(CodeSmell::class.java)
}
@Test
fun `Annotation contains a parameter on single line can't be corrected`() {
assertThat(AnnotationOnSeparateLine(Config.empty).lint("fun foo1() = @Suppress(\"DEPRECATION\") bar()"))
.isNotEmpty
.hasExactlyElementsOfTypes(CodeSmell::class.java)
}
}