Liking cljdoc? Tell your friends :D

Metrics

metrics/fn-length

Enabled by defaultSafeAutocorrectVersion AddedVersion Updated
falsetruefalse1.6.01.6.0

Avoid defn-defined functions longer than some number (10) of lines of code. Longer functions are harder to read and should be split into smaller-purpose functions that are composed.

The total length is configurable, and the size can be configured (:body or :defn styles) to be measured from the entire defn form or the vector+body.

Examples

;; :body style (default)
(defn foo
  [arg] ;; <- starts here
  0
  1
  ...
  9
  10) ;; <- ends here

(defn foo
  ([] (foo 100)) ;; <- starts and ends here
  ([arg] ;; <- starts here
   0
   1
   ...
   9
   10)) ;; <- ends here

;; :defn style
(defn foo ;; <- starts here
  [arg]
  0
  1
  ...
  9
  10) ;; <- ends here

(defn foo ;; <- starts here
  ([] (foo 100))
  ([arg]
   0
   1
   ...
   9
   10)
) ;; <- ends here

Configurable Attributes

NameDefaultOptions
:chosen-style:body:body, :defn
:length10Number

Reference


metrics/parameter-count

Enabled by defaultSafeAutocorrectVersion AddedVersion Updated
falsetruefalse1.7.01.7.0

Avoid parameter lists with more than 4 positional parameters.

The number of parameters can be configured with :count. The default style :positional excludes & args rest parameters, and the style :include-rest includes them.

Functions with multiple arities will have each arity checked.

Examples

;; :positional style (default)
; avoid
(defn example [a b c d e] ...)
(defn example ([a b c d e] ...) ([a b c d e f g] ...))
(defn example [a b c d e & args] ...)

; prefer
(defn example [a b c d] ...)
(defn example ([a b c] ...) ([a b c e] ...))
(defn example [a b c d & args] ...)

;; :include-rest style
; avoid
(defn example [a b c d & args] ...)

; prefer
(defn example [a b c & args] ...)

Configurable Attributes

NameDefaultOptions
:chosen-style:positional:positional, :include-rest
:count4Number

Reference

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close