VSCode: ESLint + Prettier コードの構文チェックと書式設定

eslint + prettierを使ってvscodeでコードの構文を確認する方法を紹介します。現在、私たちのプロジェクトは主に tsx に基づいており、以下の設定手順も tsx に基づいています。

非常に簡単です。2 つのプラグインは次のようになります。
ここに画像の説明を挿入します
コード形式と構文チェックだけの場合: vscode 設定ファイルに関連する設定を記述するだけです ~

{
    
    
  "editor.formatOnSave": true, // 值设置为true时,每次保存的时候自动格式化;值设置为false时,按Command+Shift+F 格式化代码
  "editor.defaultFormatter": "esbenp.prettier-vscode", //默认格式化规则(可以按语言配置)
   "editor.detectIndentation": false, //vscode默认 启用时根据文件类型自动设置tabsize的选项,设置为false
  "editor.tabSize": 2, //tab的缩进为2
  // 添加ts语法验证支持
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ],
  // vscode 中附带了ts的最新稳定版本,也可以通过该配置项 配置要使用的ts
  "typescript.tsdk": "node_modules/typescript/lib",
  // 每次保存的时候将代码按eslint进行修复 
  "editor.codeActionsOnSave": {
    
    
    "source.fixAll.eslint": true
    // 此处还可配置tslint stylelint,如下:
    //"source.fixAll.tslint": true,
   // "source.fixAll.stylelint": true
  },
}

参考記事:
エスリント
・プリティア

おすすめ

転載: blog.csdn.net/xiaoxiannv666/article/details/120553496