我收到了有关 linting 的各种错误。所有错误都显示在第一行代码中。导入方式没有错误,但仍然出现 linting 错误。我应该如何修复以下错误?
1:1 error Definition for rule 'import/no-named-default' was not found import/no-named-default
1:1 error Definition for rule 'react/jsx-tag-spacing' was not found react/jsx-tag-spacing
1:1 error Definition for rule 'react/no-array-index-key' was not found react/no-array-index-key
1:1 error Definition for rule 'react/require-default-props' was not found 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-react和eslint-plugin-import到您的项目或 eslint 配置。
编辑:
在您的 .eslintrc
插件字段中应如下所示:
"plugins": [
"react",
"jsx-a11y",
"import"
],
关于javascript - 导入中的 linting 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44081764/