Couto / groundskeeper

node.js package to remove forgotten console statements and specific blocks of code from you Javascript files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for deep namespaces

WickyNilliams opened this issue · comments

I have tried this with the grunt plugin and it seems to remove everything. I suppose it could potentially be an issue with the plugin not the lib, but I'm reporting here as I assume the plugin simply proxies to the lib.

If i have a customer logger solution:

var logger = {
  log : function() {
    console && console.log && console.log.apply(console, arguments);
  }
}

It would be great if I could supply the namespace "logger" and it remove all references to logger, that is, calls to logger.log would be stripped.

I'm currently at work, so I'm just asking/suggesting this in hope that it's a fast way to fix your problem, or to help me debugging it later:

Have you tried to specify the namespace option?

{
    console: true,                          // Keep console logs
    debugger: true                          // Keep debugger; statements
    pragmas: ['validation', 'development'], // Keep pragmas with the following identifiers
    namespace: ['App.logger', 'App.bucket'] // Besides console also remove function calls in the given namespace,
    replace: '0'                            // For the ones who don't know how to write Javascript...
}

I believe that if you do namespace: ['logger'] it would suffice to remove all methods of that object, if it's not happening, then yes it's a bug, and I will try to take a look into it in a few hours... =)

Yes I tried the namespaces option, but to no avail. For some reason it stripped all code from the file! It may be that it works in the general case but fails in some edge case in my code. Let me know if you observe the same. If it works for you, I'll try to create a reduced test case.

Also, there's no massive rush to fix :) using deeper namespaces such as "logger.log" is an acceptable workaround for now

thanks for testing the option, I'll try to replicate the bug and patch it as soon as I can :)

Update: I just tested and it does seem to work as you expected on a much simpler file. I'll try to narrow down it down to the offending code

I don't know what's going on, it seems to be working perfectly now. I tested and re-tested before posting this issue, but alas I must have made a mistake somewhere along the way :) I'll close this now, apologies for wasting your time.

Thanks for the great work by the way, just what I needed!

Glad you could find the solution.
You didn't waste my time at all, in fact I appreciate the feedback and to know that people use the tool :)