我在 React (TypeScript) 项目中使用 Husky 和 lint-staged。我的文件如下所示:
package.json
"check-types": "tsc --pretty --noEmit",
"fix-eslint:staged": "yarn check-eslint:staged --fix",
"fix-format:staged": "prettier --write",
pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn lint-staged
lint-staged.config.js
module.exports = {
'**/*.{js,jsx,ts,tsx}': () => [
'yarn check-types',
'yarn fix-eslint:staged',
'yarn fix-format:staged'
],
'**/*.css': ['yarn fix-stylelint:css']
};
问题是更漂亮的脚本yarn fix-format:staged
永远不会结束。即使我将它放在顶部,它也会继续运行。
如果我将 lint-stage 设置移动到package.json
如下所示,则yarn check-types
失败并出现错误:Cannot use JSX unless the '--jsx' flag is provided.
package.json
"lint-staged": {
"**/*.{js,jsx,ts,tsx}": [
"yarn check-types",
"yarn fix-eslint:staged",
"yarn fix-format:staged"
],
"**/*.css": [
"yarn fix-stylelint:css"
]
},
任何人都可以帮我吗?