grunt-remove-logging-calls

    0.1.2 • Public • Published

    grunt-remove-logging-calls

    About

    This plugin removes/replaces all or any part of console logging statements from javascript code. It handles complex cases like console.log('hello: ' + foo(), bar()) because it's based on the syntax tree given by Esprima.

    Getting Started

    This plugin requires Grunt. Install this plugin with the command:

    npm install grunt-remove-logging-calls

    Once the plugin has been installed, enable it inside the Gruntfile:

    grunt.loadNpmTasks('grunt-remove-logging-calls');

    Finally, add some configuration.

    Configuration

    grunt.initConfig({
        // ...
     
        removeLoggingCalls: {
            // the files inside which you want to remove the console statements
      files: ['src/**/*.js'],
      options: {
      // an array of method names to remove
                methods: ['log', 'info', 'assert'], 
                
                // replacement strategy
                strategy: function(consoleStatement) {
                    // comments console calls statements
                    return '/* ' + consoleStatement + '*/';
     
                    // return ''; // to remove 
                },
                
                // when the logging statement is ended by a semicolon ';'
                // include it in the 'consoleStatement' given to the strategy
                removeSemicolonIfPossible: true
            
            }
        }
     
        // ...
    });

    Install

    npm i grunt-remove-logging-calls

    DownloadsWeekly Downloads

    42

    Version

    0.1.2

    License

    none

    Last publish

    Collaborators

    • jdborowy