导入中的linting错误

时间:2017-05-20 04:00:59

标签: javascript reactjs eslint create-react-app

我有关于linting的各种错误。所有错误都显示在第一行代码中。导入方式不正确但仍然会出现linting错误。我该如何修复以下错误?

  

1:1错误定义规则' import / no-named-default'未找到import / no-named-default

     

1:1错误定义规则' react / jsx-tag-spacing'未找到react / jsx-tag-spacing

     

1:1错误定义规则' react / no-array-index-key'未找到react / no-array-index-key

     

1:1错误定义规则' react / require-default-props'未找到react / require-default-props

import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers';

const enhancers = [applyMiddleware(thunk)];

// If Redux DevTools Extension is installed use it, otherwise use Redux compose
/* eslint-disable no-underscore-dangle */
const composeEnhancers = process.env.NODE_ENV === 'development' && typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
  ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
  : compose;

export default(initialState) => createStore(rootReducer, initialState, composeEnhancers(...enhancers));

这里是eslint source

{
  "parser": "babel-eslint",
  "extends": "airbnb",
  "env": {
    "browser": true,
    "node": true,
    "jest": true,
    "es6": true
  },
  "plugins": [
    "react",
    "jsx-a11y"
  ],
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "rules": {
    "import/imports-first": 0,
    "import/newline-after-import": 0,
    "import/no-dynamic-require": 0,
    "import/no-extraneous-dependencies": 0,
    "import/no-named-as-default": 0,
    "import/no-unresolved": 2,
    "import/prefer-default-export": 0,
    "indent": [
      2,
      2,
      {
        "SwitchCase": 1
      }
    ],
    "jsx-a11y/aria-props": 2,
    "jsx-a11y/heading-has-content": 0,
    "jsx-a11y/href-no-hash": 2,
    "jsx-a11y/label-has-for": 2,
    "jsx-a11y/mouse-events-have-key-events": 2,
    "jsx-a11y/role-has-required-aria-props": 2,
    "jsx-a11y/role-supports-aria-props": 2,
    "max-len": 0,
    "newline-per-chained-call": 0,
    "no-confusing-arrow": 0,
    "no-console": 1,
    "no-use-before-define": 0,
    "prefer-template": 2,
    "class-methods-use-this": 0,
    "react/forbid-prop-types": 0,
    "react/jsx-first-prop-new-line": [
      2,
      "multiline"
    ],
    "react/jsx-filename-extension": 0,
    "react/jsx-no-target-blank": 0,
    "react/require-extension": 0,
    "react/self-closing-comp": 0,
    "require-yield": 0,
    "import/no-webpack-loader-syntax": 0
  },
  "settings": {}
}

3 个答案:

答案 0 :(得分:1)

我认为您忘了将插件eslint-plugin-reacteslint-plugin-import添加到您的项目或您的eslint配置中。

编辑:

.eslintrc插件字段中应该是这样的:

"plugins": [
  "react",
  "jsx-a11y",
  "import"
],

答案 1 :(得分:1)

你的.eslintrc规则字段应该是这样的:

"rules":{
"react/no-array-index-key":"off",
}

这将修复react / no-array-index错误。确保安装了eslint-plugin-react。

答案 2 :(得分:1)

使用import rootReducer from 'reducers';而不是import rootReducer from './reducers';