Skip to content
Moritz Heidkamp edited this page Mar 10, 2022 · 2 revisions

cn Clean ns

This op performs the following cleanups of the ns form:

  • Eliminate :use clauses in favor of refer :all.
  • Sort required libraries, imports and vectors of referred symbols
  • Rewrite to favor prefix form, e.g. [clojure [string test]] instead of two separate libspecs
  • Raise errors if any inconsistencies are found (e.g. a libspec with more than one alias).
  • Remove any duplication in the :require and :import form.
  • Remove any unused libspec vectors
  • Remove unused symbols from the :refer vector, or remove it completely.
  • Remove any unused imports

Note that we have to build an AST in order to do this, so if the current file is in a bad state this op won't work.

The prefix rewriting can be turned off by tweaking cljr-favor-prefix-notation.

Insertion of newline after the :require keyword can controlled via cljr-insert-newline-after-require.