我是archlinux 环境, node版本6.11.3, eslint版本5.9.0
javascript-eslint (disabled)
- may enable: Automatically disabled!
- executable: Found at $PROJECT_ROOT/node_modules/.bin/eslint
- config file: missing or incorrect
总是提示配置文件找不到。
我尝试在项目根目录执行 eslint --print-config .
也没有任何报错。
exec-path手动设置 eslint 的路径也没用。
有哪位有类似经验的吗?使用windows和mac都没有遇到类似的问题。。。
P.S. 使用命令行是可以正常对项目里面的js文件进行eslint检查的。
(flycheck-eslint-config-exists-p) 返回的是 nil , 这个函数的实现是
(defun flycheck-eslint-config-exists-p ()
"Whether there is a valid eslint config for the current buffer."
(let* ((executable (flycheck-find-checker-executable 'javascript-eslint))
(exitcode (and executable (call-process executable nil nil nil
"--print-config" "."))))
(eq exitcode 0)))
这里面的 call-process 返回的是127, 其他平台返回的都是0。
我在命令行执行 eslint --print-config .
是正常的。。。 太奇怪了。
程序路径是对的,emacs 里面运行就不对。 升级了 emacs 27.0也不行。。。
解决了, 修改 exec-path
指向 node
和 eslint
的路径 。
同时,必须添加一个 symbol link 把你安装的 node 指到 /usr/bin/node
。(https://cloud.tencent.com/developer/article/1028166)
可以通过下面的脚本来检测错误:
(with-temp-buffer
(list (call-process "ls" nil (current-buffer) nil "-h" "-l")
(buffer-string)))
;; we could wrap it up nicely:
(defun process-exit-code-and-output (program &rest args)
"Run PROGRAM with ARGS and return the exit code and output in a list."
(with-temp-buffer
(list (apply 'call-process program nil (current-buffer) nil args)
(buffer-string))))
(process-exit-code-and-output "ls" "-h" "-l" "-a") ;; => (0 "-r-w-r-- 1 ...")
;; 这一步很关键,可以检查 emacs 里面运行 eslint 的错误返回码
(process-exit-code-and-output "eslint" "--print-config" ".")
(call-process "eslint" nil nil nil "--help")
(call-process "node" nil nil nil "--version")
如果报错 /usr/bin/env: node: No such file or directory
这个错误码是 127,
则需要建立软链接。。。
如果下次你的 eslint 还是报错,你可以如下步骤来 check:
enable flycheck
M-x flycheck-verity-setup
检测是否可以找到 eslint的可执行程序和配置文件
如果找不到 eslint 可执行程序,需要往 exec-path 里面添加 eslint 所在路径
如果配置找不到,可以试着在项目的根目录执行 eslint --print-config .
(解决任何可能的错误)
如果步骤5正常,则需要check flycheck-eslint-config-exists-p
函数执行情况,如果返回 nil,则使用本文的方案。
fuuuuuuuuuuuuuuuuuuck 呀!!!浪费我几个小时。
2 个赞
2019.7.5 号更新:
如果 eslint的版本大于5会导致 eslint --print-config .
出错:
Oops! Something went wrong! :(
ESLint: 6.0.0.
ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:
eslint --init
ESLint looked for configuration files in /home/user/www and its ancestors.
Github上面有讨论:
opened 10:13AM - 22 Jun 19 UTC
closed 01:03AM - 25 Jun 19 UTC
bug
core
evaluating
archived due to age
<!--
ESLint adheres to the [JS Foundation Code of Conduct](https://js.found… ation/community/code-of-conduct).
This template is for bug reports. If you are here for another reason, please see below:
1. To propose a new rule: https://eslint.org/docs/developer-guide/contributing/new-rules
2. To request a rule change: https://eslint.org/docs/developer-guide/contributing/rule-changes
3. To request a change that is not a bug fix, rule change, or new rule: https://eslint.org/docs/developer-guide/contributing/changes
4. If you have any questions, please stop by our chatroom: https://gitter.im/eslint/eslint
Note that leaving sections blank will make it difficult for us to troubleshoot and we may have to close the issue.
-->
**Tell us about your environment**
* **ESLint Version:** v6.0.0
* **Node Version:** v11.15.0
* **npm Version:** 6.9.0
**What parser (default, Babel-ESLint, etc.) are you using?** default
**Please show your full configuration:**
<details>
<summary>Configuration</summary>
```js
```
</details>
**What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.**
```js
module.exports = {
env: {
browser: true,
commonjs: true,
es6: true
},
extends: [
'standard',
'plugin:vue/recommended',
'prettier',
'prettier/babel',
'prettier/standard',
'prettier/vue'
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
},
plugins: ['babel', 'prettier', 'standard', 'vue'],
rules: { 'prettier/prettier': 'error' }
};
```
```bash
$ cd /home/user/www/project && yarn run eslint --print-config .
```
**What did you expect to happen?**
Printing config
**What actually happened? Please include the actual, raw output from ESLint.**
Looks in upper path instead of current.
```
Oops! Something went wrong! :(
ESLint: 6.0.0.
ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:
eslint --init
ESLint looked for configuration files in /home/user/www and its ancestors.
```
Project path is located at `/home/user/www/project`.
**Are you willing to submit a pull request to fix this bug?**
No, sorry.
而 flycheck内部判断 eslint 配置文件是否存在是通过 eslint --print-config .
这个语句的返回值来判断的。
(defun flycheck-eslint-config-exists-p ()
"Whether there is a valid eslint config for the current buffer."
(let* ((executable (flycheck-find-checker-executable 'javascript-eslint))
(exitcode (and executable (call-process executable nil nil nil
"--print-config" "."))))
(eq exitcode 0)))
这个时候,可以通过 npm install eslint@5
降级来解决。坑了我半个小时。。 记录一下。
1 个赞
This problem is fixed by flycheck PR 1588 . So far, using the package in Melpa will be fine.
1 个赞
emacs好像不会识别项目目录下的eslintrc,而是识别了全局的,如何做到识别项目目录下的eslintrc呢?