Fork me on GitHub
#rewrite-clj
<
2021-05-04
>
martinklepsch08:05:42

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

borkdude08:05:11

I'm not aware of something like that

martinklepsch08:05:50

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

martinklepsch08:05:19

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

borkdude08:05:34

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

martinklepsch18:05:24

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