AsTeR
AsTeR

Reputation: 7521

JSLint : how to use it?

I've understood that JSLint is a great tool for JavaScript development but I've some dark points in my global comprehension of this.

  1. How to use it inside my development environment ? In other words how and when do you run JSLint against your code ? I've seen the Aptana integration but it seems that it doesn't take into account statements like :

    /* jslint nomen: false */
    
  2. How to work correctly in a client side development environment ? I want JSLint to feel good when parsing calls including objects like "console", "$" or "JQuery".

  3. How to use it on a whole project with multiple files (with no import statement inside of them) ?

I've read to much statement suggesting to copy paste on jslint to sleep correctly, so any answer consisting of configuring the online JSLint form would be considered as irrelevant.

Upvotes: 3

Views: 7775

Answers (3)

Ibu
Ibu

Reputation: 43810

Some one came up with a solution to run it automatically on your project using node.js:

Automating JSLint Validation

Upvotes: 1

AsTeR
AsTeR

Reputation: 7521

I'm sorry to write this answer which is not really one. The best solution I've found is to use JSHint which is a concurrent to JSLint with some nice extra features :

  • Installation is made easy through NPM with command like (also works for JSLint), NPM is required :

    npm install -g jshint
    
  • Execution is made easy against a lot of file (doesn't work for JSLint) :

    jshint mycodedirectory
    
  • Configuration is possible through the --config options, config files look like :

    {
      "curly":true,
      "eqeqeq": true,
      "immed": true,
      "bitwise": true,
      "newcap": true,
      "noempty": true,
      "unused": true,
      "camelcase":true,
      "undef": true,
      "strict": true,
      "trailing": true,
      "maxparams": 7,
      "maxdepth": 5,
      "maxstatements": 50,
      "maxcomplexity": 13
    }
    

This solution works for both browser and server code, it's IDE and OS independent, it can be easily integrated in continuous integration process.

Upvotes: 4

feklee
feklee

Reputation: 7695

I use (a slightly modified) JSLINT for WSH on Emacs/WinXP. It highlights problematic code right while I am typing:

  • This is of great help not only to enforce the configured coding style, but also to find many JavaScript syntax errors before executing code.

  • It does respect statements such as /* jslint nomen: false */.

  • As you are asking concerning linting code that runs in a browser environment with jQuery, simply use standard JSLint options:

    /*jslint browser: true */
    /*global $ */
    

Just be sure to replace the included JSLint code with the latest version.

Upvotes: 0

Related Questions