This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-03
Channels
- # aws (24)
- # beginners (377)
- # calva (33)
- # cider (1)
- # circleci (22)
- # cljs-dev (7)
- # clojure (40)
- # clojure-europe (1)
- # clojure-france (9)
- # clojure-norway (3)
- # clojure-taiwan (2)
- # clojurescript (8)
- # conjure (10)
- # cryogen (2)
- # emacs (1)
- # fulcro (23)
- # helix (1)
- # hoplon (2)
- # luminus (7)
- # meander (3)
- # off-topic (2)
- # re-frame (7)
- # reagent (8)
- # reveal (38)
- # sci (13)
- # shadow-cljs (17)
- # tools-deps (17)
- # vim (1)
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 :div.mx-2.my-1
, 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?
I found some leads:
• https://cljdoc.org/d/leiningen/leiningen/2.9.5/doc/leiningen-plugins#evaluating-in-project-context, 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 https://github.com/borkdude/edamame 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 https://github.com/borkdude/grasp.
As reference, grasp can search through my entire .m2 dir in 15 seconds (when parallelized)
@U04V15CAJ Thanks, I will take a look.