rewrite-clj

https://github.com/clj-commons/rewrite-clj
martinklepsch 2021-05-04T08:11:42.252500Z

does anyone know of a tool that would remove dead branches of code assuming test conditions like (if (= 1 1) :a :b) or (if true :a :b) I might work on something like this (got a nice starting point from @borkdude in https://gist.github.com/borkdude/77369ba1b2d0fbd2608a8d12f518ade3) but was just wondering if there might be something out there for this particular thing already

borkdude 2021-05-04T08:12:11.252700Z

I'm not aware of something like that

martinklepsch 2021-05-04T08:13:50.254800Z

The approach I’d take now is splitting it into two separate scripts/steps: 1. replace the feature test with it’s literal value, e.g. (feature1-enabled?) gets replaced with true 2. a more general script that tries to find dead conditional branches and removes code / reformats accordingly

martinklepsch 2021-05-04T08:15:19.255600Z

It seems like 2. could be part of a tool like carve if that were to expand scope from just vars to generally finding & removing dead code

borkdude 2021-05-04T08:27:34.256200Z

yeah, or clojure-lsp. but I don't think it's very common to have dead code based on "always true" conditions

martinklepsch 2021-05-04T18:27:24.257400Z

yeah, the (if true ,,,) case is pretty unusual I guess but I think in context of replacing a more complex form with true it kind of makes sense and would allow for a nice separation