如何解决eslint import / no-named-as-default [英] How do I resolve eslint import/no-named-as-default
问题描述
在查看了import / no-named-as-default eslint规则的文档之后,我仍然对我究竟做错了什么感到困惑。
After looking at the documentation for the import/no-named-as-default eslint rule, I'm still confused about what exactly I'm doing wrong.
我有以下文件结构
.
├── ButtonBack.css
├── ButtonBack.jsx
├── __tests__
│ └── ButtonBack.test.jsx
└── index.js
ButtonBack.jsx包含以下代码
The ButtonBack.jsx contains the following code
import React from 'react';
import PropTypes from 'prop-types';
export default class ButtonBack extends React.Component {
... code removed to keep example short ...
}
__ tests __ / ButtonBack.test.jsx包含以下代码
__tests__/ButtonBack.test.jsx contains the following code
import React from 'react';
import { shallow } from 'enzyme';
import ButtonBack from '../ButtonBack'; // <== this line has an eslint warning
... code removed to keep example short ...
问题是,我的linter说'$ / c $ c>从'../ ButtonBack 导入ButtonBack违反了以下lint规则:
The problem is, my linter says that import ButtonBack from '../ButtonBack
violates the following lint rules:
- import/no-named-as-default
- import/no-named-as-default-member
我无法弄清楚为什么我的import语句违反了lint规则。在ButtonBack.jsx中删除类的名称(导出默认类扩展React.Component
)也不能解决问题。
I can't figure out why my import statement violates the lint rule. Removing the name of the class in ButtonBack.jsx (export default class extends React.Component
) does not solve the issue either.
推荐答案
进入同样的问题,从我所看到的你只需要禁用该规则(那是我至少做了什么)
Ran into this same issue and from what I'm seeing you're going to just have to disable that rule (that's what I did at least)
不幸的是,React + Redux是最常见的情况。但是,还有很多其他情况下HOC会迫使开发人员关闭这个规则。
"Unfortunately, React + Redux is the most common scenario. However, there are lots of other cases where HOCs will force developers to shut down this rule."
https ://github.com/benmosher/eslint-plugin-import/issues/544
https://github.com/reactjs/react-redux/issues/119
https://github.com/18F/calc/pull/1235
.eslintrc
.eslintrc
"rules": {
"import/no-named-as-default": 0
}
这篇关于如何解决eslint import / no-named-as-default的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!