Fork me on GitHub
#cider
<
2021-04-07
>
Yehonathan Sharvit06:04:21

Sometimes, I need to require a namespace for its side-effects (e.g. defmethod declarations).

(ns foo
  (:require bar))
But cider-refactor removes `bar` from the require list, as it “Remove any unused libspec vectors”. Does anyone know a way to tell clj-refactor to keep `bar`?

jumar07:04:39

I don't know how to instruct clj-refactor to do this but I tend to write a comment why it's supposed to be there and check diffs before I commit the changes (+ extra code review step which should catch that too).

Yehonathan Sharvit07:04:48

That’s what I did. But I missed it during code review. And boom! My lib was corrupted.

Yehonathan Sharvit07:04:22

It’s also hard to catch with unit tests because the namespace is loaded by some tests.

jumar07:04:35

The other thing is that I don't really encounter this issue much - which specific function from clj-refactor triggers this behavior? I mostly use cljr-add-require-to-ns and that seems to work fine (that is doesn't touch the other, even unused, requires; just sorts them)

jumar07:04:10

For unused requires I simply remove them manually after quick inspection - relying on "linter errors" reported by clj-kondo

jumar07:04:17

Yeah, I never use that.

dpsutton12:04:32

(comment bar/keep-me)

dpsutton12:04:53

We do this a lot at work

Yehonathan Sharvit12:04:45

You really call the function keep-me ?

dpsutton12:04:30

Yeah it doesn’t need to resolve, just show up as a use of the namespace. The keep-me makes it clear what it’s purpose is

vemv17:04:44

What I normally do is placing a require below the ns form. There's no difference to the compiler - ns is just standardized syntax sugar over require It's fairly easy to see why a top-level require is there so I generally don't even attach an explanatory comment to them

👍 3
tvaughan15:04:36

Yes, many many times a day

nivekuil17:04:52

I always use C-x C-e or C-c C-p but I might start using C-c C-e now that I know it exists. Is it an upgrade from C-c C-v? it would be for me on dvorak but seems worse for qwerty

bozhidar20:04:43

Whether it's easier to press it debatable, but it seems like a better mnemonic to me, as it (e)val in its name.

bozhidar20:04:12

Also the keybinding in quesiton won't change much - it will become C-c C-e (C)-e.

bozhidar20:04:06

The only reason why C-c C-e and C-x C-e both are both mapped to the same command is to mimic SLIME - early on it seemed like a good idea, but as CIDER has way more commands than SLIME at some point I started to regret wasting keybindings in this fashion.

bozhidar20:04:55

Anyways, I don't feel strongly about this, I was just wondering how attached people are to this. I've never used C-c C-e myself.

tvaughan20:04:03

I won't mind if it's changed

hkjels06:04:39

I too use C-c C-e a lot, but I also don’t mind if it’s changed

bozhidar14:04:32

More context - I was considering to use C-c C-e for the eval keymap, as it'd be more convenient than C-c C-v.

bozhidar14:04:51

(or at least it will be easier to remember)