[分享] VSCode配置與團(tuán)隊(duì)ESLint和TSLint配置

2019/12/25 更新


VSCode 官網(wǎng)


常用插件

  • Eslint:代碼檢查, 跑ESlint的時(shí)候直接跑VSCode配置里的Rule。
  • Eslint-disable-snippets: 代碼內(nèi)快速生成 eslint-disable 代碼塊

setting.json

{
  /**  vscode 系統(tǒng)配置項(xiàng) */
  "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,
  // 打開對(duì)vue的lint,并自動(dòng)fix
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "vue",
      "autoFix": true
    }
  ],
  // 盡可能控制尾隨逗號(hào)的打印
  "prettier.trailingComma": "all",
  // 在保存時(shí)格式化文件
  "editor.formatOnSave": true,
  // 保存時(shí)自動(dòng)fix
  "eslint.autoFixOnSave": true,
  // 格式化插件的配置
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {}
  },
   // 對(duì)于.vue文件,交給prettier,stylus因?yàn)閜rettier不支持改用vertur選項(xiàng)
  "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"
  },

  /**  第三方插件庫(kù)配置 */
  "px2rem-plus.base": 100,
  "workbench.iconTheme": "vscode-icons",
  "workbench.startupEditor": "newUntitledFile",
  "liveServer.settings.donotShowInfoMsg": true,
  // 自動(dòng)導(dǎo)入
  "typescript.updateImportsOnFileMove.enabled": "prompt",
  "javascript.updateImportsOnFileMove.enabled": "prompt",
  "javascript.suggest.autoImports": true,
  // 文件修改自動(dòng)載入作者與時(shí)間
  "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", // 文件創(chuàng)建時(shí)間(不變)
    "LastEditors": "ZStop", // 文件最后編輯者
    "LastEditTime": "Do not edit" // 文件最后編輯時(shí)間
  },
  "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
  }
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • VS Code 常用插件列表 插件列表Auto Close Tag 自動(dòng)閉合HTML標(biāo)簽Auto Rename T...
    戰(zhàn)神飄雪閱讀 435評(píng)論 0 0
  • 工欲善其事必先利其器,軟件工程師每天打交道最多的可能就是編輯器了。入行幾年來,先后折騰過的編輯器有 EditPlu...
    王仕軍閱讀 5,242評(píng)論 2 33
  • 一只海螺拋錨了 在退潮后的沙灘 破碎的墻壁,廢棄的屋頂 所有的樓梯,通向大海 像我在夢(mèng)里害怕走下去的那樣
    咸水湖閱讀 114評(píng)論 0 0
  • 三年前,被劇情感動(dòng)得一塌糊涂的我問是否將來也有那么一個(gè)人,會(huì)讓我的葡萄藤開出百合花。問的時(shí)候內(nèi)心是絕望的。 直到,...
    心非石閱讀 688評(píng)論 0 0
  • 列表是Elixir中重要的數(shù)據(jù)結(jié)構(gòu)。相信其他編程語言中也有類似列表的結(jié)構(gòu)。Lisp的命名來自對(duì)列表的處理。在C,J...
    人世間閱讀 1,709評(píng)論 3 3

友情鏈接更多精彩內(nèi)容