Skip to content

Instantly share code, notes, and snippets.

@Deraen
Last active October 4, 2019 13:43
Show Gist options
  • Save Deraen/85ab85a626844a4142cc5754484adae4 to your computer and use it in GitHub Desktop.
Save Deraen/85ab85a626844a4142cc5754484adae4 to your computer and use it in GitHub Desktop.
Ideas for linter checks

Merge with map literal

(merge a {:a 1 :b 2}) -> (assoc a :a 1 :b2)

(-> foo (merge {:foo :bar}) -> (-> foo (assoc :foo :bar))

Reasoning:

  • Performance
  • Easier to read?

Assoc-in or update-in with concat

(assoc-in m (concat [:foo :bar] path) v) -> (update-in m [:foo :bar] assoc-in path v)

Reasoning:

  • Performance
  • Easier to read?

Assoc-in or other path operation with single item literal path

(assoc-in m [:foo] v) -> (assoc m :foo v)

(get-in m [:foo]) -> (:foo m)

(update-in m [:foo] f) -> (update m :foo f)

Reasoning:

  • Performance
  • Easier to read

Use ns alias or refer instead of full namespaced symbol

(clojure.string/split v #"/") -> (str/split v #"/")

Reasoning:

  • Easy to accidentally use namespace that is not required
  • Even with core ns that are always available, good practice to ensure they are required

If branches with nearly identical call

(if x
  (f 1)
  (f 2))
=>
(f (if x 1 2))

Indentation check

Custom forms?

(re/reg-sub :view
           (fn [db _]
             (get-in db [:view])))
=>
(re/reg-sub :view
  (fn [db _]
    (get-in db [:view])))

Reasoning:

Let as lone child inside for/doseq etc.

(for [...]
  (let [...]
    ...))
=>
(for [...
      :let [...]]
  ...)
  • Less indentation?
  • More complex/magical -> bad idea?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment