VSCode TSlint + Prettier 實現代碼的格式化


VSCode :插件搜索TSLint 和Prettier 分別安裝

1、在Vscode中的,【文件】-【首選項】-【設置】,進入settings.json文件

 

 2、增加配置:

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

3、項目根目錄下,新增 .prettierrc.json 配置文件;更多配置規則請 移步 

{
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true,
  "trailingComma": "none",
  "arrowParens": "always"
}

  

 4、tslint.json文件

{
  "defaultSeverity": "warning",
  "extends": ["tslint:latest"],
  "linterOptions": {
    "exclude": ["node_modules/**"]
  },
  "rules": {
    "indent": [true, "spaces", 2],
    "interface-name": false,
    "no-consecutive-blank-lines": false,
    "object-literal-sort-keys": false,
    "ordered-imports": false,
    "quotemark": [true, "single"],
    "semicolon": [true, "never"],
    "trailing-comma": [true, { "multiline": "never", "singleline": "never" }]
  }
}

  

網上搜索此塊內容較多,分不清正確或錯誤。如該方法失效,請在vscode安裝插件后的插件介紹中獲取使用方法。

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM