简体   繁体   English

对WebStorm中的标记区域使用ESLint修复

[英]Use ESLint fix for a marked area in WebStorm

We use ESLint in our project so I want to format my code with the ESLint rules during the development process. 我们在项目中使用ESLint,因此我想在开发过程中使用ESLint规则格式化代码。 I am using WebStorm and currently always use the "fix ESLint problems" function out of the context menu. 我正在使用WebStorm,当前始终使用上下文菜单之外的“修复ESLint问题”功能。 Unfortunately, this formats the whole file which I don't want. 不幸的是,这格式化了我不需要的整个文件。

Has anybody an idea how I can format my code like the integrated "reformat code" function integrated in WebStorm (where only the selected area gets formatted) but comply with the ESLint rules? 有谁知道如何格式化WebStorm中集成的集成“重新格式化代码”功能(仅对选定区域进行格式化)但符合ESLint规则的格式?

Here is my eslintrc configuration 这是我的eslintrc配置

{
    "extends": "eslint-config-airbnb-base",
    "rules": {
        "no-console": ["error"],
        "import/no-extraneous-dependencies": {
          "optionalDependencies": true
        },
        "indent": [ "error", 4] ,
        "arrow-parens": ["error", "as-needed"],
        "max-len": [ "error", 120, 4, { "ignoreComments": true, "ignoreUrls": true} ],
        "no-underscore-dangle": [2, { "allowAfterThis": true }]
    },
    "env": {
        "jest": true,
        "es6": true,
        "node": true
    },
    "parserOptions": { "ecmaVersion": 9 }
}

There is no way to apply ESLint fix to selection in WebStorm, and I doubt that ESLint has an API for this. 无法将ESLint修复应用于WebStorm中的选择,并且我怀疑ESLint具有用于此的API。 But you can import your code style preferences from .eslintrc and then use the built-in formatter ( Code | Reformat Code ) to format the selection 但是,您可以从.eslintrc 导入代码样式首选项 ,然后使用内置的格式化程序( Code | Reformat Code )来格式化选择

Unfortunately, WebStorm (Really the ESLint plugin for WebStorm) doesn't have support for an "inline ESLint fix" action, the option about Reformat Code will reformat all the code of the file also (And that's not what you're looking for). 不幸的是,WebStorm(实际上是WebStorm的ESLint插件)不支持“内联ESLint修复”操作,有关重新格式化代码 ”的选项也会重新格式化文件的所有代码(这不是您要查找的内容) 。 For now, you're stuck with the "Fix ESLint problem" option in WebStorm. 目前,您还只能使用WebStorm中的“修复ESLint问题”选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM