Linux 如何在 Ubuntu 上安装 JSLint?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8863888/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:04:33  来源:igfitidea点击:

How do I install JSLint on Ubuntu?

javascriptlinuxvimubuntujslint

提问by

How do I install JSLint on Ubuntu?

如何在 Ubuntu 上安装 JSLint?

I downloaded the source jsl-0.3.0-src.tar.gzfrom http://www.javascriptlint.com/download.htmand then extracted it to a dir called jsl-0.3.0on my Desktop. I then moved it to /usr/local/binwhich I have read is my PATH. I also want to mention that I have Rhino 1.7installed already.

我下载的源jsl-0.3.0-src.tar.gzhttp://www.javascriptlint.com/download.htm,然后将其解压缩到一个名为dir的jsl-0.3.0在我的桌面上。然后我将它移到/usr/local/bin读过的是我的 PATH。我还想提一下,我已经Rhino 1.7安装了。

When I try to run jslfrom terminal I got the following message:

当我尝试jsl从终端运行时,我收到以下消息:

No command 'jsl' found, did you mean:
 Command 'jls' from package 'sleuthkit' (universe)
 Command 'js' from package 'rhino' (main)
 Command 'sl' from package 'sl' (universe)
 Command 'fsl' from package 'fsl' (multiverse)
jsl: command not found

So I how do I properly install JSLint?

那么我该如何正确安装 JSLint?

采纳答案by romainl

Hereare the instructions I followed to have jslint working on Ubuntu 10.10/Vim 7.3 (and Mac OS X).

以下是我在 Ubuntu 10.10/Vim 7.3(和 Mac OS X)上运行 jslint 时遵循的说明。

EDIT

编辑

So, I've just spotted a mistake in the given link. Here are the correct steps (assuming you have already downloaded and unpacked the archive to your desktop:

所以,我刚刚在给定的链接中发现了一个错误。以下是正确的步骤(假设您已经将存档下载并解压到桌面:

$ cd /path/to/jsl-0.3.0/src
$ make -f Makefile.ref
$ cp Linux_All_DBG.OBJ/jsl /usr/local/bin/jsl

At that point you can open a new terminal window and type $ jslto display a quick help or invoke it from Vim or directly on a file in the terminal.

此时,您可以打开一个新的终端窗口并键入$ jsl以显示快速帮助或从 Vim 或直接在终端中的文件上调用它。

END EDIT

结束编辑

  • /usr/local/binis not your "PATH", it's only one of the many directories that can be part your PATHenvironment variable. $ echo $PATHwill tell you what these directories are and thus where you can put the jslexecutable. You can also put it in another place and add an alias to your .bashrc.

  • Why do you expect to be able to run jslintfrom rhino?

  • /usr/local/bin不是您的“路径”,它只是可以成为您的PATH环境变量的一部分的众多目录之一。$ echo $PATH会告诉你这些目录是什么,因此你可以把jsl可执行文件放在哪里。您也可以将它放在另一个地方并为您的.bashrc.

  • 你为什么期望能够jslintrhino

回答by Drew Chapin

You said you just copied the source to /usr/local/bin. You need to compile it. Follow the build instructions in the README.html

您说您刚刚将源代码复制到 /usr/local/bin。你需要编译它。按照 README.html 中的构建说明进行操作

Unix

  • Use 'gmake -f Makefile.ref' to build. To compile optimized code, pass BUILD_OPT=1 on the gmake command line or preset it in the environment or Makefile.ref. NOTE: Do not attempt to use Makefile to build the standalone JavaScript engine. This file is used only for building the JS-engine in the Mozilla browser.
  • Each platform on which JS is built must have a *.mk configuration file in the js/src/config directory. The configuration file specifies the compiler/linker to be used and allows for customization of command-line options. To date, the build system has been tested on Solaris, AIX, HP/UX, OSF, IRIX, x86 Linux and Windows NT.
  • Most platforms will work with either the vendor compiler or gcc. (Except that HP builds only work using the native compiler. gcc won't link correctly with shared libraries on that platform. If someone knows a way to fix this, let us know.)
  • If you define JS_LIVECONNECT, gmake will descend into the liveconnect directory and build LiveConnect after building the JS engine.
  • To build a binary drop (a zip'ed up file of headers, libraries, binaries), check out mozilla/config and mozilla/nsprpub/config. Use 'gmake -f Makefile.ref nsinstall-target all export ship'

Unix

  • 使用 'gmake -f Makefile.ref' 来构建。要编译优化代码,请在 gmake 命令行上传递 BUILD_OPT=1 或在环境或 Makefile.ref 中预设它。注意:不要尝试使用 Makefile 来构建独立的 JavaScript 引擎。该文件仅用于在 Mozilla 浏览器中构建 JS 引擎。
  • 每个构建 JS 的平台都必须在 js/src/config 目录下有一个 *.mk 配置文件。配置文件指定要使用的编译器/链接器并允许自定义命令行选项。迄今为止,构建系统已经在 Solaris、AIX、HP/UX、OSF、IRIX、x86 Linux 和 Windows NT 上进行了测试。
  • 大多数平台都可以使用供应商编译器或 gcc。(除了 HP 构建仅使用本机编译器工作。gcc 不会与该平台上的共享库正确链接。如果有人知道解决此问题的方法,请告诉我们。)
  • 如果定义了 JS_LIVECONNECT,gmake 会在构建 JS 引擎后进入 liveconnect 目录并构建 LiveConnect。
  • 要构建二进制文件(头文件、库、二进制文件的压缩文件),请查看 mozilla/config 和 mozilla/nsprpub/config。使用'gmake -f Makefile.ref nsinstall-target all export ship'

As for your question about the difference. It says on the download page that one is written in JavaScript itself.

至于你关于区别的问题。它在下载页面上说一个是用 JavaScript 本身编写的。

We all stand on the shoulders of giants. I would like to especially acknowledge Douglas > Crockford's work on JSLint. This lint is itself written in JavaScript and is an interesting and rather sophisticated script. Crockford's ideas about good coding practices served as a springboard for many of these lint rules.

我们都站在巨人的肩膀上。我要特别感谢 Douglas > Crockford 在 JSLint 上的工作。这个 lint 本身是用 JavaScript 编写的,是一个有趣且相当复杂的脚本。Crockford 关于良好编码实践的想法是许多这些 lint 规则的跳板。

回答by paulsm4

Look at your "jsl-0.3.0/src/README.html" file. This says:

查看您的“jsl-0.3.0/src/README.html”文件。这说:

1) You have a "source package". You need to "build" it (with a C compiler), then install your build.

1)你有一个“源包”。您需要“构建”它(使用 C 编译器),然后安装您的构建。

2) This is more than just JSLint. It's an entire Javascript engine. Per the README:

2) 这不仅仅是 JSLint。它是一个完整的 Javascript 引擎。根据自述文件:

This is the README file for the JavaScript Reference (JSRef, now better known as SpiderMonkey) implementation. It consists of build conventions and instructions, source code conventions, a design walk-through, and a brief file-by-file description of the source.

JSRef builds a library or DLL containing the JavaScript runtime (compiler, interpreter, decompiler, garbage collector, atom manager, standard classes). It then compiles a small "shell" program and links that with the library to make an interpreter that can be used interactively and with test .js files to run scripts. The code has no dependencies on the rest of the Mozilla codebase.

这是 JavaScript 参考(JSRef,现在更广为人知的名称为 SpiderMonkey)实现的 README 文件。它由构建约定和说明、源代码约定、设计演练和源文件的简要文件描述组成。

JSRef 构建一个包含 JavaScript 运行时(编译器、解释器、反编译器、垃圾收集器、原子管理器、标准类)的库或 DLL。然后它编译一个小的“shell”程序并将它与库链接以制作一个可以交互使用的解释器,并与测试 .js 文件一起运行脚本。该代码不依赖于 Mozilla 代码库的其余部分。

3) Here is Douglas Crockford's original JSLint page:

3) 这是 Douglas Crockford 的原始 JSLint 页面:

http://www.jslint.com/

http://www.jslint.com/

4) And here is a a good example of how you might use JSLint locally, on your own PC:

4) 这里有一个很好的例子,说明如何在自己的 PC 上本地使用 JSLint:

http://code.google.com/p/js-ria-tools/wiki/JSLint

http://code.google.com/p/js-ria-tools/wiki/JSLint

5) You say you already have Rhino - good. In Google, you'll find many obsolete links to www.jslint.com/rhino. Here's why - along with links to current Rhino-related info:

5) 你说你已经有了 Rhino - 很好。在 Google 中,您会发现许多指向 www.jslint.com/rhino 的过时链接。这就是原因 - 以及当前 Rhino 相关信息的链接:

http://hustoknow.blogspot.com/2011/02/jslint-and-rhino-support.html

http://hustoknow.blogspot.com/2011/02/jslint-and-rhino-support.html

'Hope that helps!

'希望有帮助!

回答by gmunkhbaatarmn

How to install JSLint on Ubuntu:

如何在 Ubuntu 上安装 JSLint:

  1. Install nodejs(includes npm, the Node Package Manager):

    sudo apt-get install nodejs
    
  2. Install node-jslint. either globally:

    sudo npm install -g jslint
    

    or locally, and include it in $PATH:

    npm install jslint
    

    and add this line to your.bashrc(adjust version number as appropriate)

    alias jslint='~/.npm/jslint/0.1.8/package/bin/jslint.js'
    
  1. 安装nodejs(包括npm,节点包管理器):

    sudo apt-get install nodejs
    
  2. 安装 node-jslint。要么在全球范围内:

    sudo npm install -g jslint
    

    或本地,并将其包含在$PATH

    npm install jslint
    

    并将此行添加到您的.bashrc(根据需要调整版本号)

    alias jslint='~/.npm/jslint/0.1.8/package/bin/jslint.js'