import-js/eslint-plugin-import

`named` rule not working

Open

#901 创建于 2017年7月21日

在 GitHub 查看
 (10 评论) (2 反应) (0 负责人)JavaScript (1,540 fork)batch import
bughelp wanted

仓库指标

Star
 (4,946 star)
PR 合并指标
 (平均合并 138天 22小时) (30 天内合并 3 个 PR)

描述

Hi,

First off, thanks for the great plugin. The named rule doesn't seem to be working for me (at least as expected) while others do.

Context

package.json

 $ egrep 'eslint-.*import' package.json

    "eslint-import-resolver-webpack": "^0.8.3",
    "eslint-plugin-import": "^2.7.0",

.eslintrc

{
    "parser": "babel-eslint",
    ...
    "settings": {
        ...
        "import/resolver": {
            "webpack": {
                "config": "webpack.prod.config.js"
            }
        }
    },
    ...
    "extends": [
         ...
        "plugin:import/errors",
        "plugin:import/warnings"
    ],
    "rules": {
        "max-len": ["error", 80, 2, { "ignoreUrls": true }],

        // Don't warn us about using console.log (though that should only
        // happen in the dev environment).
        "no-console": [0]
    },
    ...
}

Issue

I've got a file with the following contents

import { logToSentry, butts } from './errors'

const errorAlert = (msg, err) => {
  logToSentry(msg, err);
  butts();
}

As you can probably imagine, butts doesn't exist in ./errors and certainly isn't exported. Eslint raises no issue about this.

However, I know that eslint-plugin-import is doing something because if I change ./errors to a path that doesn't exist, I get the following output from eslint:

/code/actions.jsx
  5:36  error  Unable to resolve path to module './errorsDoesntExist'  import/no-unresolved

✖ 1 problem (1 error, 0 warnings)

So why would one rule be working (import/no-unresolved) but not the other (import/named)? Any guidance is much appreciated.

贡献者指南