打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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
    },
}

希望对大家有用

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
使用VS Code进行web开发必须知道的5个扩展插件
15款好用的VS Code插件
直接上手!不容错过的 Visual Studio Code 十大扩展组件
第一章——vue3.0 ts element-plus多页签应用模板:项目搭建篇
基于Vue3+TS的Monorepo前端项目架构设计与实现
vue-cli3项目配置eslint代码规范
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服