Skip to content

Commit 55f6c88

Browse files
authored
Merge pull request #44 from Yelp/configure-detekt
Configure Detekt
2 parents 49822a4 + cf399c2 commit 55f6c88

File tree

7 files changed

+50
-14
lines changed

7 files changed

+50
-14
lines changed

plugin/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ plugins {
99
`maven-publish`
1010
kotlin("jvm") version "1.3.41"
1111
id("com.gradle.plugin-publish") version "0.10.0"
12+
id("io.gitlab.arturbosch.detekt") version "1.0.0-RC16"
1213
}
1314

1415
java {
@@ -46,3 +47,11 @@ pluginBundle {
4647
}
4748
}
4849
}
50+
51+
detekt {
52+
toolVersion = "1.0.0-RC16"
53+
input = files("src/main")
54+
config = files("./detekt-config.yml")
55+
buildUponDefaultConfig = true
56+
filters = ".*/resources/.*,.*/build/.*"
57+
}

plugin/detekt-config.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
build:
2+
maxIssues: 1
3+
4+
complexity:
5+
active: true
6+
ComplexMethod:
7+
active: true
8+
threshold: 20
9+
ignoreSingleWhenExpression: false
10+
ignoreSimpleWhenEntries: false
11+
12+
13+
style:
14+
active: true
15+
ReturnCount:
16+
active: true
17+
max: 3
18+
excludeLabeled: false
19+
excludeReturnFromLambda: true

plugin/src/main/java/com/yelp/codegen/KotlinGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@file:Suppress("NOTHING_TO_INLINE")
1+
@file:Suppress("TooManyFunctions", "NOTHING_TO_INLINE")
22

33
package com.yelp.codegen
44

plugin/src/main/java/com/yelp/codegen/SharedCodegen.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("TooManyFunctions")
2+
13
package com.yelp.codegen
24

35
import com.yelp.codegen.utils.InlineModelResolver
@@ -130,8 +132,8 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
130132
*/
131133
fun matchXModel(name: String): String {
132134
return xModelMatches[name] ?: (
133-
this.swagger?.definitions?.get(name)?.title ?: name
134-
)
135+
this.swagger?.definitions?.get(name)?.title ?: name
136+
)
135137
}
136138

137139
/**
@@ -322,16 +324,12 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
322324
* Header Interceptor) and is helpful to remove the header from the endpoints to avoid confusion.
323325
*/
324326
protected fun getHeadersToIgnore(): List<String> {
325-
return try {
326-
val headerList = mutableListOf<String>()
327-
val headerParam = additionalProperties[HEADERS_TO_IGNORE] as? String
328-
if (headerParam != null) {
329-
headerList.addAll(headerParam.split(','))
330-
}
331-
headerList.toList()
332-
} catch (e: Throwable) {
333-
listOf()
327+
val headerList = mutableListOf<String>()
328+
val headerParam = additionalProperties[HEADERS_TO_IGNORE] as? String
329+
if (headerParam != null) {
330+
headerList.addAll(headerParam.split(','))
334331
}
332+
return headerList.toList()
335333
}
336334

337335
/**

plugin/src/main/java/com/yelp/codegen/plugin/CodegenPlugin.kt renamed to plugin/src/main/java/com/yelp/codegen/plugin/GenerateTask.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ open class GenerateTask : DefaultTask() {
5858

5959
@InputFiles
6060
@Optional
61-
@Option(option = "extraFiles", description = "Configures path of the extra files directory to be added to the Generated code.")
61+
@Option(option = "extraFiles",
62+
description = "Configures path of the extra files directory to be added to the Generated code.")
6263
var extraFiles: File? = null
6364

6465
@Nested

samples/junit-tests/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ buildscript {
1111
classpath "com.android.tools.build:gradle:3.4.2"
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.41"
1313
classpath "com.yelp.codegen:plugin:1.1.1"
14+
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.0-RC16"
1415
}
1516
}
1617

1718
apply plugin: "com.android.library"
1819
apply plugin: "kotlin-android"
1920
apply plugin: "com.yelp.codegen.plugin"
21+
apply plugin: "io.gitlab.arturbosch.detekt"
2022

2123
android {
2224
compileSdkVersion = 28
@@ -65,3 +67,9 @@ generateSwagger {
6567
repositories {
6668
mavenCentral()
6769
}
70+
71+
detekt {
72+
toolVersion = "1.0.0-RC16"
73+
input = files("src/test")
74+
filters = ".*/resources/.*,.*/build/.*"
75+
}

samples/junit-tests/src/test/java/com/yelp/codegen/generatecodesamples/FormatEndpointTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class FormatEndpointTest {
7373
""".trimIndent()))
7474

7575
// 10000000 nanoseconds == 0.01 seconds.
76-
val returned = rule.getApi<ResourceApi>().getFormatEndpoint("datetime_with_fractionalsec_and_timezone").blockingGet()
76+
val returned = rule.getApi<ResourceApi>()
77+
.getFormatEndpoint("datetime_with_fractionalsec_and_timezone").blockingGet()
7778
assertEquals(ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 10000000, ZoneId.of("+01:00")), returned.datetimeProperty)
7879
}
7980

0 commit comments

Comments
 (0)