簡體   English   中英

更漂亮,eslint - classProperties 解析器插件錯誤

[英]Prettier, eslint - classProperties parser plugin error

我正在努力讓我更漂亮的作品正常工作。 當我啟動format-checkprettier --check on js,ts 文件)時,它給了我SyntaxError: This experimental syntax requires enabling the parser plugin: 'classProperties'在許多 class 文件中的錯誤(即使是具有一個屬性和吸氣劑的簡單文件)盡管下面的配置。 當我將解析器從默認更改為.prettierrc.json中的其他內容時, "@trivago/prettier-plugin-sort-imports"插件不起作用。 我想要配置,它不會給我提到的錯誤並允許排序插件工作。 也許我在 eslint-prettier 線上有一些沖突?

package.json在主目錄中的一部分

"devDependencies": {
    "@babel/plugin-proposal-class-properties": "7.12.1",
    "@types/react": "16.9.46",
    "@types/react-dom": "16.9.8",
    "@types/styled-components": "5.1.2",
    "@typescript-eslint/eslint-plugin": "2.34.0",
    "@typescript-eslint/parser": "2.34.0",
    "@trivago/prettier-plugin-sort-imports": "1.3.0",
    "eslint": "6.8.0",
    "eslint-config-airbnb": "18.2.0",
    "eslint-config-airbnb-base": "14.2.0",
    "eslint-config-prettier": "6.11.0",
    "eslint-plugin-eslint-comments": "3.2.0",
    "eslint-plugin-eslint-plugin": "2.3.0",
    "eslint-plugin-jest": "23.20.0",
    "eslint-plugin-jsx-a11y": "5.1.1",
    "eslint-plugin-prettier": "3.1.4",
    "eslint-plugin-react": "7.20.6",
    "eslint-plugin-react-hooks": "4.1.0",
    "jest-styled-components": "7.0.3",
    "lerna": "3.22.1",
    "prettier": "2.2.1"
  },
  "scripts": {
    "format": "prettier  --write \"**/*.{ts,tsx,js,jsx}\"",
    "format-check": "prettier --check \"**/*.{ts,tsx,js,jsx}\"",
    ...
  },
  "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react",
      {
        "plugins": [
          "@babel/plugin-proposal-class-properties",
          {
            "loose": true
          }
        ]
      }
    ]
  }

.eslintrc.js在主目錄中

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
    jest: true,
  },
  plugins: ['@typescript-eslint'],
  extends: [
    'airbnb',
    'plugin:react/recommended',
    'plugin:react-hooks/recommended',
    'plugin:jsx-a11y/strict',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:@typescript-eslint/recommended-requiring-type-checking',
    'react-app',
  ],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaVersion: 2017, // Allows for the parsing of modern ECMAScript features
    sourceType: 'module', // Allows for the use of imports
    ecmaFeatures: {
      jsx: true, // Allows for the parsing of JSX
    },
    project: ['./projects/*/tsconfig.json'],
  },
  settings: {
    react: {
      version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
    },
  },
};

.prettierrc.json在主目錄中

{
  "semi": true,
  "trailingComma": "all",
  "singleQuote": true,
  "printWidth": 120,
  "tabWidth": 2,
  "arrowParens": "always",
  "importOrder": ["^[a-zA-Z](.*)$", "^@[a-zA-Z](.*)$$", "^[./]"],
  "importOrderSeparation": true
}

如果將以下內容添加到.prettierrc.json以啟用所需的解析器插件,它似乎可以正常工作:

"experimentalBabelParserPluginsList": ["classProperties", "jsx", "typescript"]

這是用prettier 2.3.2 和@trivago/prettier-plugin-sort-imports 2.0.4 測試的。

完整的.prettierrc.json

{
  "semi": true,
  "trailingComma": "all",
  "singleQuote": true,
  "printWidth": 120,
  "tabWidth": 2,
  "arrowParens": "always",
  "importOrder": ["^[a-zA-Z](.*)$", "^@[a-zA-Z](.*)$$", "^[./]"],
  "importOrderSeparation": true,
  "experimentalBabelParserPluginsList": ["classProperties", "jsx", "typescript"]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM