[android] Fix Ktlint Gradle intergration, add documentation about linting (#685)
This commit is contained in:
23
platform/android/CONTRIBUTING.md
Normal file
23
platform/android/CONTRIBUTING.md
Normal 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.
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
plugins {
|
||||
id 'org.jmailen.kotlinter'
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: "com.jaredsburrows.license"
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
plugins {
|
||||
id 'org.jmailen.kotlinter'
|
||||
}
|
||||
|
||||
apply plugin: 'java-library'
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user