Custom KtLint rules to check some of code style rules
Rules set was originaly developed as a module in https://github.com/StepicOrg/stepik-android repository.
explicit-public-type
— insists explicit type on public methodsexpression-body
(with autocorrection) — insists use of expression body istead of returnexpression-body-indent
(with autocorrection) — tracks indent of expression body
Add following repository to access binaries
allprojects {
repositories {
maven {
url = "https://maven.pkg.github.com/eadm/ktlint-rules"
credentials {
username = System.getenv("GITHUB_USER") ?: project.properties["GITHUB_USER"]
password = System.getenv("GITHUB_PERSONAL_ACCESS_TOKEN") ?: project.properties["GITHUB_PERSONAL_ACCESS_TOKEN"]
}
}
}
}
Dependency
dependencies {
implementation 'ru.nobird.android.ktlint:rules:1.0.0'
}
And then follow instructions from https://github.com/pinterest/ktlint
Example of ktlint
task realisation
To run rules tests can be used following task
./gradlew ktlint-rules:test
To see ktlint in action for sample app
./gradlew app:ktlint
And to autocorrect
./gradlew app:ktlintFormat