react-native - 反应原生 eslint 预提交不起作用
问题描述
我想在提交之前强制执行 eslint 规则,并且我已经在 react-native package.js 文件中配置了预提交,但它在提交时没有显示 eslint 错误。如果我运行yar run lint
正常。
下面是我的 Package.js 文件
{
"name": "test",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"react": "17.0.2",
"react-native": "0.65.1",
"storyblok-js-client": "^4.0.9",
"react-query": "^3.19.1",
"react-redux": "^7.2.4",
"graphql": "^15.5.0",
"graphql-request": "^3.5.0",
"react-native-typography": "^1.4.1",
"rn-fetch-blob": "^0.12.0",
"react-native-webview": "^11.13.0",
"base-64": "^1.0.0"
},
"devDependencies": {
"@babel/core": "^7.15.5",
"@babel/runtime": "^7.15.4",
"@react-native-community/eslint-config": "^3.0.1",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"babel-jest": "^27.2.0",
"eslint": "^7.32.0",
"eslint-plugin-react": "^7.25.1",
"jest": "^27.2.0",
"metro-react-native-babel-preset": "^0.66.2",
"react-native-codegen": "^0.0.7",
"react-test-renderer": "17.0.2",
"@testing-library/react-native": "^7.2.0",
"eslint-plugin-jest": "^24.4.0",
"fetch-mock": "^9.11.0",
"husky": "^7.0.2",
"lint-staged": "^11.1.2",
"typescript-styled-plugin": "^0.18.1"
},
"lint-staged": {
"src/**/*.{ts,tsx, js, jsx}": [
"eslint --ext .tsx --ext .ts src/ --fix"
],
"./src/**": [
"prettier --write ."
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged && pretty-quick --staged"
},
"jest": {
"preset": "react-native"
}
}
}
解决方案
你跑了husky install
吗?
您还可以尝试将名为“pre-commit”的文件添加到 .husky 文件夹,其内容如下:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
推荐阅读
- android - 自定义视图按钮单击 AlertDialog
- architecture - 为项目推荐目的在微服务之间共享(几乎)相同的数据是否是个坏主意
- typescript - 带有约束的打字稿通用没有键
- c# - Base64EncodedString 不包括 NewLines
- python - Pandas 连接 cols/datatypes,int() 的无效文字,基数为 10
- java - 在使用 ReadBuffer 和 WriteBuffer 时,如何从下到上反转读取文本文件?
- javascript - 查找行号布尔矩阵最大数 1s
- r - lm 与使用管道 %>% 运算符的交互项
- python - 对于 DataFrame 的每一行,将给定条件的第一列的索引放入新列
- python-3.x - 如何在python中通过请求传递参数或cookie?