[android] Fix Ktlint Gradle intergration, add documentation about linting (#685)

This commit is contained in:
Bart Louwers
2023-01-11 15:09:58 +00:00
committed by GitHub
parent 243c1a1935
commit 01729b9a49
9 changed files with 53 additions and 47 deletions

View File

@@ -0,0 +1,23 @@
# Contributing - MapLibre GL Native for Android
## Kotlin
All new code should be written in [Kotlin](https://kotlinlang.org/).
### Style Checking
To check Kotlin style, we use [ktlint](https://pinterest.github.io/ktlint/). This linter is based on the [official Kotlin coding conventions](https://kotlinlang.org/docs/coding-conventions.html). We intergrate with it using the [kotlinder](https://github.com/jeremymailen/kotlinter-gradle) Gradle plugin.
To check the style of all Kotlin source files, use:
```
$ ./gradlew checkStyle
```
To format all Kotlin source files, use:
```
$ ./gradlew formatKotlin
```
You might find it helpful to install the [Ktlint](https://plugins.jetbrains.com/plugin/15057-ktlint-unofficial-) Android Studio plugin.

View File

@@ -276,7 +276,7 @@ android-checkstyle: gradle/configuration.gradle
# Runs checkstyle on the kotlin code
.PHONY: android-ktlint
android-ktlint: gradle/configuration.gradle
$(MBGL_ANDROID_GRADLE) -Pmapbox.abis=none ktlint
$(MBGL_ANDROID_GRADLE) -Pmapbox.abis=none checkstyle
# Runs lint on the Android SDK java code
.PHONY: android-lint-sdk

View File

@@ -1,3 +1,7 @@
plugins {
id 'org.jmailen.kotlinter'
}
apply plugin: 'com.android.library'
apply plugin: "com.jaredsburrows.license"
apply plugin: 'kotlin-android'

View File

@@ -1,3 +1,7 @@
plugins {
id 'org.jmailen.kotlinter'
}
apply plugin: 'java-library'
apply plugin: 'kotlin'

View File

@@ -1,4 +1,8 @@
apply plugin: 'com.android.application'
plugins {
id 'org.jmailen.kotlinter'
id 'com.android.application'
}
apply from: "${rootDir}/gradle/native-build.gradle"
android {

View File

@@ -42,7 +42,7 @@ class OfflineDownloadTest : OfflineRegion.OfflineRegionObserver {
override fun onError(error: String) {
Logger.e(TAG, "Error while creating offline region: $error")
}
},
}
)
}
@@ -74,7 +74,7 @@ class OfflineDownloadTest : OfflineRegion.OfflineRegionObserver {
17.0,
17.0,
1.0f,
false,
false
)
}

View File

@@ -243,9 +243,9 @@ class CustomizedLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyC
pulsingCircleDurationButton!!.text = selectedMode
if (selectedMode.contentEquals(
String.format(
"%sms",
DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS.toString()
)
"%sms",
DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS.toString()
)
)
) {
LOCATION_CIRCLE_PULSE_DURATION = DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS
@@ -255,9 +255,9 @@ class CustomizedLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyC
)
} else if (selectedMode.contentEquals(
String.format(
"%sms",
SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS.toString()
)
"%sms",
SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS.toString()
)
)
) {
LOCATION_CIRCLE_PULSE_DURATION = SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS
@@ -267,9 +267,9 @@ class CustomizedLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyC
)
} else if (selectedMode.contentEquals(
String.format(
"%sms",
THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS.toString()
)
"%sms",
THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS.toString()
)
)
) {
LOCATION_CIRCLE_PULSE_DURATION = THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS

View File

@@ -1,5 +1,3 @@
apply plugin: 'io.github.gradle-nexus.publish-plugin'
buildscript {
apply from: "${rootDir}/gradle/dependencies.gradle"
@@ -17,12 +15,16 @@ buildscript {
}
}
plugins {
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id("org.jmailen.kotlinter") version "3.13.0" apply false
}
allprojects {
repositories {
mavenCentral()
google()
}
apply from: "${rootDir}/gradle/ktlint.gradle"
}
subprojects {

View File

@@ -1,31 +0,0 @@
apply from: "${rootDir}/gradle/dependencies.gradle"
repositories {
mavenCentral()
}
configurations {
ktlint
}
dependencies {
ktlint("com.pinterest:ktlint:0.48.0") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
}
}
}
task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
classpath = configurations.ktlint
main = "com.pinterest.ktlint.Main"
args "--disabled_rules=no-wildcard-imports,trailing-comma-on-call-site,trailing-comma-on-declaration-site", "src/**/*.kt"
}
task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
classpath = configurations.ktlint
main = "com.pinterest.ktlint.Main"
args "-F", "src/**/*.kt"
}