簡體   English   中英

進口中的掉毛錯誤

[英]linting error in imports

我收到有關 linting 的各種錯誤。 所有錯誤都顯示在第一行代碼中。 導入方式不正確,但仍然出現 linting 錯誤。 我應該如何修復以下錯誤?

1:1 錯誤定義 'import/no-named-default' 規則未找到 import/no-named-default

未找到規則“re​​act/jsx-tag-spacing”的 1:1 錯誤定義 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 源

{
  "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": {}
}

我認為您忘記將插件eslint-plugin-reacteslint-plugin-import 添加到您的項目或您的 eslint 配置中。

編輯:

在你的.eslintrc plugins 字段中應該是這樣的:

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

你的 .eslintrc 規則字段應該是這樣的:

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

這將修復 react/no-array-index 錯誤。 確保你已經安裝了 eslint-plugin-react。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM