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

Clj-kondo: a linter for Clojure code that sparks joy @ ClojuTRE 2019

Clj-kondo: a linter for Clojure code that sparks joy @ ClojuTRE 2019

Clj-kondo is a linter for Clojure code that sparks joy. It analyzes your code without evaluating it and detects arity errors, redundant expressions, unused requires, missing test assertions and more. It provides fast editor feedback because it runs instantly as a native binary, not depending on a REPL in a JVM. In this talk we will see what it can do, how it is implemented and how it compares to other Clojure linters.

Michiel Borkent

September 27, 2019
Tweet

More Decks by Michiel Borkent

Other Decks in Programming

Transcript

  1. Michiel Borkent

    @borkdude

    View Slide

  2. Word origins

    View Slide

  3. Clojure linters
    Linter Focus CLJS? Macroexpand? Execution
    Eastwood General No core + user JVM
    Kibit Idioms No No JVM
    Joker General Yes core Go native
    Cljfmt Formatting Yes n/a JVM
    How to ns How to ns Yes n/a Clojure JVM
    Clj-kondo General Yes core GraalVM native / JVM

    View Slide

  4. Clj-kondo origin story
    • I've been a happy joker user since 2017

    • Wanted to add a feature:

    (defn foo [x] (def x 1))
    • Joker is written in Go, can it be done in Clojure?
    • Tried with Clojure on GraalVM (native = fast startup like joker)

    • Success with rewrite-clj which is based on tools.reader

    • Writing more linting features was too much fun!

    View Slide

  5. Invalid code is still data

    View Slide

  6. View Slide

  7. View Slide

  8. Arity errors

    View Slide

  9. View Slide

  10. View Slide

  11. REPL state

    View Slide

  12. REPL state
    $ clj-kondo --lint src
    | grep "unresolved symbol c"
    src/dre/analytics/authors.clj:585:41:
    info: unresolved symbol c

    View Slide

  13. Unused let and fn bindings

    View Slide

  14. Unresolved symbols

    View Slide

  15. Redundant let + do

    View Slide

  16. Missing test assertion

    View Slide

  17. Style: don't refer :all

    View Slide

  18. Ns form cleanup

    View Slide

  19. Ns form cleanup

    View Slide

  20. Type checking

    View Slide

  21. Editor support

    View Slide

  22. .clj-kondo
    • .clj-kondo/config.edn

    • Shared configuration, intended for version control

    • .clj-kondo/.cache

    • Automatically updated when changing code in editor

    • Contains arity and other info about linted code

    • Allows linter to reason about multiple namespaces

    • Populate with lib info: clj-kondo --lint $(clj -Spath)

    View Slide

  23. Config
    from
    manifold.deferred
    Clj-kondo doesn't know how to lint this macro

    View Slide

  24. Config

    View Slide

  25. Analysis export

    View Slide

  26. Who uses clj-kondo?
    Github #438
    Add your company to the list:

    View Slide

  27. Thank you
    https://github.com/borkdude/clj-kondo

    View Slide