Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Detekt #44

Merged
merged 1 commit into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
`maven-publish`
kotlin("jvm") version "1.3.41"
id("com.gradle.plugin-publish") version "0.10.0"
id("io.gitlab.arturbosch.detekt") version "1.0.0-RC16"
}

java {
Expand Down Expand Up @@ -46,3 +47,11 @@ pluginBundle {
}
}
}

detekt {
toolVersion = "1.0.0-RC16"
input = files("src/main")
config = files("./detekt-config.yml")
buildUponDefaultConfig = true
filters = ".*/resources/.*,.*/build/.*"
}
19 changes: 19 additions & 0 deletions plugin/detekt-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
build:
maxIssues: 1

complexity:
active: true
ComplexMethod:
active: true
threshold: 20
ignoreSingleWhenExpression: false
ignoreSimpleWhenEntries: false


style:
active: true
ReturnCount:
active: true
max: 3
excludeLabeled: false
excludeReturnFromLambda: true
2 changes: 1 addition & 1 deletion plugin/src/main/java/com/yelp/codegen/KotlinGenerator.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("NOTHING_TO_INLINE")
@file:Suppress("TooManyFunctions", "NOTHING_TO_INLINE")

package com.yelp.codegen

Expand Down
20 changes: 9 additions & 11 deletions plugin/src/main/java/com/yelp/codegen/SharedCodegen.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("TooManyFunctions")

package com.yelp.codegen

import com.yelp.codegen.utils.InlineModelResolver
Expand Down Expand Up @@ -130,8 +132,8 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
*/
fun matchXModel(name: String): String {
return xModelMatches[name] ?: (
this.swagger?.definitions?.get(name)?.title ?: name
)
this.swagger?.definitions?.get(name)?.title ?: name
)
}

/**
Expand Down Expand Up @@ -322,16 +324,12 @@ abstract class SharedCodegen : DefaultCodegen(), CodegenConfig {
* Header Interceptor) and is helpful to remove the header from the endpoints to avoid confusion.
*/
protected fun getHeadersToIgnore(): List<String> {
return try {
val headerList = mutableListOf<String>()
val headerParam = additionalProperties[HEADERS_TO_IGNORE] as? String
if (headerParam != null) {
headerList.addAll(headerParam.split(','))
}
headerList.toList()
} catch (e: Throwable) {
listOf()
val headerList = mutableListOf<String>()
val headerParam = additionalProperties[HEADERS_TO_IGNORE] as? String
if (headerParam != null) {
headerList.addAll(headerParam.split(','))
}
return headerList.toList()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ open class GenerateTask : DefaultTask() {

@InputFiles
@Optional
@Option(option = "extraFiles", description = "Configures path of the extra files directory to be added to the Generated code.")
@Option(option = "extraFiles",
description = "Configures path of the extra files directory to be added to the Generated code.")
var extraFiles: File? = null

@Nested
Expand Down
8 changes: 8 additions & 0 deletions samples/junit-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ buildscript {
classpath "com.android.tools.build:gradle:3.4.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.41"
classpath "com.yelp.codegen:plugin:1.1.1"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.0-RC16"
}
}

apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: "com.yelp.codegen.plugin"
apply plugin: "io.gitlab.arturbosch.detekt"

android {
compileSdkVersion = 28
Expand Down Expand Up @@ -65,3 +67,9 @@ generateSwagger {
repositories {
mavenCentral()
}

detekt {
toolVersion = "1.0.0-RC16"
input = files("src/test")
filters = ".*/resources/.*,.*/build/.*"
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class FormatEndpointTest {
""".trimIndent()))

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

Expand Down