oakmac / clojurefmt-js

clojurefmt in JavaScript
ISC License
4 stars 0 forks source link

implement "how to ns" rules #5

Open oakmac opened 1 year ago

oakmac commented 1 year ago

The formatter should implement the rules from how to ns

oakmac commented 3 months ago

Note for the future: we will have to adjust the node tree / "print from scratch" the ns form in order to accomplish sorting of :require nodes. This will be tricky with comments; I think they will need to be "attached" to a require line and we will have to detect that and keep the comments when sorting.

This is a change from the rest of the algorithm where it basically "prints what it has, with adjustments" as opposed to the "print from scratch" approach.

oakmac commented 3 months ago

How should the comment ; aaa be formatted in the below example? It occurs outside of the ns form.

(ns example
  (:refer-clojure :only [get])) ; aaa

Should it be "attached" to the :refer-clojure line or no? I think the answer is "no" because it exists outside of the ns form.

In this example, it should be "attached" to the :refer-clojure line:

(ns example
  (:refer-clojure :only [get]) ; aaa
  )

Update: I changed my mind about this. ; aaa should be attached to the :refer-clojure line in both cases.

oakmac commented 3 months ago

Useful: https://8thlight.com/insights/clojure-libs-and-namespaces-require-use-import-and-ns