Eslint-plugin-import: import/namespace does not support shadowing

Created on 24 Aug 2016  路  4Comments  路  Source: benmosher/eslint-plugin-import

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

bug help wanted semver-minor

Most helpful comment

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

All 4 comments

Yep. 馃槄

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

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

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leonid-bauxy picture leonid-bauxy  路  3Comments

daltonamitchell picture daltonamitchell  路  3Comments

xiaodi0003 picture xiaodi0003  路  3Comments

silvenon picture silvenon  路  3Comments

AndrewLeedham picture AndrewLeedham  路  3Comments