Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/razum2um/dead_code_terminator
❌ Remove dead conditional branches
https://github.com/razum2um/dead_code_terminator
dead-code-elimination dead-code-removal ruby-parser
Last synced: 27 days ago
JSON representation
❌ Remove dead conditional branches
- Host: GitHub
- URL: https://github.com/razum2um/dead_code_terminator
- Owner: razum2um
- License: mit
- Created: 2021-05-31T04:42:36.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-05-31T22:53:56.000Z (over 3 years ago)
- Last Synced: 2024-10-06T04:24:25.648Z (about 1 month ago)
- Topics: dead-code-elimination, dead-code-removal, ruby-parser
- Language: Ruby
- Homepage:
- Size: 24.4 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# DeadCodeTerminator
![ci](https://github.com/razum2um/dead_code_terminator/actions/workflows/main.yml/badge.svg)
[![gem](https://badge.fury.io/rb/dead_code_terminator.svg)](https://rubygems.org/gems/dead_code_terminator)
[![codecov](https://codecov.io/gh/razum2um/dead_code_terminator/branch/master/graph/badge.svg)](https://app.codecov.io/gh/razum2um/dead_code_terminator)This acts like [webpack's DefinePlugin](https://webpack.js.org/plugins/define-plugin/) with minification pass. It allows to eliminate dead code statically, which can be required by regulations.
```ruby
value = if ENV['FLAG']
:then_branch
else
value2 = unless ENV['PRODUCTION']
:then_branch
else
ENV['RUNTIME'] ? :else1 : :else2
end
end
``````ruby
# returns a valid ruby code string back with statically evaluated conditions
DeadCodeTerminator.strip(string, env: { "PRODUCTION" => true, "FLAG" => false })
``````ruby
value =value2 =
ENV['RUNTIME'] ? :else1 : :else2
```Note: it keeps *precise* code locations (including whitespaces and line-breaks).
So if you have hotfix patches from upstream - they'll be applied without conflicts.
Backtrace line numbers are also preserved and can point to original code.Other examples can be found in [specs](https://github.com/razum2um/dead_code_terminator/blob/master/spec/dead_code_terminator_spec.rb)
## TODO
- builtin file tree processing
## LicenseThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).