Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve eslint import/no-named-as-default

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.

I have the following file structure

. ├── ButtonBack.css ├── ButtonBack.jsx ├── __tests__ │   └── ButtonBack.test.jsx └── index.js 

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 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 ... 

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

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.

like image 241
mrbinky3000 Avatar asked Jun 08 '17 13:06

mrbinky3000


People also ask

What is import no named as default?

Reports use of an exported name as a property on the default export. Rationale: Accessing a property that has a name that is shared by an exported name from the same module is likely to be a mistake.

What does Eslint plugin Import do?

This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import names. All the goodness that the ES2015+ static module syntax intends to provide, marked up in your editor.


1 Answers

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)

"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

"rules": {     "import/no-named-as-default": 0 } 
like image 103
Gregory Nowakowski Avatar answered Sep 28 '22 05:09

Gregory Nowakowski