seaofvoices / darklua

A command line tool that transforms Lua code
https://darklua.com/
MIT License
71 stars 9 forks source link

Add rule to remove assert calls #163

Closed jeparlefrancais closed 9 months ago

jeparlefrancais commented 9 months ago

Closes #2

Add a new rule remove_assertions that remove calls to the assert global functions

github-actions[bot] commented 9 months ago

Coverage after merging remove-assert-call-rule into main will be

87.02%

Coverage Report for Changed Files
FileStmtsBranchesFuncsLinesUncovered Lines
src/rules
   mod.rs89.14%100%77.78%90.60%110–112, 116, 126–128, 146–148, 150, 181–183, 273, 314–315, 350–352, 415–417, 71
   remove_assertions.rs92.68%100%86.67%94.03%14, 34
matthargett commented 9 months ago

If removing the assert() results in an empty block, will that block be removed? If there's a simple boolean expression gating the block, will that also be removed?

jeparlefrancais commented 9 months ago

If removing the assert() results in an empty block, will that block be removed? If there's a simple boolean expression gating the block, will that also be removed?

Hey Matt 👋 The idea is that the empty do block is being removed by the remove_empty_do rule after in the process sequence. And by a boolean gating the block, do you mean something like this:

if someCondition() then
    assert(...) -- that would get converted to a `do end`
end

That would still leave an empty if statement right now. That gives me an idea for a rule I could make that could restructure empty control flow statements though. Something that takes empty ifs and loops and flattens them into do block that preserves potential side effects. I need to think about this 🤔