darklua icon indicating copy to clipboard operation
darklua copied to clipboard

Removing prints, warnings and/or error functions

Open Sebastian2852 opened this issue 10 months ago • 1 comments

A rule that allows for the removal of calls the print(), warning() and error(). These could all be seperate rules or be all under a single rule, but I think having seperate rules for each would be best.

Sebastian2852 avatar Jan 30 '25 16:01 Sebastian2852

Maybe "remove_logging"? Where the rule has different options to remove print() and warn() (both enabled by default). Should probably have an option like preserve_arguments_side_effects in remove_debug_profiling. Can't really see a reason to remove error() calls from the code but it could always be an option (though personally it should be off by default as it would change code behaviour).

Although if you want something to remove prints in a sort of production build you could always reimplement it with inject_global_value and remove_unused_if_branch:

if _G.PROD then
    local NOOP = function() end
    print = NOOP
    warn = NOOP
end

-- These won't omit when the "PROD" value is true.
print("Hello World!")
warn("Warning message")

(If #36 gets added, the actual print() and warn() calls would also be entirely removed.)

Though this rule would remove the boilerplate code you would have to write in each file to add this right now.

ewd3v avatar Feb 03 '25 14:02 ewd3v