Emacs - 无法让 Flymake 与 JSHint 一起使用

发布于 2024-12-09 04:57:27 字数 1289 浏览 1 评论 0原文

我正在尝试让 JSHint 与 Flymake 一起使用。

jshint 确实安装在 /opt/bin 中并且可以工作。 /opt/bin 位于 Emacs 的 exec-path 中。

我已遵循 EmacsWiki 上的说明,并将其放入我的 init.el< /code>:

(defun flymake-jshint-init ()
  (let* ((temp-file (flymake-init-create-temp-buffer-copy
                     'flymake-create-temp-inplace))
         (local-file (file-relative-name
                      temp-file
                      (file-name-directory buffer-file-name))))
    (list "jshint" (list local-file))))

(setq flymake-err-line-patterns
      (cons '("^  [[:digit:]]+ \\([[:digit:]]+\\),\\([[:digit:]]+\\): \\(.+\\)$"
              nil 1 2 3)
            flymake-err-line-patterns))

(add-to-list 'flymake-allowed-file-name-masks
             '("\\.js\\'" flymake-jshint-init))

当我打开 JavaScript 文件时,我的模型行显示为:

[(Javascript Flymake* AC)]

这很奇怪,因为当我将 Flymake 与 C++ 或 Python 一起使用时,* 通常不会出现。根据 Flymake 文档,Flymake* 表示“Flymake 当前正在运行”。然而,Flymake 没有显示任何错误。

我已经检查了 *Messages* 缓冲区,但它只列出了几行 Fontifying foo.js... (regexps.............. ......)。没有错误。

其他建议?

I'm trying to get JSHint to work with Flymake.

jshint is indeed installed in /opt/bin and works. /opt/bin is in Emacs' exec-path.

I've followed the directions on the EmacsWiki and have this in my init.el:

(defun flymake-jshint-init ()
  (let* ((temp-file (flymake-init-create-temp-buffer-copy
                     'flymake-create-temp-inplace))
         (local-file (file-relative-name
                      temp-file
                      (file-name-directory buffer-file-name))))
    (list "jshint" (list local-file))))

(setq flymake-err-line-patterns
      (cons '("^  [[:digit:]]+ \\([[:digit:]]+\\),\\([[:digit:]]+\\): \\(.+\\)$"
              nil 1 2 3)
            flymake-err-line-patterns))

(add-to-list 'flymake-allowed-file-name-masks
             '("\\.js\\'" flymake-jshint-init))

When I open JavaScript files, my modeline appears as:

[(Javascript Flymake* AC)]

This is odd because the * usually doesn't appear when I'm using Flymake with C++ or Python. According to the Flymake docs, Flymake* means "Flymake is currently running." However, Flymake isn't showing any errors.

I've checked the *Messages* buffer but it only lists a few lines of Fontifying foo.js... (regexps...................). No errors.

Other suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

伴随着你 2024-12-16 04:57:27

尝试使用 M-: 执行 (setq Flymake-log-level 3),这将使 Flymake 将调试信息打印到 *Messages*

这是我如何将 Flymake 与 jslint 结合使用,效果很好对我来说——该代码可能会给你一些关于你出了什么问题的线索。

您还可以考虑js2-mode,它提供一些语言感知的类似 lint 的警告,而无需运行外部进程。

Try using M-: to execute (setq flymake-log-level 3), which will cause flymake to print debug info into *Messages*.

Here's how I use flymake with jslint, which works nicely for me -- that code might give you a clue about what's going wrong for you.

You might also consider js2-mode, which provides some language-aware lint-like warnings without resorting to running an external process.

谈下烟灰 2024-12-16 04:57:27

我找到了一个名为 jshint-mode 的项目并进行了尝试。它创建了一个名为 *jshint-mode* 的缓冲区,它揭示了错误:JSHint 找不到强大的模块。

我在 Emacs 中运行 Mx setenv 来设置 NODE_PATH,以便 jshint 可以找到强大的库。我还在 /etc/profile 中设置了 NODE_PATH

I found a project called jshint-mode and tried that. It created a buffer called *jshint-mode* which revealed the error: JSHint couldn't find the formidable module.

I ran M-x setenv in Emacs to set NODE_PATH so that jshint could find the formidable library. I also set NODE_PATH in /etc/profile.

翻了热茶 2024-12-16 04:57:27

jshint-mode 对我不起作用(我使用 Linux Mint 14 'Nadia')——我当运行 curl 与运行 jshint 脚本的 Node.js 实例对话时,“flymake 的配置”出现错误。这很令人困惑,而且我不熟悉 ELisp 来搞乱 .el 文件。

我通过直接访问 github 上的 Emacs flymake 项目 fork 解决了这个问题,该项目现在支持 jshint内置(它需要安装为 npm -g install jshint ,这反过来要求您安装 npm 和 node.js(如果尚未安装)。这使得事情顺利进行。

还要注意一点:在我的 Linux 机器上,node 是一个已存在于 /usr/sbin 中的可执行文件,我必须创建一个名为 node 的符号链接> 在 /usr/local/bin 中覆盖前者。这是必要的,因为 Linux Mint(也可能是 Ubuntu,我还没有检查)的 Node.js 二进制文件被命名为 nodejs,并且会导致许多脚本假设二进制名称为 node失败。您可以通过输入 node 进行测试:如果它是预先存在的二进制文件,它通常会默默地返回到提示符,但如果它是 Node.js,它会用 > 提示您code> (你可以按 Ctrl-D 退出)

jshint-mode did not work for me (I use Linux Mint 14 'Nadia') -- I was getting errors with "flymake's configuration" when it runs curl to talk to the Node.js instance running the jshint script. This was perplexing, and I'm not familiar with ELisp to go around messing with the .el files.

I solved this by instead going straight to the Emacs flymake project fork on github which now has support for jshint built-in (it needs to be installed as npm -g install jshint which in turn requires you to install npm and node.js if you haven't already). This made things work.

One more caveat: on my Linux box, node was an executable already existing in /usr/sbin and I had to make a symbolic link named node in /usr/local/bin to override the former. This was necessary as the Node.js binary for Linux Mint (possibly Ubuntu as well, I haven't checked) is named nodejs instead and will cause many scripts written assuming a binary name of node to fail. You can test this by typing node: if it is the pre-existing binary it generally returns to the prompt silently, but if it is Node.js it prompts you with a > (you can Ctrl-D to quit out of there)

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