0

我试图让 JSHint 与 Flymake 一起工作。

jshint确实已安装/opt/bin并可以正常工作。/opt/bin在 Emacs 中exec-path

我已按照EmacsWiki 上的说明进行操作,并在我的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))

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

[(Javascript Flymake* AC)]

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

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

其他建议?

4

3 回答 3

1

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

下面是我如何将 flymake 与 jslint 一起使用,这对我来说效果很好——该代码可能会为您提供有关您出了什么问题的线索。

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

于 2011-10-12T09:42:36.750 回答
0

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

M-x setenv在 Emacs 中运行进行设置NODE_PATH,以便jshint可以找到强大的库。我也NODE_PATH入了/etc/profile

于 2011-10-11T22:07:07.860 回答
0

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)

于 2013-03-19T07:52:45.720 回答