create-react-app创建的项目的eslint配置问题

创建项目后,执行了npm run eject显示隐藏文件,安装了eslint-config-airbnb-base,然后创建了三个文件.editorconfig、.eslintignore、.eslintrc.js,结果atom报错,开启开发工具看,报错是

D:\UPUPW\htdocs\LotteryAPP_MS\01Code\partner_react\node_modules\eslint-config-airbnb-base\rules\style.js:
    Configuration for rule "indent" is invalid:
    Value "[object Object]" should NOT have additional properties.

几个文件内容如下
.editorconfig

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

.eslintignore

public/*.js
config/*.js
scripts/*.js

.eslintrc.js

module.exports = {
  root: true,
  parser: 'babel-eslint',
  parserOptions: {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    },
  },
  extends: 'airbnb-base',
  // required to lint *.vue files
  plugins: [
    'react'
  ],
  // add your custom rules here
  'rules': {
    'import/extensions': ['error', 'always', {
      'js': 'never',
    }],
    'radix': 0,
    'global-require': 0,
    'import/no-dynamic-require': 0,
  },
  "env": {
      "browser": true
  },
  "globals": {
  },
}

求教这是为什么

阅读 7.4k
3 个回答

似乎是eslint版本问题,我重新create-react-app,创建的项目eslint及其相关包的版本都是不同的,此时再用eslint-config-airbnb-base就正常了
之前的eslint相关包的版本

    "eslint": "4.4.1",
    "eslint-config-airbnb-base": "^12.1.0",
    "eslint-config-react-app": "^2.0.1",
    "eslint-loader": "1.9.0",
    "eslint-plugin-flowtype": "2.35.0",
    "eslint-plugin-import": "2.7.0",
    "eslint-plugin-jsx-a11y": "5.1.1",
    "eslint-plugin-react": "7.1.0",

重新生成的项目中eslint相关包的版本

    "eslint": "4.10.0",
    "eslint-config-airbnb-base": "^12.1.0",
    "eslint-config-react-app": "^2.0.1",
    "eslint-loader": "1.9.0",
    "eslint-plugin-flowtype": "2.39.1",
    "eslint-plugin-import": "2.8.0",
    "eslint-plugin-jsx-a11y": "5.1.1",
    "eslint-plugin-react": "7.4.0",

从错误提示看,说的是 indent 的配置是无效的,检查 indent 的配置,删除试试好用不

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题