我们在项目中使用 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/