我在 React 项目的 linting 过程中遇到错误:
Error: prettier.resolveConfig is not a function
Occurred while linting `path`
Rule: "prettier/prettier"
使用这些依赖项:
"@emotion/react": "^11.11.0",
"@emotion/styled": "^11.11.0",
"@formatjs/cli": "^5.1.13",
"@ladle/react": "^2.12.3",
"@tailwindcss/forms": "^0.5.3",
"@tippyjs/react": "^4.2.6",
"@types/async": "^3.2.20",
"@types/howler": "^2.2.7",
"@types/node": "^18.16.15",
"@types/pako": "^2.0.0",
"@types/react": "^18.2.7",
"@types/ws": "^8.5.4",
"dexie": "^3.2.3",
"framer-motion": "^11.2.10",
"howler": "^2.2.3",
"jsdom": "^20.0.3",
"lodash": "^4.17.21",
"logrocket": "^3.0.1",
"pako": "^2.1.0",
"postcss": "^8.4.23",
"prettier": "^2.8.8",
"prettier-plugin-tailwindcss": "^0.1.13",
"react": "^18.2.0",
"screenfull": "^6.0.2",
"tailwindcss": "^3.3.2",
"tailwindcss-debug-screens": "^2.2.1",
"typescript": "^4.9.5",
"xo": "^0.58.0",
与
.xo-config.json
(ESLint 包装器)一起使用的 xo
配置文件:
{
"space": 4,
"prettier": true,
"ignores": ["capacitor.config.ts", "android/**", "ios/**", "vite.config.ts", "node_modules", "dist", "build"],
"rules": {
"import/extensions": 0,
"no-warning-comments": 0,
"@typescript-eslint/consistent-type-definitions": 0,
"@typescript-eslint/naming-convention": 0,
"@typescript-eslint/no-unsafe-call": 0,
"@typescript-eslint/no-unsafe-return": 0,
"unicorn/prefer-switch": 0,
"@typescript-eslint/no-unsafe-assignment": 0,
"@typescript-eslint/ban-types": 0,
"unicorn/no-array-reduce": 0,
"n/file-extension-in-import": 0,
"unicorn/filename-case": 0,
"import/no-unassigned-import": 0,
"unicorn/prefer-module": 0,
"unicorn/prevent-abbreviations": [
"error",
{
"replacements": {
"param": false,
"params": false,
"props": false,
"args": false,
"e": false,
"ref": false,
"db": false,
"env": false,
"endOfLine": false
}
}
],
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "lodash",
"importNames": ["default"],
"message": "Use named imports"
}
]
}
]
}
}
Prettier使用的
.prettierrc
配置文件:
{
"printWidth": 120,
"trailingComma": "all",
"tabWidth": 4,
"singleQuote": true,
"bracketSpacing": true,
"endOfLine": "auto"
}
如何解决它以继续使用“xo”的 Prettier 格式? Prettier ^2.8.8 和“prettier/prettier”规则之间是否存在兼容性问题?
就我而言,升级到 Prettier v3> 对 eslint v9 有所帮助。