JSLint with multiple files

走远了吗. 提交于 2019-11-27 07:34:18

问题


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?


回答1:


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.




回答2:


What's wrong with just running the command?

jslint .

will check all js files in the current directory and recurse down the tree.




回答3:


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.




回答4:


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  



回答5:


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




回答6:


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



回答7:


(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.



来源:https://stackoverflow.com/questions/7628009/jslint-with-multiple-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!