是否可以配置 .eslintrc
以便运行 eslint --fix
也可以运行 prettier --write
?
现在我需要做 prettier --write && eslint --fix
并且我希望我可以只运行一个命令。
更新
使用 prettier-eslint
“有效”,但它不应用我的自定义覆盖:
我的 .eslintrc.js
看起来像
module.exports = {
extends: [
'prettier',
],
plugins: [
'prettier',
],
rules: {
'prettier/prettier': [
'error',
{
'singleQuote': true,
},
],
}
};
然后我有一个虚拟 file.js:
const path = require("path");
const foo = () => {
return path;
}
如果我运行 eslint ./file.js
我会得到预期的输出:
error Replace
"path"
with'path'
prettier/prettier
但是当我运行 prettier-eslint --eslint-config-path .eslintrc.js --write ./file.js
时,它会保留 "
并且不会将其替换为 '
我不想为 prettierrc 建立一个单独的文件,而是希望将两者保留在一个文件中。
最佳答案
有一个很棒的软件包,名为 prettier-eslint我们以前在工作中使用过。它将使用 prettier 进行格式化,然后运行 eslint --fix
在你的代码上。我们喜欢它,尝试一下!
关于javascript - 如何让 ESLint --fix 也运行 prettier --write,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58648902/