rewrite-clj

Oliver George 2022-05-31T00:05:04.810559Z

Am I missing something obvious for treating code as data and interrogating it? The code is all Clojurescript. I've been playing with clj-rewrite. What I really want is to write scripts which analyse my source code - looking for undesirable code patterns, estimating complexity, priporitising testing effort on usage, KPIs around prepost use, it goes on... Reading is non trivial because of read macros. So clj-rewrite is nice. Then it gets fiddly because of needing to resolve aliases (manually got around the worst of this by parsing the ns forms). Feels like a script which reads, resolves and shoves everything into a datascript db would be good. I think perhaps that's what clj-kondo used to do but perhaps that changed. Haven't tried edamame yet.

lread 2022-05-31T01:05:56.305129Z

@olivergeorge you might be interested in taking advantage of https://github.com/clj-kondo/clj-kondo/tree/master/analysis.

Oliver George 2022-05-31T01:11:17.288119Z

Thanks. I got the impression that's more limited in scope but I'll look again.

lread 2022-05-31T01:12:55.106349Z

Well, clj-kondo uses rewrite-clj to read Clojure. But then it interprets it for the purposes of linting. You get access to those interpretations via data analysis.

☝️ 1
lread 2022-05-31T01:14:05.212479Z

There’s a chance it might not meet your requirements, but probably worth another look-see.

Oliver George 2022-05-31T01:14:21.065989Z

It does generate lots of useful data.

borkdude 2022-05-31T05:19:15.666849Z

Take a look at grasp as well (Google borkdude grasp)

borkdude 2022-05-31T05:19:27.781859Z

On the phone so I can't paste link

Oliver George 2022-05-31T06:33:12.524659Z

Thanks @borkdude I was having a great time with that this morning. Was able to do things like "find maps with a specific key where the value is missing something". Worked like a charm with very little code. Brilliant stuff.

Oliver George 2022-05-31T06:33:37.371549Z

What is it using under the hood? The deps didn't reveal much.

borkdude 2022-05-31T07:06:17.947589Z

It's using spec under the hood :)

borkdude 2022-05-31T07:06:42.238739Z

And SCI, but only for resolving var names, not really for anything fancy

Oliver George 2022-05-31T07:41:19.682109Z

Nice. And Sci, in turn, uses edamame.

borkdude 2022-05-31T07:42:31.437619Z

Yes