Reactjs 为开玩笑而设置lint
我得试着用皮棉搭一辆哈士奇。起初,我试图像下面这样设置,但这不起作用Reactjs 为开玩笑而设置lint,reactjs,eslint,husky,lint-staged,Reactjs,Eslint,Husky,Lint Staged,我得试着用皮棉搭一辆哈士奇。起初,我试图像下面这样设置,但这不起作用 "lint-staged": { "*.js": [ "prettier --write", "eslint src/ --fix", "npm run test", "git add" ] } 然后,经过一些搜索,我将设置更改为以下,但这再次报告了差异错误 "lint-staged": { "*.js": [ "prettier --w
"lint-staged": {
"*.js": [
"prettier --write",
"eslint src/ --fix",
"npm run test",
"git add"
]
}
然后,经过一些搜索,我将设置更改为以下,但这再次报告了差异错误
"lint-staged": {
"*.js": [
"prettier --write",
"eslint src/ --fix",
"jest --bail --findRelatedTests",
"git add"
]
}
错误描述
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation to specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
当我在终端中运行npm运行测试时,它工作正常。那么,为什么它不使用“lint”呢。我做错什么了吗
mypackage.json
{
"name": "myproject",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-redux": "^6.0.1",
"react-router-dom": "^5.0.0",
"react-scripts": "2.1.8",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"standard-http-error": "^2.0.1",
"styled-components": "^4.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"husky": "^1.3.1",
"install": "^0.12.2",
"lint-staged": "^8.1.5",
"prettier": "1.16.4"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"prettier --write",
"eslint src/ --fix",
"jest --bail --findRelatedTests",
"git add"
]
}
}
lint staged glob模式仅设置为在root上的*.js文件上运行。您必须将其更改为**/*.js才能在项目中包含所有*.js文件
"lint-staged": {
"**/*.js": [
"prettier --write",
"eslint src/ --fix",
"jest --bail --findRelatedTests",
"git add"
]
}
lint staged glob模式仅设置为在root上的*.js文件上运行。您必须将其更改为**/*.js才能在项目中包含所有*.js文件
"lint-staged": {
"**/*.js": [
"prettier --write",
"eslint src/ --fix",
"jest --bail --findRelatedTests",
"git add"
]
}
使用createreact应用程序意味着您必须使用React脚本进行测试,因为它们具有缺少jest的babel配置 使用react脚本测试设置husky lint,避免弹出和配置您自己的babel和jest 使用包cross env,它将允许我们在当前所处的任何环境中配置CI环境变量 安装时使用:
yarn add --dev cross-env
或
然后,在package.json上应该有如下内容:
{
"scripts" {
...,
"lint": "eslint src --fix"
"test": "cross-env CI=true react-scripts test --env=jsdom",
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"**/*.js": [
"yarn lint",
"yarn test"
]
},
}
如果您使用的是npm,您可以将纱线测试更改为npm运行测试,皮棉也是如此
希望有帮助 使用Create-React应用程序意味着您必须使用React脚本进行测试,因为它们的babel配置中缺少jest 使用react脚本测试设置husky lint,避免弹出和配置您自己的babel和jest 使用包cross env,它将允许我们在当前所处的任何环境中配置CI环境变量 安装时使用:
yarn add --dev cross-env
或
然后,在package.json上应该有如下内容:
{
"scripts" {
...,
"lint": "eslint src --fix"
"test": "cross-env CI=true react-scripts test --env=jsdom",
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"**/*.js": [
"yarn lint",
"yarn test"
]
},
}
如果您使用的是npm,您可以将纱线测试更改为npm运行测试,皮棉也是如此
希望有帮助 多亏了这篇文章,我得到了这个解决方案。多亏了这篇文章,我得到了这个解决方案。