there's no way to adjust the output of zip/sexpr, right?
in what way? please be more specific
given @foo, i want (splint/deref foo) not (deref foo)
actually it's a bug in rewrite-clj that the deref isn't fully qualified, it should be. that's been filed here. rewrite-clj doesn't allow rendering this different unless you override the protocol
which for a library isn't recommended
forgot link to issue: https://github.com/clj-commons/rewrite-clj/issues/305
Oh right... I should finally go ahead and merge the associated PR https://github.com/clj-commons/rewrite-clj/pull/306
well, then my question stands: given @foo, i want (splint/deref foo) not (clojure.core/deref foo) . is that possible in rewrite-clj or do i need to write my own sexpr converter?
my goal is to know when a piece of code was originally written with @ and not deref/`clojure.core/deref` so i can return the code in the same style it was in when i read it
When you use sexpr you will often lose information. Do you need to use sexpr?
the workaround-ish way of doing this is to look at occurrences of clojure.core/deref / deref and then go back to the original location (if you have that on the s-expr) to see if the original was written with @. the even shorter way: if the s-expr still contains location metadata, you can even derive it from that information only, since the begin and end-location of "@" only differ in one character
and yeah, you should avoid calling sexpr if you can, it's lossy
#splint is written to match against clojure data structures, and the "alternative" forms that it prints are built in clojure data structures as well, so when I'm using rewrite-clj to do potential replacements, I need to convert the node to a sexpr and then convert the resulting sexpr back to a node
you don't need to do it that way
switching from edamame to rewrite-clj would be a dramatic loss of performance for all situations where autocorrect isn't needed (and would complicate all of the hand-built replacement code that currently expects clojure data structures)
if you have a suggestion for how to avoid this that doesn't involve changing roughly 110 existing splint rules, i'm all ears
I'd keep the matching logic the same, but do the rewriting in terms of nodes by looking up the location of the original s-expr and then parse stuff with rewrite-clj, rewrite nodes, then use str . sexpr is sometimes handy, but can often fail
all the rewriting logic in clojure-lsp is done in that way, for good reasons
yeah, I think of sexpr as a convenience fn to use very cautiously
I'm sure you've read the user guide on this but here it is anyway: https://cljdoc.org/d/rewrite-clj/rewrite-clj/1.1.48/doc/user-guide#sexpr-nuances
here's an example of the kind of code that exists: https://github.com/NoahTheDuke/splint/blob/85ac71378ae57b387fbe650aa7d133c7458fad27/src/noahtheduke/splint/rules/lint/body_unquote_splicing.clj
the pattern matches the form and builds a map of matched objects {?f ... ?init-arg ...}, and then the :on-match just builds a new clojure datastructure using those objects (`(list ?f (list 'let [...] ...))`), and returns it in :replace-form
having worked with clj-kondo's hooks api, it's really cumbersome to write (hook/list-node [(hook/token-node ?f) (hook/list-node ...)]) and avoiding that pain was one of my big motivations for splint
clj-kondo also supports :macroexpand hooks which are less cumbersome
but come with trade-offs
right, there's trade-offs to all of these approaches lol
that existed prior to splint
i don't mean to denigrate clj-kondo, my feelings come from "using it in anger" as they say lol. i wanted to try something new and until now it's worked well, but supporting autocorrect looks like it'll require me to make some fundamental changes
maybe find a hammock and sleep on it a bit, you might come up with some new awesome way to achieve your goal
but if you have more rewrite-clj questions, you know where to find us! ❤️
you probably didn't get the answers you wanted today, but I hope we helped to clarify things.
haha it's all good
it's all a learning journey!
standing on the shoulders of giants (you two) as i build this thing
Hey, I'm no giant! Just a happy bumbler! But borkdude, well, you can stand on his shoulders (if he's ok with that).
Or screw that @nbtheduke, we'll stand on your shoulders! Don't sell yourself short!