简体   繁体   English

如何在Linux Mint 17 Cinnamon的SublimeLinter中启用JSHint?

[英]How to enable JSHint in SublimeLinter in Linux Mint 17 Cinnamon?

Desired Behaviour 期望的行为

Linting of .js files with Sublime Text 3. 使用Sublime Text 3激活.js文件。

Actual Behaviour 实际行为

No linting is taking place. 没有掉毛。

For example the following shows no errors: 例如,以下显示没有错误:

var x = "" 

Steps To Reproduce 重现步骤

Environment 环境

  • Linux Mint 17 Cinnamon Linux Mint 17 Cinnamon
  • Sublime Text Build 3065 Sublime Text Build 3065
  • Tools > SublimeLinter > Lint Mode > "Background"
  • Tools > SublimeLinter > Mark Style > "Fill"

In Sublime Text (to install SublimeLinter and JSHint plugin) 在Sublime Text中(安装SublimeLinter和JSHint插件)

  • ctrl+shift+p CTRL + SHIFT + P
  • Package Control: Install Package 包控制:安装包
  • Install SublimeLinter 安装SublimeLinter
  • Install SublimeLinter jshint plugin 安装SublimeLinter jshint插件

At Command Line 在命令行

  • Install node.js, npm and jshint with: 使用以下命令安装node.js,npm和jshint:

    sudo apt-get install nodejs npm
    sudo npm install -g jshint

Quit and restart Sublime Text. 退出并重新启动Sublime Text。

Troubleshooting 故障排除

At Command Line: 在命令行:

hash -r
which jshint

returns

/usr/local/bin/jshint

I also tried this solution ( https://stackoverflow.com/a/21203179/1063287 ) involving manuualy changing the path in Preferences > Package Settings > SublimeLinter > "Settings - User" and restarted Sublime Text but there was no change: 我也试过这个解决方案( https://stackoverflow.com/a/21203179/1063287 ),涉及手动更改Preferences > Package Settings > SublimeLinter > "Settings - User"的路径并重新启动Sublime Text但没有更改:

"paths": {
    "linux": ["/usr/local/bin/jshint"],
    "osx": [],
    "windows": []
},

Documentation Reference 文档参考

On how to install jshint plugin: 关于如何安装jshint插件:

https://github.com/SublimeLinter/SublimeLinter-jshint https://github.com/SublimeLinter/SublimeLinter-jshint

UPDATE UPDATE

I just ran this in command line - the results may help to troubleshoot: 我只是在命令行中运行它 - 结果可能有助于排除故障:

jshint --version
/usr/bin/env: node: No such file or directory

This also comes up in Sublime Text Console: 这也出现在Sublime文本控制台中:

SublimeLinter: WARNING: no jshint version could be extracted from:
/usr/bin/env: node: No such file or directory

This seems to make JSHint work - but if anyone could confirm that this is the best approach that would be great: 这似乎使JSHint工作 - 但如果有人能够确认这是最好的方法:

https://github.com/joyent/node/issues/3911#issuecomment-8956154 https://github.com/joyent/node/issues/3911#issuecomment-8956154

I've found this is often a misnaming error, if you install from a package manager you bin may be called nodejs so you just need to symlink it like so "ln -s /usr/bin/nodejs /usr/bin/node" 我发现这通常是一个错误的错误,如果你从包管理器安装你的bin可能被称为nodejs所以你只需要符号链接它就像这样“ln -s / usr / bin / nodejs / usr / bin / node”

Note: Using this solution, no adjustments need to be made to paths in Preferences > Package Settings > SublimeLinter > "Settings - User" . 注意:使用此解决方案,不需要在Preferences > Package Settings > SublimeLinter > "Settings - User"对路径进行调整。

The solution that you (the OP) provided will work, but I'll give some explanation, show you how to validate the issue, provide some other options and maybe a bit of best practice (which is what you were seeking when you posted the answer. 您(OP)提供的解决方案将起作用,但我会给出一些解释,告诉您如何验证问题,提供一些其他选项以及一些最佳实践(这是您在发布时所寻求的内容)回答。

The Problem 问题

The problem is that the jshint executable is looking to run using the "node" interpreter, and the system can't find an executable that matches the name "node" in your path. 问题是jshint可执行文件正在寻找使用“node”解释器运行,并且系统找不到与路径中的名称“node”匹配的可执行文件。 (I believe that "node" used to be the standard name previously, but now it's generally referred to using "nodejs" because there was concern about the "node" name being to generic and conflicting with other executables.) (我相信以前“节点”曾经是标准名称,但现在它通常被称为“nodejs”,因为担心“节点”名称是泛型的并且与其他可执行文件冲突。)

Here's how you can see what is going on... At the terminal, do the following: - find the path to the jshint executable by executing "which jshint" (you should find it in "/usr/local/bin") - view the contents by issuing "cat /usr/local/bin". 以下是如何查看正在发生的事情...在终端上,执行以下操作: - 通过执行“which jshint”找到jshint可执行文件的路径(您应该在“/ usr / local / bin”中找到它) - 通过发出“cat / usr / local / bin”来查看内容。 You'll see that the first line specifies the interpreter to use, which is "node" (not "nodejs"). 您将看到第一行指定要使用的解释器,即“node”(不是“nodejs”)。

The Cause 原因

Currently, when you install Node.js using the package manager, the Debian package called "nodejs" creates the executable "/usr/bin/nodejs". 目前,当您使用包管理器安装Node.js时,名为“nodejs”的Debian包会创建可执行文件“/ usr / bin / nodejs”。 Therefore, any other executables that specify the "node" executable don't find one and won't work. 因此,指定“节点”可执行文件的任何其他可执行文件都找不到,并且不起作用。

The Fix 修复

You have many options: 你有很多选择:

  1. The quickest and easiest. 最快捷,最简单。 Create a symbolic link (effectively a "shortcut") for "node" that points to "nodejs". 为“node”创建指向“nodejs”的符号链接(实际上是“快捷方式”)。 You had a version of this in your answer. 你的答案中有一个版本。 It is generally accepted that it is a better practice to put this link in a location in your PATH other than in /usr/bin, such as in /usr/local/bin. 通常认为,将此链接放在PATH中除/ usr / bin之外的位置(例如/ usr / local / bin中)是更好的做法。 The directory is protected, so you need superuser privileges to create the link in the destination. 该目录受到保护,因此您需要超级用户权限才能在目标中创建链接。 So, the command to issue is: 因此,要发出的命令是:

     sudo ln -s /usr/bin/nodejs /usr/local/bin/node" sudo ln -s / usr / bin / nodejs / usr / local / bin / node“ 
  2. Alternatively, if you are on a system that doesn't have Node.js yet (or you remove the current package), when you install it via the package manager use the "nodejs-legacy" package (instead of nodejs). 或者,如果您所在的系统还没有Node.js(或者您删除了当前的软件包),那么当您通过软件包管理器安装它时,请使用“nodejs-legacy”软件包(而不是nodejs)。 This package actually creates a link automatically for you. 此包实际上会自动为您创建一个链接。 If you already have Node.js installed, you should remove it first. 如果您已经安装了Node.js,则应首先将其删除。

    • To remove "nodejs" package: 要删除“nodejs”包:
       sudo apt-get remove nodejs 
    • Install "nodejs-legacy" (the one with the link) 安装“nodejs-legacy”(带链接的那个)
       sudo apt-get install nodejs-legacy 
  3. Finally, you could install Node.js manually or build it. 最后,您可以手动安装Node.js或构建它。 This is more complicated and I won't try to explain all of that here. 这更复杂,我不会在这里解释所有这些。

Validation 验证

You can validate that jshint can run now by issuing the command "jshint --version", which should now look something like this: 您可以通过发出命令“jshint --version”来验证jshint现在可以运行,现在看起来应该是这样的:

$ jshint --version
    jshint v2.5.10

Happy Linting! 快乐的Linting!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM