VS Code保存去掉自动加分号、逗号、双引号

之前发过一篇ESlint检测自动加逗号的文章,VS Code设置了如果还是未生效,应该怎么办呢?

书写规范是非常重要的,出了统一,还要简洁。

1、VS Code识别编辑规范

在项目根目录新建.editorconfig文件,加入设置:

# editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

2、ESlint规则

在项目根目录新建.eslintrc.json文件,加入设置:

{
  "env": {
    "browser": true,
    "es2021": true,
    "jquery": true // $不报错
  },
  "extends": [
    "standard"
  ],
  "parserOptions": {
    "ecmaVersion": 12,
    "sourceType": "module"
  },
  "rules": {
    "space-before-function-paren": ["error", {
      "anonymous": "always",
      "named": "never",
      "asyncArrow": "always"
    }]
  }
}

3、VS Code保存去掉自动加分号、逗号、双引号

在VS Code的是settings.json插入:

{
    "prettier.useEditorConfig": true,
    "prettier.jsxSingleQuote": true,
    "prettier.singleQuote": true,
    "prettier.trailingComma": "none",
    "prettier.semi": false,
    "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "editor.formatOnSave": false,
    "editor.codeActionsOnSave": {
        // For ESLint
        "source.fixAll.eslint": true,
        // For TSLint
        "source.fixAll.tslint": true,
        // For Stylelint
        "source.fixAll.stylelint": true
    },
    "[html]": {
        "editor.defaultFormatter": "HookyQR.beautify"
    },
    "files.exclude": {
        "node_modules": true
    },
}
本条目发布于。属于科技分类。作者是

关于有个狸

2005年开始的一名站长,从事网站策划、运营,早期一批扎根阿里妈妈、Google Adsense的一员,目前司职前端与产品设计。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注