Merge pull request #18 from ultrasonic/add-detekt

Add detekt
This commit is contained in:
Yahor Berdnikau 2017-07-30 22:29:45 +02:00 committed by GitHub
commit ba265b1bbe
29 changed files with 175 additions and 31 deletions

View File

@ -19,6 +19,9 @@ jobs:
- run:
name: unit-tests
command: ./gradlew test
- run:
name: static analysis
command: ./gradlew -Pqc detektCheck
- save_cache:
paths:
- ~/.gradle

View File

@ -4,18 +4,27 @@ buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath gradlePlugins.androidTools
classpath gradlePlugins.kotlin
classpath gradlePlugins.ktlintGradle
classpath(gradlePlugins.detekt) {
exclude module: 'kotlin-compiler-embeddable'
exclude module: 'kotlin-stdlib'
}
}
}
allprojects {
// Buildscript here is required by detekt
buildscript {
repositories {
jcenter()
}
}
repositories {
jcenter()
}

View File

@ -7,6 +7,7 @@ ext.versions = [
androidTools : "2.3.3",
ktlint : "0.9.0",
ktlintGradle : "2.1.0",
detekt : "1.0.0.M13.2",
androidSupport : "22.2.1",
@ -26,6 +27,7 @@ ext.gradlePlugins = [
androidTools : "com.android.tools.build:gradle:$versions.androidTools",
kotlin : "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin",
ktlintGradle : "gradle.plugin.org.jlleitschuh.gradle:ktlint-gradle:$versions.ktlintGradle",
detekt : "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$versions.detekt",
]
ext.androidSupport = [

111
detekt-config.yml Normal file
View File

@ -0,0 +1,111 @@
autoCorrect: true
failFast: false
build:
warningThreshold: 0
failThreshold: 0
weights:
complexity: 2
formatting: 1
LongParameterList: 1
comments: 1
potential-bugs:
active: true
DuplicateCaseInWhenExpression:
active: true
EqualsWithHashCodeExist:
active: true
ExplicitGarbageCollectionCall:
active: true
LateinitUsage:
active: false
UnsafeCallOnNullableType:
active: false
UnsafeCast:
active: false
performance:
active: true
ForEachOnRange:
active: true
SpreadOperator:
active: true
exceptions:
active: true
empty-blocks:
active: true
complexity:
active: true
LongMethod:
threshold: 20
LongParameterList:
threshold: 5
LargeClass:
threshold: 150
ComplexMethod:
threshold: 10
TooManyFunctions:
threshold: 10
ComplexCondition:
threshold: 3
LabeledExpression:
active: false
code-smell:
active: true
FeatureEnvy:
threshold: 0.5
weight: 0.45
base: 0.5
formatting:
active: false
style:
active: true
NewLineAtEndOfFile:
active: true
ForbiddenComment:
active: true
values: 'TODO:,FIXME:,STOPSHIP:'
WildcardImport:
active: true
MaxLineLength:
active: true
maxLineLength: 120
excludePackageStatements: false
excludeImportStatements: false
NamingConventionViolation:
active: true
variablePattern: '^(_)?[a-z$][a-zA-Z$0-9]*$'
constantPattern: '^([A-Z_]*|serialVersionUID)$'
methodPattern: '^[a-z\s`$][a-zA-Z\s$0-9`]*$'
classPattern: '[A-Z$][a-zA-Z$]*'
enumEntryPattern: '^[A-Z$][a-zA-Z_$0-9]*$'
comments:
active: true
CommentOverPrivateMethod:
active: true
CommentOverPrivateProperty:
active: true
UndocumentedPublicClass:
active: false
searchInNestedClass: true
searchInInnerClass: true
searchInInnerInterface: true
UndocumentedPublicFunction:
active: false
# *experimental feature*
# Migration rules can be defined in the same config file or a new one
migration:
active: false
imports:
# your.package.Class: new.package.or.Class
# for example:
# io.gitlab.arturbosch.detekt.api.Rule: io.gitlab.arturbosch.detekt.rule.Rule

View File

@ -1,6 +1,7 @@
// Applies code quality plugins when -Pqc is passed to the gradle
def isCodeQualityEnabled = project.hasProperty('qc')
// KtLint
if (isCodeQualityEnabled) {
apply plugin: "org.jlleitschuh.gradle.ktlint"
@ -8,3 +9,20 @@ if (isCodeQualityEnabled) {
version = versions.ktlint
}
}
// Detekt
if (isCodeQualityEnabled) {
if (!project.rootProject.plugins.hasPlugin("io.gitlab.arturbosch.detekt")) {
Project rootProject = project.rootProject
rootProject.apply {
apply plugin: "io.gitlab.arturbosch.detekt"
detekt {
version = versions.detekt
profile("main") {
config = "${rootProject.projectDir}/detekt-config.yml"
}
}
}
}
}

View File

@ -30,6 +30,7 @@ import java.util.TimeZone
/**
* Integration test for [SubsonicAPIClient] class.
*/
@Suppress("TooManyFunctions")
class SubsonicAPIClientTest {
companion object {
const val USERNAME = "some-user"
@ -49,7 +50,7 @@ class SubsonicAPIClientTest {
}
@Test
fun `Should pass password hash and salt in query params for api version 1_13_0`() {
fun `Should pass password hash and salt in query params for api version 1 13 0`() {
val clientV12 = SubsonicAPIClient(mockWebServerRule.mockWebServer.url("/").toString(), USERNAME,
PASSWORD, SubsonicAPIVersions.V1_14_0, CLIENT_ID)
enqueueResponse("ping_ok.json")
@ -70,7 +71,7 @@ class SubsonicAPIClientTest {
}
@Test
fun `Should pass hex encoded password in query params for api version 1_12_0`() {
fun `Should pass hex encoded password in query params for api version 1 12 0`() {
val clientV11 = SubsonicAPIClient(mockWebServerRule.mockWebServer.url("/").toString(), USERNAME,
PASSWORD, SubsonicAPIVersions.V1_12_0, CLIENT_ID)
enqueueResponse("ping_ok.json")
@ -153,7 +154,7 @@ class SubsonicAPIClientTest {
@Test
fun `Should parse get indexes ok response`() {
// TODO: check for shortcut parsing
// check for shortcut parsing
enqueueResponse("get_indexes_ok.json")
val response = client.api.getIndexes(null, null).execute()