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

标签 javascript webstorm eslint jetbrains-ide

我们在项目中使用 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。但你可以import your code style preferences来自 .eslintrc,然后使用内置格式化程序(Code | Reformat Code)来格式化所选内容

关于javascript - 使用 ESLint 修复 WebStorm 中的标记区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56575370/

相关文章:

javascript - gulp-ignore 与 gulp-jshint

css - 无论如何不要在 WebStorm 中格式化 CSS 新断线以更好地支持 Flexbox Grid

javascript - JQuery:div正常出现和消失,但第二次单击它不起作用

javascript - 如何从 Django 中的模态表单更新单个字段?

javascript - 将服务工作人员代码完成添加到 JetBrains WebStorm

javascript - 包含脚本时 react "document not defined"

eslint - 如何使用长 svg 路径满足 eslint 最大行长规则?

javascript - 如何绕过 ESLint 调用 Typescript 中未定义的 Geolocation 接口(interface)?

javascript - 使用 Javascript 在新选项卡中打开 PDF

WebStorm:尝试在项目树中移动目录时出现 "move failed"