Skip to content

Commit

Permalink
MBS-8436 add detekt plugin; apply and fix UnusedPrivateMember rule (#639
Browse files Browse the repository at this point in the history
)

* MBS-8436 add detekt plugin; apply and fix UnusedPrivateMember rule

* MBS-8436 fix makefile

* MBS-8436 more comments
  • Loading branch information
dsvoronin authored Nov 18, 2020
1 parent d6d6bf1 commit ec0dc8e
Show file tree
Hide file tree
Showing 15 changed files with 760 additions and 232 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ unit_tests:
compile_tests:
./gradlew -p subprojects compileTestKotlin $(log_level)

check:
./gradlew -p subprojects check

detekt:
./gradlew -p subprojects detektAll

clear_k8s_deployments_by_namespaces:
./gradlew subprojects\:ci\:k8s-deployments-cleaner\:clearByNamespaces -PteamcityApiPassword=$(teamcityApiPassword) $(log_level)

Expand Down
50 changes: 50 additions & 0 deletions subprojects/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import com.android.build.gradle.AppPlugin
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.LibraryPlugin
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.jfrog.bintray.gradle.BintrayExtension
import com.jfrog.bintray.gradle.BintrayExtension.PackageConfig
import com.jfrog.bintray.gradle.BintrayExtension.VersionConfig
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand All @@ -18,10 +20,17 @@ buildscript {
}

plugins {
/**
* https://docs.gradle.org/current/userguide/base_plugin.html
* base plugin added to add wiring on check->build tasks for detekt
*/
base

id("org.jetbrains.kotlin.jvm") apply false
id("com.android.application") apply false
id("com.jfrog.bintray") version "1.8.4" apply false
id("com.autonomousapps.dependency-analysis") apply false
id("io.gitlab.arturbosch.detekt") version "1.15.0-RC1"
}

if (gradle.startParameter.taskNames.contains("buildHealth")) {
Expand Down Expand Up @@ -56,6 +65,21 @@ val finalProjectVersion: String = System.getProperty("avito.project.version").le
if (env.isNullOrBlank()) projectVersion else env
}

repositories {
exclusiveContent {
forRepository {
jcenter()
}
filter {
//all for detekt
includeGroup("io.gitlab.arturbosch.detekt")
includeGroupByRegex("org.jetbrains.*")
includeModule("com.beust", "jcommander")
includeModule("org.yaml", "snakeyaml")
}
}
}

subprojects {

repositories {
Expand Down Expand Up @@ -359,3 +383,29 @@ fun Project.configureJunit5Tests() {
maxParallelForks = 8
}
}

val detektAll by tasks.registering(Detekt::class) {
description = "Runs over whole code base without the starting overhead for each module."
parallel = true
setSource(files(projectDir))

//
/**
* About config:
* yaml is a copy of https://github.com/detekt/detekt/blob/master/detekt-core/src/main/resources/default-detekt-config.yml
* all rules are disabled by default, enabled one by one
*/
config.setFrom(files(project.rootDir.resolve("detekt.yml")))
buildUponDefaultConfig = false

include("**/*.kt")
include("**/*.kts")
exclude("**/resources/**")
exclude("**/build/**")
reports {
xml.enabled = false
html.enabled = false
}
}

tasks.named("check").dependsOn(detektAll)
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import java.io.IOException
*/
class FallbackInterceptor(
private val fallbackRequest: (Request) -> Request,
private val doFallbackOnTheseCodes: List<Int> = listOf(404, 503, 502, 504),
private val onFallback: (Response) -> Unit = {}
private val doFallbackOnTheseCodes: List<Int> = listOf(404, 503, 502, 504)
) : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fun isPlaintext(buffer: Buffer): Boolean {
val prefix = Buffer()
val byteCount = if (buffer.size < 64) buffer.size else 64
buffer.copyTo(prefix, 0, byteCount)
@Suppress("UnusedPrivateMember")
for (i in 0..15) {
if (prefix.exhausted()) {
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ internal class FallbackInterceptorTest {
) {
addInterceptor(
FallbackInterceptor(
doFallbackOnTheseCodes = listOf(doFallbackOnThisResponseCode),
fallbackRequest = { request ->
request.newBuilder()
.url(request.url.newBuilder().addPathSegment("fallback").build())
.addHeader("X-FALLBACK", "true")
.build()
})
},
doFallbackOnTheseCodes = listOf(doFallbackOnThisResponseCode)
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,6 @@ internal class ReportsFetchApiImpl(
}
}

/**
* RunTest.Get
* получение результата конкретного теста по id
*/
private fun getTest(id: String): RunTest {
return requestProvider.jsonRpcRequest<RpcResult<RunTest>>(
RfcRpcRequest(
method = "RunTest.Get",
params = mapOf(
"id" to id
)
)
).result
}

private fun deserializeStatus(reportModel: ListResult): Status {
return when (reportModel.status) {
TestStatus.OK -> Status.Success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ fun getHttpClient(
request.newBuilder()
.url(fallbackUrl)
.build()
},
onFallback = { logger.debug("Fallback to ingress") })
})
)
}
}
Expand Down
Loading

0 comments on commit ec0dc8e

Please sign in to comment.