Skip to content

πŸ¦„ A sample repository adapting ktlint on android project

License

Notifications You must be signed in to change notification settings

HaenaraShin/Ktlint-Android-Sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Ktlint-Android-Sample

This proejct introduce how to apply ktlint on an android project.

πŸ“Œ μžμ„Έν•œ μ„€λͺ…은 λΈ”λ‘œκ·Έμ—μ„œ ν™•μΈν•˜μ‹€ 수 μžˆμŠ΅λ‹ˆλ‹€.

⭐️ What is a Ktlint?

ktlint is a lint for Kotlin. It is a static code analytics tool that checks if your codes fits on Kotlin coding convention or style guide line.πŸ”Ž

By applying Ktlint, consistency of kotlin codes in your project would be maintained strongly. As a result, unnecessary communication costs because of low readability and differences in coding styles among team members can be reduced.

πŸ’β€β™‚οΈ Read more about ktlint here

πŸš€ How to apply ktlint

1. build.gradle(root)

  • Add plugin org.jlleitschuh.gradle.ktlint
  • Add repository maven https://plugins.gradle.org/m2/
  • Add classpath dependency org.jlleitschuh.gradle:ktlint-gradle:9.3.0
apply plugin: 'org.jlleitschuh.gradle.ktlint'
...
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
...
    dependencies {
        classpath "org.jlleitschuh.gradle:ktlint-gradle:9.3.0"
    }
}

πŸ’β€β™‚οΈ Check an example file on here.

2. build.gradle(android module)

  • Add plugin org.jlleitschuh.gradle.ktlint.
  • Add ktlint plugin setting.
plugins {
    id 'org.jlleitschuh.gradle.ktlint'
}
...
ktlint {
    android = true
    outputColorName ="RED"
    verbose = true
    disabledRules.addAll("import-ordering")
}

πŸ’β€β™‚οΈ Check an example file on here.

3. build.gradle(non-android module)

  • Add plugin org.jlleitschuh.gradle.ktlint.
  • Add ktlint plugin setting.
plugins {
    id 'org.jlleitschuh.gradle.ktlint'
}
...
ktlint {
    android = false
    outputColorName ="RED"
    verbose = true
    disabledRules.addAll("import-ordering")
}

πŸ’β€β™‚οΈ Check an example file on here.

🌈 How to use ktlint

1. Ktlint check

Execute a following gradle task on Android Studio's gradle tab.

  • ProjectName > Tasks > verification > ktlintCheck

Otherwise, on type following command on console.

./gradlew ktlintCheck

2. Check ktlint on git commit (Usubg Git hook)

Execute a following gradle task on Android Studio's gradle tab.

  • ClassNote > Tasks > help > addKtlintCheckGitPreCommitHook

Otherwise, on type following command on console.

./gradlew addKtlintCheckGitPreCommitHook
  • If follwoing error is occurred, create a directory ./.git/hooks on your project directory.

Execution failed for task ':addKtlintCheckGitPreCommitHook'. java.io.IOException: No such file or directory

3. Make your Android Studio formatter following rule of Ktlint.

Execute a following gradle task on Android Studio's gradle tab.

  • ClassNote > Tasks > help > ktlintApplyToIdea

Otherwise, on type following command on console.

./gradlew ktlintApplyToIdea

πŸ‘€ Reference

Sample codes and instructions of this project refers to following list

License

MIT License

Copyright (c) 2020 Haenala Shin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

πŸ¦„ A sample repository adapting ktlint on android project

Topics

Resources

License

Stars

Watchers

Forks

Languages