如何在WebStorm/PHPStorm中保存时配置ESLint自动修复? [英] How to configure ESLint auto fix on save in WebStorm/PHPStorm?

查看:1144
本文介绍了如何在WebStorm/PHPStorm中保存时配置ESLint自动修复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在WebStorm中创建一个自定义文件监视程序,该监视程序将在保存时自动修复ESLint错误.在Settings > Tools > File Watchers中,我使用以下设置创建了一个新的文件查看器:

I am trying to create a custom file watcher in WebStorm that will auto fix ESLint errors on save. In Settings > Tools > File Watchers I created a new file watcher with the following settings:

  • 文件类型:Any
  • 范围:All places
  • 程序:/home/user/Projects/todo-app/eslint-autofix.sh
  • 参数:空白
  • 要刷新的输出路径:空白
  • 其他选项>工作目录:/home/user/Projects/todo-app
  • File type: Any
  • Scope: All places
  • Program: /home/user/Projects/todo-app/eslint-autofix.sh
  • Arguments: blank
  • Output paths to refresh: blank
  • Other options > Working directory: /home/user/Projects/todo-app

eslint-autofix.sh:

#!/usr/bin/env bash

./node_modules/.bin/eslint --fix

然后我犯了一个ESLint错误,然后按 Ctrl + S 保存.弹出以下错误:

Then I made an ESLint error and pressed Ctrl + S to save. The following error pops up:

/home/user/Projects/todo-app/eslint-autofix.sh
/usr/bin/env: ‘node’: No such file or directory

如何解决此错误?

推荐答案

根据这篇文章,设置应如下所示:

According to this article, settings should be as the following:

  • 文件类型:任意(或JavaScript)
  • 范围:项目文件
  • 程序:$ ProjectFileDir $/node_modules/.bin/eslint
  • 参数:--fix $ FilePath $
  • 要刷新的输出路径:$ FileDir $

这篇关于如何在WebStorm/PHPStorm中保存时配置ESLint自动修复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆