繁体   English   中英

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

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

我们在项目中使用ESLint,因此我想在开发过程中使用ESLint规则格式化代码。 我正在使用WebStorm,当前始终使用上下文菜单之外的“修复ESLint问题”功能。 不幸的是,这格式化了我不需要的整个文件。

有谁知道如何格式化WebStorm中集成的集成“重新格式化代码”功能(仅对选定区域进行格式化)但符合ESLint规则的格式?

这是我的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 }
}

无法将ESLint修复应用于WebStorm中的选择,并且我怀疑ESLint具有用于此的API。 但是,您可以从.eslintrc 导入代码样式首选项 ,然后使用内置的格式化程序( Code | Reformat Code )来格式化选择

不幸的是,WebStorm(实际上是WebStorm的ESLint插件)不支持“内联ESLint修复”操作,有关重新格式化代码 ”的选项也会重新格式化文件的所有代码(这不是您要查找的内容) 。 目前,您还只能使用WebStorm中的“修复ESLint问题”选项。

暂无
暂无

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

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