Webstorm和其他JetBrains

Webstorm和其他JetBrains

本文介绍了如何在Intellij-IDEA,Webstorm和其他JetBrains IDE中的JavaScript上运行eslint --fix?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我保存文件时,我想运行eslint,并修复任何可以解决的问题。



我知道这可以通过使用命令行运行应用 - 修复参数。



我也知道Intellij-IDEA已与Eslint集成直;但是,Intellij-IDEA使用stdin进行集成,这意味着你不能将 - fix 作为参数传递。

解决方案

通过几个快速步骤,您可以设置一个文件监视器,它将对您保存的文件运行eslint --fix。



一步一步:




  • 安装


    When I save a file, I would like to run eslint, and have it fix any issues that eslint can fix.

    I know this can be accomplished using the command line by running applying the --fix argument.

    I also know that Intellij-IDEA has integration with Eslint directly; however, Intellij-IDEA uses stdin for it's integration which means you can't pass --fix as an argument.

    解决方案

    With a few quick steps you can setup a file watcher that will run eslint --fix on the files you save.

    Step by step:

    • Install the File Watcher plugin
    • Navigate to Preferences > Tools > File Watchers and create a new File Watcher
    • Choose File type: JavaScript
    • Optionally, apply a scope for the watcher. For example, I chose $ProjectFileDir$/apps/web/src/ and included all of it's contents recursively.
    • Choose the program to run. With node, npm, and eslint installed point to the eslint bin. In my project, the path was $ProjectFileDir$/apps/web/node_modules/eslint/bin/eslint.js
    • Apply the following arguments to run eslint with the fix option on the file that was saved --fix $FileName$
    • Specify the working directory as $FileDir$.

    Name, and save the File Watcher. Then, edit a JavaScript file in the directory you scoped and watch many of your errors and warnings go away! Thanks Eslint!

    Note: If you find Intellij-IDEA asking if you want to load file changes without you saving know (which gets annoying) it's because the IDE is saving in the background. You can uncheck Immediate file synchronization to have a better editing experience.

    这篇关于如何在Intellij-IDEA,Webstorm和其他JetBrains IDE中的JavaScript上运行eslint --fix?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 08:28