[英]Setting up Airbnb ESLint with React and Webpack
I am trying to set up linting with Airbnb's Javascript standards on my React project, it uses webpack.我正在尝试在我的 React 项目上使用 Airbnb 的 Javascript 标准设置 linting,它使用 webpack。
Updated with latest packages based on comments.根据评论更新了最新的软件包。
"babel-eslint": "^6.1.2",
"eslint": "^3.2.2",
"eslint-config-airbnb": "^10.0.0",
"eslint-plugin-import": "^1.12.0",
"eslint-plugin-jsx-a11y": "^2.0.1",
"eslint-plugin-react": "^6.0.0",
"jshint": "^2.9.2",
"jshint-loader": "^0.8.3",
"json-loader": "^0.5.4",
I also have a preloader setup in my webpack config我的 webpack 配置中也有一个预加载器设置
preLoaders: [
{
test: /\.jsx?$/,
loaders: ['eslint'],
// define an include so we check just the files we need
include: PATHS.app
}
],
And the following set up for running the script以下设置用于运行脚本
"lint": "eslint . --ext .js --ext .jsx --ignore-path .gitignore --cache",
I also have a .eslintrc
file which has the following我还有一个.eslintrc
文件,其中包含以下内容
{
"extends": "airbnb",
"env": {
"node": true,
"es6": true
}
}
This gives me the following error:这给了我以下错误:
Configuration for rule "react/jsx-sort-props" is invalid:
Value "data["0"].shorthandLast" has additional properties.
If i remove the .eslintrc
file which i thought might be conflicting, I get the following error:如果我删除了我认为可能存在冲突的.eslintrc
文件, .eslintrc
出现以下错误:
error Parsing error: The keyword 'const' is reserved
Followed by a npm error which causes the task to exit.接着是一个 npm 错误,导致任务退出。
So, I had the same issue, but I fixed this error using last version of current packages:所以,我遇到了同样的问题,但我使用当前包的最新版本修复了这个错误:
"eslint": "3.2.2",
"eslint-config-airbnb": "10.0.0",
"eslint-loader": "1.5.0",
"eslint-plugin-import": "1.12.0",
"eslint-plugin-jsx-a11y": "2.0.1",
"eslint-plugin-mocha": "2.2.0",
"eslint-plugin-react": "6.0.0",
And please, do this tutorial: React Code Style with ESLint + Babel + Webpack请执行本教程:使用 ESLint + Babel + Webpack 的 React Code Style
module: {
preLoaders: [
{
test: /\.jsx?$/,
loaders: ['eslint-loader'],
include: path.join(__dirname, 'src'),
exclude: path.join(__dirname, 'src/app/container')
}
],
...
eslint: {
configFile: './.eslintrc', //your .eslintrc file
emitWarning: true
}
.eslintrc file .eslintrc 文件
{
"extends": "airbnb"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.