grunt-remove-logging icon indicating copy to clipboard operation
grunt-remove-logging copied to clipboard

code destruction due missing semicolon in commented lines

Open davidlinse opened this issue 11 years ago • 5 comments

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.

davidlinse avatar Sep 01 '13 09:09 davidlinse

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 \([^;]*\) )

alexglue avatar Dec 17 '13 08:12 alexglue

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.

ehynds avatar Dec 17 '13 15:12 ehynds

plz note this unfixed BUG to README, it can save life

atian25 avatar Jan 10 '14 07:01 atian25

+1 would like to see a fix for this issue

krisalexander200 avatar Apr 02 '14 17:04 krisalexander200

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.

superelement avatar Jan 31 '15 11:01 superelement