Fork me on GitHub
#cider
<
2021-12-11
>
diego.videco16:12:45

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.

dpsutton16:12:11

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

@diego.vid.eco 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!)

borkdude16:12:34

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

borkdude16:12:50

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

vemv16:12:39

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

borkdude16:12:13

works for JVM, not for CLJS

vemv16:12:46

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

borkdude16:12:45

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
vemv16:12:25

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

borkdude16:12:32

but then again, so doesn't potemkin

dpsutton16:12:36

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

👀 1
vemv16:12:31

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

vemv16:12:58

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

vemv16:12:31

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

borkdude16:12:48

clj-kondo at least finds all top level namespace usages

👍 1