如何在 VSCode 中使用 eslint 为文件添加单引号

How to make files single quotes using eslint in VSCode

我想在保存时将文件设为单引号而不使用 prettier,并且仅使用 eslint 或配置基本 VScode 设置。

我读到 .eslintrc.js 需要编辑以在保存时将双引号更改为单引号,但它位于 VScode 中的什么位置?我试过在设置中搜索但找不到 .eslintrc.js.

这对我有用

我的eslint.rc

{
     ... //other options
     "rules": {
        "quotes": [2, "single"]
      }
}

我的vscodesettings.json

{
   ...,
   "editor.codeActionsOnSave": {
      "source.fixAll.eslint": true
    },
   "eslint.validate": [
      "typescript",
      "typescriptreact"
   ]
}

在您的 vscode 设置中,添加以下内容:

"javascript.preferences.quoteStyle": "single",
"typescript.preferences.quoteStyle": "single"