JSLint 可以离线使用吗?

发布于 2024-07-18 08:11:03 字数 230 浏览 5 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(17

苍风燃霜 2024-07-25 08:11:03

如果您喜欢 JSLint Web 界面,您可以执行 File > 将页面另存为...另存为类型: 网页,完整(在 Firefox 中,在 Internet Explorer 中执行此操作可能略有不同)到本地文件夹。

我将名称更改为 jslint.htm,使其低于 8.3,且不带空格。

保存在本地后似乎可以工作。

三件事:

  1. 这可能违反他的许可证,尽管我保留版权完好无损并且不修改他的任何代码,并且从技术上讲,我的网络浏览器已经在我的本地硬盘上创建了他的网站的副本,所以我不确定我是否不管是否违法,我也不是律师,所以我会继续这样做,直到收到一封要求我停止的信。
  2. 该页面可能仍能以某种方式将您的代码发送到 Internet,尽管这种可能性非常渺茫。 也就是说,WSH 或 Rhino 版本可能比本地保存网页中的版本更容易将您提交的代码发送到互联网(如果您偏执的话)。
  3. 您将落后于道格拉斯所做的任何错误修复或更新。 但如果您不定期更新 WSH 或 Rhino 版本,同样的情况也适用。

If you like the JSLint web interface, you can do File > Save Page As... and Save 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:

  1. This may violate his license, although I leave the Copyright intact and don't modify any of his code, and technically my web browser already created a copy of his site on my local HD, so I'm not sure whether I'm in violation or not and I'm not a lawyer so I'll keep doing this until I get a letter telling me to stop.
  2. The page may somehow still be able to send your code to the Internet, although the chance of it being possible is very remote. That said, the WSH or Rhino versions could probably send the code you submit to the Internet easier than a version in a locally saved web page could (if you're paranoid).
  3. You'll get behind on any bug fixes or updates Douglas does. But the same thing applies to the WSH or Rhino versions if you don't update them regularly.
羁绊已千年 2024-07-25 08:11:03

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

不如归去 2024-07-25 08:11:03

是:

基本上,您只需要一个嵌入式 JavaScript 编译器即可运行 jslint.js。

Yes:

Basically, you just need an embedded JavaScript compiler to run jslint.js.

孤独陪着我 2024-07-25 08:11:03

还有另一个 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.

愚人国度 2024-07-25 08:11:03

如果您使用的是 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. :-)

触ぅ动初心 2024-07-25 08:11:03

YSlow for Firebug 内置了此功能

YSlow for Firebug has this feature built in

自由范儿 2024-07-25 08:11:03

如果您使用 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

看春风乍起 2024-07-25 08:11:03

我有一个工具,可以使用 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/

仅冇旳回忆 2024-07-25 08:11:03

尝试 Google Closure Linter。 它也比 JSLint 有更多的功能。

Try the Google Closure Linter. It has more features than JSLint, too.

香橙ぽ 2024-07-25 08:11:03

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

浪荡不羁 2024-07-25 08:11:03

由于 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.

故事和酒 2024-07-25 08:11:03

我有 带有 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.

萝莉病 2024-07-25 08:11:03

如果您使用 TextMate,则 JSLintMate 捆绑包具有简单的界面,支持 JSLint 和 JSHint,并允许您以各种方式设置自定义选项(例如,每个项目的配置文件、所有项目的全局选项)。

JSLintMate 屏幕截图

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

JSLintMate screenshots

栀梦 2024-07-25 08:11:03

如果您已经使用 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

甜嗑 2024-07-25 08:11:03

您也可以直接下载源代码,而不是使用浏览器下载。 这样做的优点是您可以使用版本控制系统更新它们,并阅读带注释的源代码。

git clone https://github.com/douglascrockford/JSLint.git

这为您提供了 HTML 和 JS 源文件,但您不能按原样使用它们。 按照README中的构建过程进行操作。 简而言之,您需要 git clone Douglas Crockford 的另外两个 JS 项目,然后将所有三个 git 存储库中的一些 JS 文件连接(并最小化)到 web_jslint.js 中。

我使用 YUI Compressor 这样做:

cat ../ADsafe/adsafe.js ../JSON-js/json2.js intercept.js jslint.js > /tmp/web_jslint.uncomp.js
java -jar ../../yuicompressor-2.4.7.jar /tmp/web_jslint.uncomp.js > web_jslint.js

然后用浏览器打开 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.

git clone https://github.com/douglascrockford/JSLint.git

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 to git clone two other JS projects of Douglas Crockford, then concatenate (and minimise) some JS files from all three git repositories into web_jslint.js.

I did it like this, with the YUI Compressor:

cat ../ADsafe/adsafe.js ../JSON-js/json2.js intercept.js jslint.js > /tmp/web_jslint.uncomp.js
java -jar ../../yuicompressor-2.4.7.jar /tmp/web_jslint.uncomp.js > web_jslint.js

Then open jslint.html with your browser.

走走停停 2024-07-25 08:11:03

在 JSLint.com 上重新创建 Crockford 的内容非常容易。 JSLint.com 的 .js 在线版本 是几个文件的缩小组合,其中包括一些开销不太明白,比如那个ADSAFE东西。 让我们将其简化为最简单的案例包装器。

为 JSLint 构建您自己的 HTML 包装器:

以下是查找 jslint.js 的网页代码(当前可以找到最新版本的 JSLint 在 github 中作为原始文本)在同一目录中,并以与 JSLint.com 现在类似的方式启动。

<html>
    <head>
        <script src="jslint.js"></script>

        <script>
            function jslintalizeMe()
            {
                var i, divOut, errs, errsMsg = "";

                divOut = document.getElementById("errors");
                divOut.innerHTML = "";

                if (!JSLINT(document.forms[0].elements[0].value))
                {
                    errs = JSLINT.errors;
                    for (i=0; i < errs.length; i++)
                    {
                        err = errs[i];
                        if (null !== err)
                        {
                            if (undefined !== err.id)
                            {
                                errsMsg += "Error: " 
                                + err.code 
                                + " -- line " 
                                + err.line 
                                + " char " 
                                + err.character + "<br />"
                                + "    " 
                                + err.evidence + "<br />"
                                + "    " +
                                 err.reason + "<br /><br />\n";
                            }
                            else
                            {
                                errsMsg += err.reason;
                            }
                        }
                    }
                    divOut.innerHTML = errsMsg;
                }
            }
        </script>

    </head>

    <body>

        <form>
            <textarea rows="24" cols="80"
                placeholder="// Paste quality code here"></textarea>
            <br />
            <button onclick="jslintalizeMe();return false;">JSLint</button>
        </form>

        <div id="errors"></div>
    </body>
</html>

^ 来自我的一篇旧博客文章< /a>.

众所周知,读者应该让 GUI 变得更加粘稠,但是这个报告以及 JSLint 站点现在所做的都是如此。

包装器代码的示例 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.

<html>
    <head>
        <script src="jslint.js"></script>

        <script>
            function jslintalizeMe()
            {
                var i, divOut, errs, errsMsg = "";

                divOut = document.getElementById("errors");
                divOut.innerHTML = "";

                if (!JSLINT(document.forms[0].elements[0].value))
                {
                    errs = JSLINT.errors;
                    for (i=0; i < errs.length; i++)
                    {
                        err = errs[i];
                        if (null !== err)
                        {
                            if (undefined !== err.id)
                            {
                                errsMsg += "Error: " 
                                + err.code 
                                + " -- line " 
                                + err.line 
                                + " char " 
                                + err.character + "<br />"
                                + "    " 
                                + err.evidence + "<br />"
                                + "    " +
                                 err.reason + "<br /><br />\n";
                            }
                            else
                            {
                                errsMsg += err.reason;
                            }
                        }
                    }
                    divOut.innerHTML = errsMsg;
                }
            }
        </script>

    </head>

    <body>

        <form>
            <textarea rows="24" cols="80"
                placeholder="// Paste quality code here"></textarea>
            <br />
            <button onclick="jslintalizeMe();return false;">JSLint</button>
        </form>

        <div id="errors"></div>
    </body>
</html>

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

sample JSLint output from wrapper code

半步萧音过轻尘 2024-07-25 08:11:03

有一个很棒的雅虎小部件:

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.

alt text
(source: googlecode.com)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文