Skip to content

Commit a7b0a9d

Browse files
committed
improving static code analysis for sample Kotlin app and bumping Kotlin version
1 parent 03e9abb commit a7b0a9d

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[*.{kt,kts}]
2+
# possible values: number (e.g. 2), "unset" (makes ktlint ignore indentation completely)
3+
indent_size=2
4+
# possible values: number (e.g. 2), "unset"
5+
continuation_indent_size=2
6+
# true (recommended) / false
7+
insert_final_newline=unset
8+
# possible values: number (e.g. 120) (package name, imports & comments are ignored), "off"
9+
# it's automatically set to 100 on `ktlint --android ...` (per Android Kotlin Style Guide)
10+
max_line_length=off

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ Static code analysis runs Checkstyle, FindBugs, PMD, Lint, ErrorProne and NullAw
457457
Static code analysis for the sample Kotlin app with detekt can be executed as follows:
458458

459459
```
460-
./gradlew detektCheck
460+
./gradlew detektCheck ktlintCheck
461461
```
462462

463463
Reports from analysis are generated in `library/build/reports/` directory.

app-kotlin/build.gradle

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44
apply plugin: 'io.gitlab.arturbosch.detekt'
5+
apply plugin: 'org.jlleitschuh.gradle.ktlint'
56

67
android {
78
compileSdkVersion rootProject.ext.compileSdkVersion
@@ -36,14 +37,19 @@ android {
3637
}
3738

3839
detekt {
39-
version = "1.0.0.RC6-1"
40+
version = rootProject.ext.detektVersion
4041
profile("main") {
4142
input = "$projectDir"
4243
config = "$projectDir/detekt.yml"
4344
filters = ".*test.*,.*/resources/.*,.*/tmp/.*"
4445
}
4546
}
4647

48+
ktlint {
49+
verbose = true
50+
reporters = ["CHECKSTYLE", "PLAIN"]
51+
}
52+
4753
dependencies {
4854
implementation project(':library')
4955
implementation deps.kotlinstdlib
@@ -63,5 +69,6 @@ buildscript {
6369
dependencies {
6470
classpath deps.kotlingradleplugin
6571
classpath deps.detekt
72+
classpath deps.ktlintgradle
6673
}
6774
}

app-kotlin/src/main/kotlin/com/github/pwittchen/reactivenetwork/kotlinapp/MainActivity.kt

+14-14
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ class MainActivity : Activity() {
4242
super.onResume()
4343

4444
connectivityDisposable = ReactiveNetwork.observeNetworkConnectivity(applicationContext)
45-
.subscribeOn(Schedulers.io())
46-
.observeOn(AndroidSchedulers.mainThread())
47-
.subscribe { connectivity ->
48-
Log.d(TAG, connectivity.toString())
49-
val state = connectivity.state()
50-
val name = connectivity.typeName()
51-
connectivity_status.text = String.format("state: %s, typeName: %s", state, name)
52-
}
45+
.subscribeOn(Schedulers.io())
46+
.observeOn(AndroidSchedulers.mainThread())
47+
.subscribe { connectivity ->
48+
Log.d(TAG, connectivity.toString())
49+
val state = connectivity.state()
50+
val name = connectivity.typeName()
51+
connectivity_status.text = String.format("state: %s, typeName: %s", state, name)
52+
}
5353

5454
internetDisposable = ReactiveNetwork.observeInternetConnectivity()
55-
.subscribeOn(Schedulers.io())
56-
.observeOn(AndroidSchedulers.mainThread())
57-
.subscribe { isConnectedToInternet ->
58-
internet_status.text = isConnectedToInternet.toString()
59-
}
55+
.subscribeOn(Schedulers.io())
56+
.observeOn(AndroidSchedulers.mainThread())
57+
.subscribe { isConnectedToInternet ->
58+
internet_status.text = isConnectedToInternet.toString()
59+
}
6060
}
6161

6262
override fun onPause() {
@@ -70,4 +70,4 @@ class MainActivity : Activity() {
7070
disposable.dispose()
7171
}
7272
}
73-
}
73+
}

build.gradle

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ ext {
66
compileSdkVersion = 28
77
buildToolsVersion = '28'
88
gradleVersion = '4.4.1'
9-
kotlinVersion = '1.2.51'
9+
kotlinVersion = '1.2.60'
10+
detektVersion = '1.0.0.RC6-1'
1011
}
1112

1213
ext.deps = [rxjava2 : 'io.reactivex.rxjava2:rxjava:2.2.0',
@@ -19,9 +20,10 @@ ext.deps = [rxjava2 : 'io.reactivex.rxjava2:rxjava:2.2.0',
1920
mockitocore : 'org.mockito:mockito-core:2.21.0',
2021
nullaway : 'com.uber.nullaway:nullaway:0.5.3',
2122
errorprone : 'com.google.errorprone:error_prone_core:2.3.1',
23+
ktlintgradle : 'gradle.plugin.org.jlleitschuh.gradle:ktlint-gradle:4.1.0',
2224
kotlinstdlib : "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion",
2325
kotlingradleplugin: "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion",
24-
detekt : "gradle.plugin.io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.0.RC6-1"]
26+
detekt : "gradle.plugin.io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detektVersion"]
2527

2628
buildscript {
2729
repositories {

0 commit comments

Comments
 (0)