[分享] VSCode配置与团队ESLint和TSLint配置

2019/12/25 更新


VSCode 官网


常用插件

  • Eslint:代码检查, 跑ESlint的时候直接跑VSCode配置里的Rule。
  • Eslint-disable-snippets: 代码内快速生成 eslint-disable 代码块

setting.json

{
  /**  vscode 系统配置项 */
  "window.zoomLevel": 0,
  "files.autoSave": "afterDelay",
  "explorer.confirmDelete": false,
  "explorer.confirmDragAndDrop": false,
  "vsicons.dontShowNewVersionMessage": true,
  "editor.foldingStrategy": "indentation",
  "git.autofetch": true,
  "git.enableSmartCommit": true,
  "editor.tabCompletion": "on",
  "editor.codeActionsOnSave": {
    "source.fixAll.tslint": true,
    "source.fixAll.eslint": true
  },
  "editor.accessibilitySupport": "off",
  "terminal.integrated.rendererType": "dom",

  /**  代码格式化配置 */
  "editor.tabSize": 2,
  // 打开对vue的lint,并自动fix
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "vue",
      "autoFix": true
    }
  ],
  // 尽可能控制尾随逗号的打印
  "prettier.trailingComma": "all",
  // 在保存时格式化文件
  "editor.formatOnSave": true,
  // 保存时自动fix
  "eslint.autoFixOnSave": true,
  // 格式化插件的配置
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {}
  },
   // 对于.vue文件,交给prettier,stylus因为prettier不支持改用vertur选项
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  "vetur.format.defaultFormatter.css": "prettier",
  "vetur.format.defaultFormatter.postcss": "prettier",
  "vetur.format.defaultFormatter.scss": "prettier",
  "vetur.format.defaultFormatter.less": "prettier",
  "vetur.format.defaultFormatter.stylus": "stylus-supremacy",
  "vetur.format.defaultFormatter.js": "prettier",
  "vetur.format.defaultFormatter.ts": "prettier",
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[scss]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[javascriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[typescriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },

  /**  第三方插件库配置 */
  "px2rem-plus.base": 100,
  "workbench.iconTheme": "vscode-icons",
  "workbench.startupEditor": "newUntitledFile",
  "liveServer.settings.donotShowInfoMsg": true,
  // 自动导入
  "typescript.updateImportsOnFileMove.enabled": "prompt",
  "javascript.updateImportsOnFileMove.enabled": "prompt",
  "javascript.suggest.autoImports": true,
  // 文件修改自动载入作者与时间
  "fileheader.configObj": {
    "createFileTime": true,
    "language": {
      "languagetest": {
        "head": "/$$",
        "middle": " $ @",
        "end": " $/"
      }
    },
    "autoAdd": false,
    "autoAlready": true,
    "annotationStr": {
      "head": "/*",
      "middle": " * @",
      "end": " */",
      "use": false
    },
    "headInsertLine": {
      "php": 2
    },
    "beforeAnnotation": {},
    "afterAnnotation": {},
    "specialOptions": {},
    "switch": {
      "newlineAddAnnotation": true
    },
    "config": {
      "dateFormat": "YYYY-MM-DD HH:mm:ss",
      "prohibitAutoAdd": ["json"],
      "moveCursor": true
    }
  },
  "fileheader.cursorMode": {},
  "fileheader.customMade": {
    "Author": "ZStop",
    "Date": "Do not edit", // 文件创建时间(不变)
    "LastEditors": "ZStop", // 文件最后编辑者
    "LastEditTime": "Do not edit" // 文件最后编辑时间
  },
  "diffEditor.ignoreTrimWhitespace": false,
  "[vue]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
}


tslint.json

{
  "defaultSeverity": "warning",
  "extends": ["tslint:recommended"],
  "linterOptions": {
    "exclude": ["node_modules/**"]
  },
  "rules": {
    "indent": [true, "spaces", 2],
    "interface-name": false,
    "ordered-imports": false,
    "object-literal-sort-keys": false,
    "max-line-length": false,
    "no-consecutive-blank-lines": false,
    "trailing-comma": false,
    "eofline": false,
    "quotemark": false,
    "typedef-whitespace": false,
    "no-console": false,
    "no-var-requires": false,
    "prefer-for-of": false,
    "forin": false,
    "variable-name": false,
    "no-empty": false,
    "noImplicitThis": false,
    "arrow-parens": false,
    "no-shadow": false,
    "no-shadowed-variable": false,
    "only-arrow-functions": false
  }
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • VS Code 常用插件列表 插件列表Auto Close Tag 自动闭合HTML标签Auto Rename T...
    战神飘雪阅读 423评论 0 0
  • 工欲善其事必先利其器,软件工程师每天打交道最多的可能就是编辑器了。入行几年来,先后折腾过的编辑器有 EditPlu...
    王仕军阅读 5,095评论 2 33
  • 一只海螺抛锚了 在退潮后的沙滩 破碎的墙壁,废弃的屋顶 所有的楼梯,通向大海 像我在梦里害怕走下去的那样
    咸水湖阅读 93评论 0 0
  • 三年前,被剧情感动得一塌糊涂的我问是否将来也有那么一个人,会让我的葡萄藤开出百合花。问的时候内心是绝望的。 直到,...
    心非石阅读 645评论 0 0
  • 列表是Elixir中重要的数据结构。相信其他编程语言中也有类似列表的结构。Lisp的命名来自对列表的处理。在C,J...
    人世间阅读 1,648评论 3 3