Fork me on GitHub

Is there a way with clj-refactor to prevent the clean-ns function from running when moving a form to another namespace? Or more concretely is there way to prevent it from deleting unused exports in a namespace? I am using potemkin/import-vars in one ns, so the unused requires aren't really unused.


we have a trick for this at work. in the require you have [some-ns :as alias] and in the code do (comment alias/keep-me)

vemv16:12:22 I recommend removing it from the ns form and using (require ...) right below it. ns is only sugar over require/`load` so there's no difference. There's a good chance other tools will also understand this pattern (clj-kondo does!)


clj-kondo (and clojure-lsp) won't warn/touch unused requires when they have 1) no alias and 2) no refers


if they don't have 1 and 2 then it is assumed the namespace was required for side effects


yeah that's a difference relative to refactor-nrepl, which doesn't infer things from ns libspecs In a way I like require , it seems very explicit/unmistakable


works for JVM, not for CLJS


don't quote me on this but doesn't cljs support require now?


not really. in the REPL yes, but in a file, perhaps only the first top level require, but not all over the place. don't also quote me on that

😀 1

yeah I had the same in mind, first top-level


but then again, so doesn't potemkin


The top level requires might make some reloading code not function correctly. Both tools namespace and possibly require :reload-all

👀 1

t.n for sure, that's a good call


honestly I consider it a flaw that it doesn't try analyzing the whole source other than the ns form


code in the wild not only can have top-level requires, but also conditional ones, which warrant a more advanced parsing


clj-kondo at least finds all top level namespace usages

👍 1