漂亮的文件不会格式化.tsx文件

我在视觉工作室代码编辑器中使用Prettier扩展已有很长时间了,但是最近我正在使用Typescript编写React。因此,我需要为Prettier配置以格式化.tsx文件。

评论
  • 苍老师
    苍老师 回复

    我的用法

    The way I set this up is to use eslint's .eslintrc.json file. First of all, in the "extends" array, I've added

    "plugin:@typescript-eslint/recommended"
    

    "prettier/@typescript-eslint"
    

    Then, I've set "parser" to "prettier/@typescript-eslint"

    Finally, in "plugins" array I've added "@typescript-eslint".

    You'll need to grab a couple of NPM packages (install with the -D option):

    @typescript-eslint/eslint-plugin
    @typescript-eslint/parser
    

    For reference, my entire .eslintrc.json file:

    {
      "env": {
        "browser": true,
        "es6": true,
        "jest": true
      },
      "extends": [
        "plugin:@typescript-eslint/recommended",
        "prettier/@typescript-eslint",
        "plugin:prettier/recommended"
      ],
      "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
      },
      "parser": "@typescript-eslint/parser",
      "parserOptions": {
        "ecmaFeatures": {
          "jsx": true
        },
        "project": "./src/tsconfig.json",
        "ecmaVersion": 2018,
        "sourceType": "module"
      },
      "plugins": ["react", "@typescript-eslint", "jest"],
      "rules": {
        "react/react-in-jsx-scope": "off"
      }
    }
    

    希望这可以帮助。