javascript 带有多个文件的 JSLint
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7628009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSLint with multiple files
提问by Randomblue
JSLint works fine for just one JavaScript file. Recently, I've started breaking my program into several pieces.
JSLint 仅适用于一个 JavaScript 文件。最近,我开始将我的程序分成几部分。
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?
我不想每次使用 JSLint 检查我的代码时都将这些片段串起来。使用 JSLint 处理多个文件的标准解决方案是什么?
采纳答案by Nery Jr
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:
有一个版本的 JSLint (node-JSLint)(命令行)允许您一次检查多个文件。按照 GitHub 上的下载链接:
https://github.com/reid/node-jslint
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.
注意:此应用程序是为 NodeJS 开发的。
回答by Daniel Scott
What's wrong with just running the command?
只运行命令有什么问题?
jslint .
will check all js files in the current directory and recurse down the tree.
将检查当前目录中的所有 js 文件并向下递归树。
回答by Ross Patterson
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 文件运行 JSLint,而不仅仅是针对 JavaScript 文件(这是有道理的,因为有<SCRIPT>
标签)。并且 JSLint 对外部脚本很聪明——如果它可以定位它们,它将作为处理的一部分加载它们。所以尝试这样的事情:
<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.
在其上运行 JSLint,而不是在您的每个文件上运行。
回答by Jeroen K
The command line app JavaScript Lint (http://www.javascriptlint.com/) works with multiple files and can recurse directories. E.g.
命令行应用程序 JavaScript Lint ( http://www.javascriptlint.com/) 可以处理多个文件并且可以递归目录。例如
%JSLPATH%\jsl.exe +recurse -process src\scripts\*.js
回答by chase.martin
If you don't need a running count of errors, open terminal (in OS X) and paste this:
如果您不需要运行错误计数,请打开终端(在 OS X 中)并粘贴以下内容:
for i in $(find . -iname "*.js"); do jshint $i; done
回答by deviousdodo
You can also have a look here: https://github.com/mikewest/jslint-utilsIt 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
您也可以在这里查看:https: //github.com/mikewest/jslint-utils它应该适用于 Rhino 或 NodeJS。您还可以传递多个文件进行检查。注意:如果您有一个不将多个文件作为参数的命令行脚本,您总是可以执行以下操作:ls public/javascripts/**/*.js | jslint
回答by Ben
(This Is taken from this linkand formatted)
(这是从这个链接中获取并格式化的)
Rhinois 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.
Rhino是一个完全用 Java 编写的 Javascript 引擎。它可用于在带有 Java 解释器的系统上从命令行运行 JSLint。
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.
文件 jslint.js 可以由 Rhino 运行。它将从文件中读取 JavaScript 程序。如果没有问题,它会安静地终止。如果有问题,它会输出一条消息。JSLint 的 WSH 版本不生成函数报告。
One way to run JSLint is with this command:
运行 JSLint 的一种方法是使用以下命令:
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.
它运行java,它加载并运行Rhino,它加载并运行jslint.js,它将读取文件myprogram.js 并在找到时报告错误。
Download jslint.js.
下载 jslint.js。