darklua
darklua copied to clipboard
Add `remove_continue` rule
Closes #202
Examples
Case: There are continue and break together in a loop but there are more continue than break
Input
for i = 1, 10 do
if i % 3 == 0 then
continue
end
if i % 6 == 0 then
continue
end
if i % 9 == 0 then
continue
end
if i % 10 == 0 then
break
end
end
Output
for i = 1, 10 do
local __DARKLUA_REMOVE_CONTINUE_break5784919bbab63ddf=false repeat if i % 3 == 0 then
break
end
if i % 6 == 0 then
break
end
if i % 9 == 0 then
break
end
if i % 10 == 0 then
__DARKLUA_REMOVE_CONTINUE_break5784919bbab63ddf=true break
end
until true if __DARKLUA_REMOVE_CONTINUE_break5784919bbab63ddf then break end end
Case: There are continue and break together in a loop but there are more break than continue
Input
for i = 1, 10 do
if i % 3 == 0 then
break
end
if i % 6 == 0 then
break
end
if i % 9 == 0 then
break
end
if i % 10 == 0 then
continue
end
end
Output
for i = 1, 10 do
local __DARKLUA_REMOVE_CONTINUE_continue5784919bbab63ddf=false repeat if i % 3 == 0 then
break
end
if i % 6 == 0 then
break
end
if i % 9 == 0 then
break
end
if i % 10 == 0 then
__DARKLUA_REMOVE_CONTINUE_continue5784919bbab63ddf=true break
end
until true if not __DARKLUA_REMOVE_CONTINUE_continue5784919bbab63ddf then break end end
Case: There is only continue in a loop
Input
for i = 1, 10 do
if i % 5 == 0 then
continue
end
print(i)
end
Output
for i = 1, 10 do
repeat if i % 5 == 0 then
break
end
print(i)
until true end
Note
blake3used for exit variable name (break_variable_name,continue_variable_name)
TO-DOs
- [x] Add tests for cases where continue and break are mixed.