$30 off During Our Annual Pro Sale. View Details »

What I Talk About When I Talk About Ktlint

What I Talk About When I Talk About Ktlint

Yuichi Maekawa

March 20, 2018
Tweet

More Decks by Yuichi Maekawa

Other Decks in Programming

Transcript

  1. What
    I talk
    about
    when I
    talk
    about
    Ktlint
    kaelaela

    View Slide

  2. Problems in a large team
    ● Spawn untold coding rule
    ● Reviewer spend fluitless time for similer
    mistake
    ● Yesterday’s nice doc could be today’s trash

    View Slide

  3. Difficulty of Kotlin
    ● Many different ways of writing
    ● So we make many team rules
    ● These all rules can’t taught through word of
    mouth

    View Slide

  4. We have many solutions
    ● Inspect by Android Studio
    ● Static code analytics
    ● Automate with Danger
    etc...

    View Slide

  5. Static code analytics
    e.g.
    FindBugs
    Android Lint
    Ktlint
    ...

    View Slide

  6. What is ktlint?

    View Slide

  7. Customize with editorconfig

    View Slide

  8. Basic usage
    Write code Push CI Analytics + Danger Fix format Push Review Fix Push

    View Slide

  9. Not good enough
    Write code Push CI Analytics + Danger Fix format Push Review Fix Push
    we S I L ne fi d o r d .

    View Slide

  10. Redundant commits...
    ● fix danger comment
    ● fix danger
    ● fix code format
    ● format code
    ● format
    ● :put_litter_in_its_place:
    ...

    View Slide

  11. Write code Push CI Analytics + Danger Fix format Push Review Fix Push
    More and more automation

    View Slide

  12. Write code build & format push CI Analytics + Danger Review Fix Push
    More and more automation

    View Slide

  13. Write code build & format push CI Analytics + Danger Review Fix Push
    More and more automation
    No m ed n ev .
    No m or c it.
    No m or c e r a d!

    View Slide

  14. Add ktformat task to build.gradle
    task ktFormat {
    description "R.I.P danger..."
    classpath = configrations.ktlint
    Main = "com.github.shyiko.ktlint.Main"
    args "-F", "src/**/*.kt"
    }

    View Slide

  15. Add ktformat task to build.gradle
    task ktFormat {
    description "R.I.P danger..."
    classpath = configrations.ktlint
    Main = "com.github.shyiko.ktlint.Main"
    args "-F", "src/**/*.kt"
    } For p i

    View Slide

  16. Add ktformat task to build.gradle
    task ktFormat {
    description "R.I.P danger..."
    classpath = configrations.ktlint
    Main = "com.github.shyiko.ktlint.Main"
    args "-F", "src/**/*.kt"
    } Yo c ha t et s

    View Slide

  17. Only format @ local debug build time
    e.g.
    applicationVariants.all { variant ->
    def flavor = variant.productFlavors[0].name
    def buildType = variant.buildType.name
    if (flavor == 'develop' && buildType == 'debug') {
    ktFormat.execute()
    }
    }

    View Slide

  18. $./gradlew --profile ktFormat
    Che p r a c
    on p o c !

    View Slide

  19. What I talk about
    ● Use ktlint for your team
    ● Do not review about code fomat
    ● And I want to remove “Format commit”
    ● Use ktFormat for reviewer and you
    ● Format at local debug build time
    ● Focus your coding

    View Slide

  20. Tha y .
    What
    I talk
    about
    when I
    talk
    about
    Ktlint

    View Slide