Clojure Linters

>100 Views

February 15, 18

スライド概要

Utilise linters for clean Clojure code (*> ᴗ •*)ゞ

profile-image

「楽しく楽にcoolにsmartに」を理想とするprogrammer/philosopher/liberalist/realist。 好きな言語はClojure, Haskell, Python, English, français, русский。 読書、プログラミング、語学、法学、数学が大好き! イルカと海も大好き🐬

シェア

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
1.

Clojure Linters

2.

Self-introduction lagénorhynque /laʒenɔʁɛ k ̃ / カマイルカ (defprofile lagénorhynque :name "Kent OHASHI" :languages [Clojure Haskell Python Scala English français Deutsch русский] :interests [programming language-learning mathematics] :contributing [github.com/japan-clojurians/clojure-site-ja])

3.

「Clojureをプロダクトに導⼊した話」

4.

1. cljfmt: formatter 2. eastwood: linter 3. kibit: idiom checker 4. Example Usage 5. Other Tools

6.

What's the problem? (when something (something-else) )

7.

$ lein cljfmt check (when something - (something-else) -) + (something-else))

8.

What's the problem? (when something something-else)

9.

$ lein cljfmt check (when something something-else) + something-else)

10.

What's the problem? (filter even? (range 1 10))

11.

$ lein cljfmt check (filter even? - (range 1 10)) + (range 1 10))

12.

What's the problem? (if something ala bala)

13.

$ lein cljfmt check (if something ala bala) + ala + bala)

14.

What's the problem? (or ala bala portokala)

15.

$ lein cljfmt check (or - ala - bala - portokala) + ala + bala + portokala)

17.

What's the problem? (ns linting-example.eastwood-target (:use [clojure.string]))

18.

$ lein eastwood src/linting_example/eastwood_target.clj:2:10: unlimited-use: Unl imited use of ([clojure.string]) in linting-example.eastwood-tar get

19.

What's the problem? (if-let [x []] (conj x 42) :falsy)

20.

$ lein eastwood src/linting_example/eastwood_target.clj:4:1: constant-test: Test expression is always logical true or always logical false: [] in form (if temp__5455__auto__ (clojure.core/let [x temp__5455__aut o__] (conj x 42)) :falsy)

21.

What's the problem? (defn f [x] (def y (* x x)) (+ y 2))

22.

$ lein eastwood src/linting_example/eastwood_target.clj:9:8: def-in-def: There i s a def of y nested inside def f

23.

What's the problem? (defn g [x] "blah blah blah." (* x x))

24.

$ lein eastwood src/linting_example/eastwood_target.clj:12:7: misplaced-docstrin gs: Possibly misplaced docstring, g src/linting_example/eastwood_target.clj:12:1: unused-ret-vals: C onstant value is discarded: "blah blah blah."

25.

What's the problem? (defn h [str] (str "Hello, " str "!"))

26.

$ lein eastwood src/linting_example/eastwood_target.clj:17:3: local-shadows-var: local: str invoked as function shadows var: #'clojure.core/str

28.

What's the problem? (defn add-one [x] (+ x 1))

29.

$ lein kibit At src/linting_example/kibit_target.clj:4: Consider using: (inc x) instead of: (+ x 1)

30.

What's the problem? (defn check-if-zero? [x] (== x 0))

31.

$ lein kibit At src/linting_example/kibit_target.clj:7: Consider using: (zero? x) instead of: (== x 0)

32.

What's the problem? (defn zip-with-* [xs ys] (map #(* %1 %2) xs ys))

33.

$ lein kibit At src/linting_example/kibit_target.clj:null: Consider using: * instead of: #(* %1 %2)

34.

What's the problem? (defn coll->vec [coll] (into [] coll))

35.

$ lein kibit At src/linting_example/kibit_target.clj:13: Consider using: (vec coll) instead of: (into [] coll)

36.

What's the problem? (defn flat-map [f coll] (apply concat (map f coll)))

37.

$ lein kibit At src/linting_example/kibit_target.clj:16: Consider using: (mapcat f coll) instead of: (apply concat (map f coll))

38.

Example Usage

39.
[beta]
e.g. lagenorhynque/situated-programchallenge/rest-server/project.clj
:plugins [[jonase/eastwood "0.2.5"]
[lein-cljfmt "0.5.7"]
[lein-kibit "0.1.6"]]
:aliases {"lint" ^{:doc "Execute cljfmt check, eastwood and kibit."}
["do" ["cljfmt" "check"]
["eastwood" "{:source-paths [\"src\"]}"]
["kibit"]]}

↓↓↓
lein cljfmt check && lein eastwood <opts> && lein kibit
= lein do cljfmt check, eastwood <opts>, kibit
= lein lint # alias as `lint`

40.

$ lein lint All source files formatted correctly == Eastwood 0.2.5 Clojure 1.9.0 JVM 9.0.1 Directories scanned for source files: src test == Linting rest-server.util == == Linting rest-server.boundary.db.core == == Linting rest-server.boundary.db.group == ... == Linting rest-server.handler.venue-test == == Linting rest-server.handler.meetup-test == == Linting rest-server.handler.member-test == == Warnings: 0 (not including reflection warnings) Exceptions thrown: 0

41.

Other Tools

42.

dependency lein deps :tree lein-ancient

48.

Utilise linters for clean Clojure code!