JSLint 可以离线使用吗?
我想使用 JSLint,但我对可以访问我未经过滤的源代码的工具持谨慎态度。 是否有离线版本或者是否有其他类似的工具可以对 JavaScript 离线进行“lint
错误检查”?
编辑:一个带有 GUI 的,可以向您显示样式化的错误列表,而不是命令行界面?
I'd like to use JSLint, but I am wary of tools that have access to my unfiltered source code. Is there an offline version or is there another similar tool that does "lint
error checking" for JavaScript offline?
Edit: One with a GUI and that shows you a styled list of errors, instead of a command line interface?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
如果您喜欢 JSLint Web 界面,您可以执行
File
>将页面另存为...
和另存为类型:
网页,完整
(在 Firefox 中,在 Internet Explorer 中执行此操作可能略有不同)到本地文件夹。我将名称更改为
jslint.htm
,使其低于 8.3,且不带空格。保存在本地后似乎可以工作。
三件事:
If you like the JSLint web interface, you can do
File
>Save Page As...
andSave as type:
Web Page, complete
(in Firefox, doing it in Internet Explorer may be slightly different) to a local folder.I change the name to
jslint.htm
to get it under 8.3 with no spaces.It seems to work when saved locally.
Three things:
JSLint 可以使用 WSH 或 Rhino 离线运行:
http://www.jslint.com/lint。 html#try
编辑:自从提出这个问题以来的两年里,JSLint 已经放弃了对 Rhino 和 WSH 的支持。 我鼓励任何对 linting 代码感兴趣的人也查看 JSHint。 它是 JSLint 的一个分支,旨在比原始版本更加灵活,但也恰好支持 Node、Rhino 和 WSH(当然,除了浏览器之外)。
JSLint can be run offline with either WSH or Rhino:
http://www.jslint.com/lint.html#try
Edit: In the two years since this question was asked, JSLint has dropped support for Rhino and WSH. I encourage anyone interested in linting their code to also check out JSHint. It's a fork of JSLint which aims to be more flexible than the original, but also happens to support Node, Rhino, and WSH (in addition to browsers, of course).
是:
基本上,您只需要一个嵌入式 JavaScript 编译器即可运行 jslint.js。
Yes:
Basically, you just need an embedded JavaScript compiler to run
jslint.js
.还有另一个 JS Linter,名为 JavaScript Lint,它有在线版本和可下载的命令行版本。 我一直使用可下载版本。 我一直在考虑将它作为钩子的一部分集成到 SVN 中。 与 JSLint 相比,我更喜欢它,因为它有更多选项,并且似乎可以检测到更多东西。 它可以配置为将某些标识符视为预定义的工具包等,这允许它检查未定义变量的使用情况,我很确定 JSLint 无法做到这一点。
There's another JS Linter, called JavaScript Lint, that has both online and downloadable command line versions. I use the downloadable version all time. I've been thinking about integrating it into SVN as part of a hook. I like it better than JSLint because it has more options and seems to detect more things. It can be configured to treat certain identifiers as predefined, for toolkits and the like, which allows it to check for usage of undefined variables, which I'm pretty sure JSLint can't do.
如果您使用的是 Java 环境,您可能会发现我的 jslint4java 工具很有用。 它有命令行变体,也可以集成到 Ant 脚本中。 没有 GUI,因为我对这些很烂。 :-)
If you're in a Java environment, you may find my jslint4java tool useful. It comes in a command line variant, and can also be integrated into an ant script. No GUI, because I suck badly at those. :-)
YSlow for Firebug 内置了此功能
YSlow for Firebug has this feature built in
如果您使用 TextMate,我已经制作了一个运行 JSLint 并在图形窗口中显示输出的包。 一切都是独立的; 不需要安装任何其他东西即可使用它:
在 GitHub 上查看 JSLint.tmbundle
If you use TextMate, I've made a bundle that runs JSLint and displays the output in a graphical window. It's all self-contained; nothing else needs to be installed to use it:
View JSLint.tmbundle at GitHub
我有一个工具,可以使用 SpiderMonkey shell 从命令行运行 JSLint或Rhino。 它还包含一个 Vim 插件,允许您按一个按钮自动编辑文件时突出显示任何问题行:
http://github.com/hallettj/jslint .vim/
I have a tool for running JSLint from the command line with either the SpiderMonkey shell or Rhino. It also includes a plugin for Vim that allows you to press a button to automatically highlight any problem lines while editing a file:
http://github.com/hallettj/jslint.vim/
尝试 Google Closure Linter。 它也比 JSLint 有更多的功能。
Try the Google Closure Linter. It has more features than JSLint, too.
Cory Bennet 有一篇关于命令行 JSLint 的好帖子。 您的大部分设置将让 SpiderMonkey 正常工作。 如果你运行的是 Linux,那还不错; 如果您使用的是 Windows 和 Cygwin,那就更难了。 这里有一些与Rhino运行时的更多讨论和比较。
更新:2013.11 - 如果您在命令行上使用node.js(为什么不呢?)您可以同时运行 jslint 和新的 eslint。 [注意:我已经向 eshint 贡献了错误报告和测试代码。] 这两个都比我上面的更容易设置......
Cory Bennet has a good post on command-line JSLint. Much of your setup will be getting SpiderMonkey working. Not so bad if you're running Linux; a wee harder if you're using Windows and Cygwin. And here are some more discussion and comparison with Rhino run-times.
UPDATE: 2013.11 - if you're using node.js on the commandline (and why wouldn't you?) you can run both jslint and the new eslint. [NB: I have contributed bug-reports and test-code to eshint.] Both of these are way easier to setup than what I have above....
由于 JSLint 本身是用 JavaScript 编写的,因此您可以通过在本地复制 HTML 和引用的 JavaScript 文件来离线运行它。 IE7 的“另存为...”“网页,完整”功能可以很好地做到这一点。
Since JSLint itself is written in JavaScript, you can run it offline by copying the HTML and referenced JavaScript files locally. IE7's "Save As..." "webpage, complete" feature does this just fine.
我有 带有 Node.js 验证代码的 JSLint我的部署脚本,以确保我不会意外推送可能破坏我的网站的代码。 它可以节省以后处理客户支持问题的大量时间。
I have JSLint with Node.js validating code in my deploy scripts to ensure I don't accidentally push code that could break my site. It can save a lot of time handling customer support issues later.
如果您使用 TextMate,则 JSLintMate 捆绑包具有简单的界面,支持 JSLint 和 JSHint,并允许您以各种方式设置自定义选项(例如,每个项目的配置文件、所有项目的全局选项)。
If you're using TextMate, the JSLintMate bundle has a simple interface, supports both JSLint and JSHint, and lets you set custom options in various ways (e.g., a config file per project, global options across all projects).
如果您已经使用 ruby gems,那么您可以通过一个命令安装 jslint gem:
http://rubygems.org/gems/jslint
If you already use ruby gems then you may install jslint gem in one command :
http://rubygems.org/gems/jslint
您也可以直接下载源代码,而不是使用浏览器下载。 这样做的优点是您可以使用版本控制系统更新它们,并阅读带注释的源代码。
这为您提供了 HTML 和 JS 源文件,但您不能按原样使用它们。 按照
README
中的构建过程进行操作。 简而言之,您需要 git clone Douglas Crockford 的另外两个 JS 项目,然后将所有三个 git 存储库中的一些 JS 文件连接(并最小化)到web_jslint.js
中。我使用 YUI Compressor 这样做:
然后用浏览器打开 jslint.html。
Instead of downloading with a browser, you can also directly download the sources. This has the advantage that you can update them with the versioning system, and read the commented source code.
This gives you HTML and JS source files, but you cannot use them as they are. Follow the build process in
README
. In a nutshell, you need togit clone
two other JS projects of Douglas Crockford, then concatenate (and minimise) some JS files from all three git repositories intoweb_jslint.js
.I did it like this, with the YUI Compressor:
Then open
jslint.html
with your browser.在 JSLint.com 上重新创建 Crockford 的内容非常容易。 JSLint.com 的 .js 在线版本 是几个文件的缩小组合,其中包括一些开销不太明白,比如那个
ADSAFE
东西。 让我们将其简化为最简单的案例包装器。为 JSLint 构建您自己的 HTML 包装器:
以下是查找 jslint.js 的网页代码(当前可以找到最新版本的 JSLint 在 github 中作为原始文本)在同一目录中,并以与 JSLint.com 现在类似的方式启动。
^ 来自我的一篇旧博客文章< /a>.
众所周知,读者应该让 GUI 变得更加粘稠,但是这个报告以及 JSLint 站点现在所做的都是如此。
It's pretty easy to recreate what Crockford has on JSLint.com. JSLint.com's online version of the .js is a minified conglomeration of a few files that includes some overhead I don't quite understand, like that
ADSAFE
stuff. Let's strip it down to a simplest case wrapper instead.Building your own HTML wrapper for JSLint:
Here's the code to a web page that'll look for jslint.js (the latest version of JSLint can currently be found in github here as raw text) in the same directory and fire away in a similar fashion as JSLint.com does now.
^ From an old blog post of mine.
It's up to the proverbial reader to make the GUI more gooey, but this reports as well as the JSLint site does now.
有一个很棒的雅虎小部件:
http://ajaxian.com/archives/jslint-multi
它是开源的,如果您偏执,您可以审核代码。
(来源:googlecode.com)
There is a great Yahoo Widget:
http://ajaxian.com/archives/jslint-multi
It is open source, if you are paranoid you can audit the code.
(source: googlecode.com)