Reputation: 116373
JSLint works fine for just one JavaScript file. Recently, I've started breaking my program into several pieces.
I don't want to be stringing the pieces each time I use JSLint to check my code. What is the standard solution to deal with multiples files with JSLint?
Upvotes: 26
Views: 14559
Reputation: 7961
What's wrong with just running the command?
jslint .
will check all js files in the current directory and recurse down the tree.
Upvotes: 15
Reputation: 71
If you don't need a running count of errors, open terminal (in OS X) and paste this:
for i in $(find . -iname "*.js"); do jshint $i; done
Upvotes: 1
Reputation: 4009
There is a version of JSLint (node-JSLint) (command line) that allows you to check multiple files at once. Follow link for download at GitHub:
https://github.com/reid/node-jslint
The following examples of calling via the command line:
JSLint app.js
JSLint lib / lib worker.js / server.js # Multiple files
JSLint - white - onevar - regexp app.js JSLint # All options supported
JSLint - bitwise false app.js # Defaults to true, but You Can Specify false
JSLint - goodparts - # undef false app.js The Good Parts, except undef
JSLint-gp app.js # Shorthand for - goodparts:-gp
find . -name "*.js" -print0 | xargs -0 jslint # JSLint JSLint your Entire Project
Note: This application was developed to NodeJS.
Upvotes: 25
Reputation: 10448
The command line app JavaScript Lint (http://www.javascriptlint.com/) works with multiple files and can recurse directories. E.g.
%JSLPATH%\jsl.exe +recurse -process src\scripts\*.js
Upvotes: 2
Reputation: 9569
You can run JSLint against HTML files, not just against JavaScript files (which makes sense, because of the <SCRIPT>
tag). And JSLint is smart about external scripts - if it can locate them, it will load them as part of the processing. So try something like this:
<html>
<head>
<script src="file1.js"></script>
<script src="file2.js"></script>
...
<script>mainRoutine();</script>
</head>
</html>
Run JSLint on that, instead of on each of your files.
Upvotes: 2
Reputation: 10298
(This Is taken from this link and formatted)
Rhino is a Javascript engine that is written entirely in Java. It can be used to run JSLint from the command line on systems with Java interpreters.
The file jslint.js can be run by Rhino. It will read a JavaScript program from a file. If there are no problems, it terminates quietly. If there is a problem, it outputs a message. The WSH edition of JSLint does not produce a Function Report.
One way to run JSLint is with this command:
C:\> java org.mozilla.javascript.tools.shell.Main jslint.js myprogram.js
It runs java which loads and runs Rhino which loads and runs jslint.js, which will read the file myprogram.js and report an error if found.
Download jslint.js.
Upvotes: 0
Reputation: 9172
You can also have a look here: https://github.com/mikewest/jslint-utils
It should work with either Rhino or NodeJS. You can also pass multiple files for checking.
NB: if you have a command line script which doesn't take multiple files as arguments, you can always do something like: ls public/javascripts/**/*.js | jslint
Upvotes: 1