grunt-remove-logging
grunt-remove-logging copied to clipboard
code destruction due missing semicolon in commented lines
The plugin tends to be destructive when there are missing semicolons, even in comments.
An example:
Executing the grunt
task in this piece of code
(function () {
function foo (msg) {
// console.log(msg) # <= note missing ;
}
function bar (msg) {
console.log(msg);
}
function baz (msg) {
console.log(msg);
}
})();
produces this log-output:
Running "removelogging:test" (removelogging) task
Removed 2 logging statements from remove-logging-test.js
and will result in:
(function () {
function foo (msg) {
//
}
function baz (msg) {
}
})();
Sadly this renders the plugin to be completely unusable.
Also, cause of that problem this plugin makes code-mess on case:
console.log('test')
if ( testvar ) {
//doing smth
}
comes to this:
//doing smth
}
I think u have to fix regexp by this:
console.(?:log)\s*\([^;]*?\)(?!\s*[;,]?\s*\/\*\s*RemoveLogging:skip\s*\*\/);?\s*
(i pay your attention to this \([^;]*?\)
instead of your \([^;]*\)
)
The trade off with that regex is that you cannot use a semi-colon inside the actual console text (like console.log('some; message');
, which I tend to do a lot.
plz note this unfixed BUG to README, it can save life
+1 would like to see a fix for this issue
Faced the same issue and added a fix for it in this fork: https://github.com/jimdoyle82/grunt-remove-logging
Done a pull request, so hopefully it gets accepted.