Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import/namespace does not support shadowing #518

Closed
Jessidhia opened this issue Aug 24, 2016 · 4 comments
Closed

import/namespace does not support shadowing #518

Jessidhia opened this issue Aug 24, 2016 · 4 comments

Comments

@Jessidhia
Copy link

import/namespace does not detect when something in a closer scope shadows a namespace import, leading to bogus lint warnings.

This example is a bit bigger than necessary, but it is closer to the conditions where I encountered it:

import React, { PropTypes } from 'react'
import { createStructuredSelector } from 'reselect'
import { connect } from 'react-redux'
import * as todos from 'ducks/todos'

const mapStateToProps = createStructuredSelector({
  todos: todos.getTodos
})

const TodoApp = ({
  todos
}) => (
  <ol>
    {/* import/namespace 'map' not found in imported namespace 'todos' */}
    {todos.map(({ id }) => (<li key={id}>{id}</li>))}
  </ol>
)

const connected = connect(mapStateToProps)(TodoApp)
export { connected as TodoApp }

The same thing happens if I change the arrow function to start like props => { const { todos } = props; ..., or even props => { const todos = props.todos; ....

@benmosher
Copy link
Member

Yep. 😅

It's been on my radar for a while, but hasn't come up in practice so it hasn't been a priority.

@dead-claudia
Copy link
Contributor

dead-claudia commented Nov 9, 2017

@benmosher I suspect adding the following line after this line would fix it. Would you agree?

if (declaredScope(context, dereference.object.name) !== 'module') return

penx added a commit to penx/eslint-plugin-import-bug that referenced this issue Jun 23, 2020
@penx
Copy link

penx commented Jun 23, 2020

Issue recreated here:
https://github.com/penx/eslint-plugin-import-bug

import * as color from './color';
export const getBackgroundFromColor = (color) => color.bg;
export const getExampleColor = () => color.example
'bg' not found in imported namespace 'color'. eslintimport/namespace

@ljharb
Copy link
Member

ljharb commented Jun 23, 2020

Thanks to @penx's repro and @isiahmeadows's suggested fix, I've got a fix ready for this :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants