Question

If I've install JSLint through NPM globally, is there a way to disable certain rules either within the current scope of my application or globally on my system?

The main issue is the dangling underscore problem. I mean, the main place this comes up is in node.js when i use __dirname, but I am sure it will come up for underscorejs as well. I've ignored it with a jslint directive, but I think it is a little annoying to need to do that on every file I use underscore.

For that matter do I need to place 'use strict'; at the top of every single file?

Was it helpful?

Solution

Consider using a build tool for lint configuration and automation. When your project grows, you will need one anyway.

For node.js projects, I recommend using grunt. Install grunt into your project:

npm install grunt

Grunt has a built-in task for lint (https://github.com/cowboy/grunt/blob/master/docs/task_lint.md).

Now create a grunt.js file and configure linting there:

module.exports = function(grunt) {
  grunt.initConfig({
    lint: {
      all: [
        'app.js',
        'modules/*.js'
      ]
    },
    jshint: {
      options: {
        nomen: false
      }
    }
  });

  grunt.registerTask('default', 'lint');
};

Note how you can add easily multiple files and file patterns and apply options globally to all of these.

Now you can just run grunt by invoking:

grunt

Note that if you use jshint, nomen is off by default (http://www.jshint.com/options/).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top