[英]How to configure ESLint auto fix on save in WebStorm/PHPStorm?
我正在尝试在 WebStorm 中创建一个自定义文件观察器,它将在保存时自动修复 ESLint 错误。 在Settings > Tools > File Watchers
文件观察器中,我创建了一个具有以下设置的新文件观察器:
Any
All places
/home/user/Projects/todo-app/eslint-autofix.sh
/home/user/Projects/todo-app
eslint-autofix.sh:
#!/usr/bin/env bash
./node_modules/.bin/eslint --fix
然后我犯了一个 ESLint 错误并按Ctrl + S保存。 弹出以下错误:
/home/user/Projects/todo-app/eslint-autofix.sh
/usr/bin/env: ‘node’: No such file or directory
如何修复此错误?
根据这篇文章,设置应该如下:
在WebStorm 2020.1.1
,有一个名为Run eslint --fix on save
的复选框。
另见:
只是为了扩展 jstice4all 和 gotjosh 的解决方案:
对于某些项目,我能够将 FileWatcher 设置为 ESLint,但它无法与插件扩展一起使用:'@react-native-community'
@react-native-community/eslint-config#overrides[2]:
Environment key "jest/globals" is unknown
事实证明, @react-native-community 插件需要从项目文件夹本身运行才能加载环境变量,而文件观察器从 node_module/eslint 路径运行。 为了让它工作,我必须添加以下配置:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.