Skip to content

Commit 1257d5b

Browse files
schalkmsvanniktech
authored andcommitted
Update detekt task to v1.0.0 (#198)
1 parent f15ab22 commit 1257d5b

File tree

4 files changed

+24
-117
lines changed

4 files changed

+24
-117
lines changed

src/main/kotlin/com/vanniktech/code/quality/tools/DetektCheckTask.kt

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,15 @@ import java.io.File
4242
executeDetekt(configuration)
4343
}
4444

45-
@Suppress("Detekt.ComplexMethod") // Can remove all of the compatibility crap once Detekt reached 1.0.0
4645
private fun executeDetekt(configuration: FileCollection, shouldCreateBaseLine: Boolean = false) {
47-
val fixedVersion = version.replace(".RC", "-RC").asVersion() // GradleVersion does not understand . as a - in this case. Let's fix it and hope it does not break.
48-
val possibleRcVersion = Regex("RC[\\d]+").find(version)?.value?.replace("RC", "")?.toIntOrNull()
49-
val isAtLeastRc10 = possibleRcVersion != null && possibleRcVersion >= RC_BREAKING_POINT // GradleVersion thinks RC10 is smaller than RC9.
50-
val shouldUseReport = fixedVersion >= VERSION_REPORT_CHANGE || isAtLeastRc10
51-
val canUseFileEnding = fixedVersion >= VERSION_REPORT_EXTENSION_CHANGE && isAtLeastRc10
52-
val shouldUseFailFastCliFlag = fixedVersion >= VERSION_FAIL_FAST_CHANGE && isAtLeastRc10
53-
val shouldUseExcludes = fixedVersion >= VERSION_FILTERS_CHANGE && isAtLeastRc10
54-
55-
val reportKey = if (shouldUseReport) "--report" else "--output"
56-
val reportValue = if (shouldUseReport) {
57-
listOf(
46+
val reportKey = "--report"
47+
val reportValue = listOf(
5848
ReportingMetaInformation("plain", "txt", "plain"),
5949
ReportingMetaInformation("xml", "xml", "checkstyle"),
6050
ReportingMetaInformation("html", "html", "report")
6151
).joinToString(separator = ",") {
62-
val reportId = if (canUseFileEnding) it.fileEnding else it.reportId
63-
reportId + ":" + File(outputDirectory, "detekt-${it.fileNameSuffix}.${it.fileEnding}").absolutePath
52+
it.fileEnding + ":" + File(outputDirectory, "detekt-${it.fileNameSuffix}.${it.fileEnding}").absolutePath
6453
}
65-
} else {
66-
outputDirectory.absolutePath
67-
}
6854

6955
project.javaexec { task ->
7056
task.main = "io.gitlab.arturbosch.detekt.cli.Main"
@@ -78,13 +64,9 @@ import java.io.File
7864
task.args("--config", configFile)
7965
}
8066

81-
if (shouldUseExcludes) {
82-
task.args("--excludes", "**/build/**")
83-
} else {
84-
task.args("--filters", ".*build/.*")
85-
}
67+
task.args("--excludes", "**/build/**")
8668

87-
if (shouldUseFailFastCliFlag && failFast) {
69+
if (failFast) {
8870
task.args("--fail-fast")
8971
}
9072

@@ -103,12 +85,4 @@ import java.io.File
10385
val fileEnding: String,
10486
val fileNameSuffix: String
10587
)
106-
107-
internal companion object {
108-
internal const val RC_BREAKING_POINT = 10
109-
internal val VERSION_REPORT_CHANGE = "1.0.0-RC9".asVersion()
110-
internal val VERSION_REPORT_EXTENSION_CHANGE = "1.0.0-RC10".asVersion()
111-
internal val VERSION_FAIL_FAST_CHANGE = "1.0.0-RC13".asVersion()
112-
internal val VERSION_FILTERS_CHANGE = "1.0.0-RC15".asVersion()
113-
}
11488
}

src/main/kotlin/com/vanniktech/code/quality/tools/DetektExtension.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open class DetektExtension {
88
var enabled: Boolean = true
99

1010
/** @since 0.6.0 */
11-
var toolVersion: String = "1.0.0.RC6"
11+
var toolVersion: String = "1.0.0"
1212

1313
/** @since 0.6.0 */
1414
var config: String = "code_quality_tools/detekt.yml"

src/test/kotlin/com/vanniktech/code/quality/tools/CodeQualityToolsPluginDetektTest.kt

Lines changed: 17 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,21 @@ import java.io.File
1111
class CodeQualityToolsPluginDetektTest {
1212
@get:Rule val testProjectDir = TemporaryFolder()
1313

14+
private val testCode = "package com.vanniktech.test;\nfun foo(param: Int) = param * param\n"
15+
private val testPath = "src/main/kotlin/com/vanniktech/test/Foo.kt"
16+
1417
@Test fun success() {
1518
Roboter(testProjectDir)
1619
.withConfiguration("failFast: true")
17-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo(param: Int) = param * param\n")
18-
.succeeds()
19-
}
20-
21-
@Test fun successBreakingReportChangeRC9() {
22-
Roboter(testProjectDir, version = "1.0.0.RC9")
23-
.withConfiguration("failFast: true")
24-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo(param: Int) = param * param\n")
25-
.succeeds()
26-
}
27-
28-
@Test fun successBreakingReportChangeRC92() {
29-
Roboter(testProjectDir, version = "1.0.0.RC9.2")
30-
.withConfiguration("failFast: true")
31-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo(param: Int) = param * param\n")
20+
.withKotlinFile(testPath, testCode)
3221
.succeeds()
3322
}
3423

35-
@Test fun successBreakingReportChangeRC10() {
36-
Roboter(testProjectDir, version = "1.0.0-RC10")
37-
.withConfiguration("failFast: true")
38-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo(param: Int) = param * param\n")
39-
.succeeds()
40-
}
41-
42-
@Test fun worksWithRC11() {
43-
Roboter(testProjectDir, version = "1.0.0-RC11")
44-
.withConfiguration("failFast: true")
45-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo(param: Int) = param * param\n")
46-
.succeeds()
47-
}
48-
49-
@Test fun worksWithRC12() {
50-
Roboter(testProjectDir, version = "1.0.0-RC12")
51-
.withConfiguration("failFast: true")
52-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo(param: Int) = param * param\n")
53-
.succeeds()
54-
}
55-
56-
@Test fun worksWithRC13() {
57-
Roboter(testProjectDir, version = "1.0.0-RC13")
58-
.withConfiguration("") // Fail Fast is configured via the CLI parameter.
59-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo(param: Int) = param * param\n")
60-
.succeeds()
61-
}
62-
63-
@Test fun worksWithRC14() {
64-
Roboter(testProjectDir, version = "1.0.0-RC14")
65-
.withConfiguration("") // Fail Fast is configured via the CLI parameter.
66-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo(param: Int) = param * param\n")
67-
.succeeds()
68-
}
69-
70-
@Test fun worksWithRC15() {
71-
Roboter(testProjectDir, version = "1.0.0-RC15")
72-
.withConfiguration("") // Fail Fast is configured via the CLI parameter.
73-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "package com.vanniktech.test;\nfun foo(param: Int) = param * param\n")
74-
.succeeds()
24+
@Test fun works() {
25+
Roboter(testProjectDir, version = "1.0.0")
26+
.withConfiguration("") // Fail Fast is configured via the CLI parameter.
27+
.withKotlinFile(testPath, testCode)
28+
.succeeds()
7529
}
7630

7731
@Test fun noSrcFolder() {
@@ -83,14 +37,14 @@ class CodeQualityToolsPluginDetektTest {
8337
@Test fun differentConfigFile() {
8438
Roboter(testProjectDir, config = "code_quality_tools/config-detekt.yml")
8539
.withConfiguration("failFast: true")
86-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo(param: Int) = param * param\n")
40+
.withKotlinFile(testPath, testCode)
8741
.succeeds()
8842
}
8943

9044
@Test fun fails() {
9145
Roboter(testProjectDir)
9246
.withConfiguration("failFast: true")
93-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo() = Unit")
47+
.withKotlinFile(testPath, "fun foo() = Unit")
9448
.fails(containsMessage = "NewLineAtEndOfFile - [Foo.kt]")
9549
}
9650

@@ -111,14 +65,14 @@ class CodeQualityToolsPluginDetektTest {
11165
@Test fun disabled() {
11266
Roboter(testProjectDir, enabled = false)
11367
.withConfiguration("failFast: true")
114-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo() = Unit")
68+
.withKotlinFile(testPath, "fun foo() = Unit")
11569
.doesNothing()
11670
}
11771

11872
@Test fun creatingInitialBaselineFails() {
11973
Roboter(testProjectDir, baselineFileName = "detekt-baseline.xml")
12074
.withConfiguration("failFast: true")
121-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo() = Unit")
75+
.withKotlinFile(testPath, "fun foo() = Unit")
12276
.fails(containsMessage = "NewLineAtEndOfFile - [Foo.kt]")
12377
.baseLineContains("<ID>NewLineAtEndOfFile:Foo.kt\$.Foo.kt</ID>")
12478
}
@@ -131,46 +85,25 @@ class CodeQualityToolsPluginDetektTest {
13185
<SmellBaseline>
13286
<Blacklist timestamp="1529425729991"></Blacklist>
13387
<Whitelist timestamp="1529425729991">
134-
<ID>NewLineAtEndOfFile:Foo.kt$.Foo.kt</ID>
88+
<ID>InvalidPackageDeclaration:Foo.kt$.Foo.kt</ID>
13589
</Whitelist>
13690
</SmellBaseline>""".trimIndent())
137-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo() = Unit")
138-
.succeeds()
139-
}
140-
141-
@Test fun mayBeConstSucceedsWithReleaseCandidate7() {
142-
Roboter(testProjectDir, version = "1.0.0.RC7")
143-
.withConfiguration("failFast: true")
144-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", """
145-
|const val TEST = "test"
146-
|val TEST2 = "test" + TEST
147-
|""".trimMargin())
91+
.withKotlinFile(testPath, "fun foo(i: Int) = i * 3\n")
14892
.succeeds()
14993
}
15094

151-
@Test fun mayBeConstFailsWithReleaseCandidate72() {
152-
// RC7-2 fixed this - https://github.com/arturbosch/detekt/pull/930
153-
Roboter(testProjectDir, version = "1.0.0.RC7-2")
154-
.withConfiguration("failFast: true")
155-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", """
156-
|const val TEST = "test"
157-
|val TEST2 = "test" + TEST
158-
|""".trimMargin())
159-
.fails(containsMessage = "MayBeConst - [TEST2] at")
160-
}
161-
16295
@Test fun checkTaskRunsDetekt() {
16396
Roboter(testProjectDir)
16497
.withConfiguration("failFast: true")
165-
.withKotlinFile("src/main/kotlin/com/vanniktech/test/Foo.kt", "fun foo() = Unit")
98+
.withKotlinFile(testPath, "fun foo() = Unit")
16699
.fails(taskToRun = "check", taskToCheck = "detektCheck", containsMessage = "NewLineAtEndOfFile - [Foo.kt] at")
167100
}
168101

169102
class Roboter(
170103
private val directory: TemporaryFolder,
171104
private val config: String = "code_quality_tools/detekt.yml",
172105
enabled: Boolean = true,
173-
version: String = "1.0.0.RC6",
106+
version: String = "1.0.0",
174107
private val baselineFileName: String? = null
175108
) {
176109
init {

src/test/kotlin/com/vanniktech/code/quality/tools/CodeQualityToolsPluginExtensionTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CodeQualityToolsPluginExtensionTest {
1313
assertThat(extension.textReports).isFalse()
1414

1515
assertThat(extension.errorProne.toolVersion).isEqualTo("2.1.3")
16-
assertThat(extension.detekt.toolVersion).isEqualTo("1.0.0.RC6")
16+
assertThat(extension.detekt.toolVersion).isEqualTo("1.0.0")
1717
assertThat(extension.ktlint.toolVersion).isEqualTo("0.32.0")
1818
assertThat(extension.checkstyle.toolVersion).isEqualTo("8.6")
1919
assertThat(extension.pmd.toolVersion).isEqualTo("6.0.0")

0 commit comments

Comments
 (0)