Fork me on GitHub
Vincent Cantin04:01:56

Hi. I would like to build a CLI tool which extracts CSS classnames from the user’s CLJS source code and I am not sure where to start. The class names could be isolated strings in the source code like ["mx-2" "my-1"], inside keywords like, or if possible tagged by meta-data ^:css ["mx-2" "my-1"] My first (dummy) approach will be to scan source file as edn, but I may get false positives and miss the classe-name which could be generated using macro. I feel that the compiler could help, but I don’t know how exactly. Which path would you recommend? Do you have some links to relevant articles?

Vincent Cantin06:01:34

I found some leads: •, so that I can use macro expanded source code. • all-ns, ns-interns and ns-map to list the root vars in a namepace, from which I can read associated metadata. • I can ask the user to wrap its reagent functions in a macro which adds the ^:css metadata derived from the body of the function. If I missed something else, I would be glad to know - I am a beginner in this area.


you might look into the machinery underneath clj-kondo. it already has a lot of static analysis tools that @U04V15CAJ has built for it that have a high likelihood of being useful


@U8MJBRSR5 A few pointers: you can use for parsing Clojure code. You can also use tools.reader directly but it's likely that edamame works better with GraalVM native-image, if you want to make a native CLI. Another pointer: I think your code search can be implemented directly using

👍 3

As reference, grasp can search through my entire .m2 dir in 15 seconds (when parallelized)

🔥 3

and you get to use specs for what you want to search

Vincent Cantin18:01:25

@U04V15CAJ Thanks, I will take a look.