0

我有一个 TypeScript React Native 项目。我正在尝试使用 eslint 和 Prettier 配置项目。

这是我的.eslint.yaml

env:
  browser: true
  es2021: true
  node: true
extends:
  - "plugin:react/recommended"
  - google
  - prettier
  - eslint-config-prettier
parser: "@typescript-eslint/parser"
parserOptions:
  ecmaFeatures:
    jsx: true
  ecmaVersion: 12
  sourceType: module
plugins:
  - react
  - "@typescript-eslint"
rules: { "max-len": ["error", { "code": 80 }] }
settings:
  react:
    pragma: React
    version: detect

这是我的.prettierrc.yaml

printWidth: 80

如果它有帮助,这是我的package.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject",
    "test": "jest"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/vector-icons": "^12.0.0",
    "@react-navigation/bottom-tabs": "^6.0.5",
    "@react-navigation/native": "^6.0.2",
    "@react-navigation/native-stack": "^6.1.0",
    "eslint-config-prettier": "^8.3.0",
    "expo": "~42.0.1",
    "expo-asset": "~8.3.2",
    "expo-constants": "~11.0.1",
    "expo-font": "~9.2.1",
    "expo-linking": "~2.3.1",
    "expo-splash-screen": "~0.11.2",
    "expo-status-bar": "~1.0.4",
    "expo-web-browser": "~9.2.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-native": "0.63",
    "react-native-gesture-handler": "~1.10.2",
    "react-native-reanimated": "~2.2.0",
    "react-native-safe-area-context": "3.2.0",
    "react-native-screens": "~3.4.0",
    "react-native-web": "~0.13.12"
  },
  "devDependencies": {
    "@babel/core": "^7.9.0",
    "@testing-library/react-hooks": "^7.0.2",
    "@types/react": "~16.9.35",
    "@types/react-native": "~0.63.2",
    "@typescript-eslint/eslint-plugin": "^4.32.0",
    "@typescript-eslint/parser": "^4.32.0",
    "eslint": "^7.32.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-react": "^7.26.0",
    "improved-yarn-audit": "^2.3.3",
    "jest-expo": "42.1.0",
    "prettier": "^2.4.1",
    "typescript": "~4.0.0",
    "yarn-audit-fix": "^7.0.4"
  },
  "private": true
}

现在,当我运行时eslint **/*.ts **/*.tsx,它会按预期失败,因为某些文件的行数超过 80 个字符。但是,当我运行时prettier --check .,它不会失败,同样,prettier --write .也不会修复任何东西。

如何让 Prettier 检测和修复这些行长违规?

4

0 回答 0