Repository: import-js/eslint-plugin-import (JavaScript)

Issue:
[BUG] `import/no-unused-modules` does not work with `import { name as otherName }`
When using `import { ... as ... }` statements, `import/no-unused-modules` does not seem to properly work.

In the following example, `test` export is used, but it's still reported as not used:

```
$ eslint .
/home/ehmicky/no-unused-modules-bug/src/file.js
  1:1  error  exported declaration 'test' not used within other modules  import/no-unused-modules

✖ 1 problem (1 error, 0 warnings)
```

`src/main.js`:

```js
import { test as testTwo } from './file.js'
```

`src/file.js`:

```js
export const test = true
```

`.eslintrc.json`:

```json
{
  "parserOptions": {
    "ecmaVersion": 2019,
    "sourceType": "module"
  },
  "plugins": ["import"],
  "rules": {
    "import/no-unused-modules": [
      2,
      {
        "unusedExports": true,
        "ignoreExports": ["src/main.js"]
      }
    ]
  }
}
```

`package.json`:

```json
{
  "name": "no-unused-modules-bug",
  "version": "1.0.0",
  "dependencies": {},
  "devDependencies": {
    "eslint": "^5.16.0",
    "eslint-plugin-import": "^2.17.2"
  }
}
```

Note: removing the `ignoreExports: ["src/main.js"]` does not fix this issue.


Discussion:
cc @rfermann 
Thanks a lot for the quick response!

However it seems like this bug is still happening. If you publish a new version of this library, I can create a demo repository.

In the meantime, you should be able to re-create this bug by copying the files as described above.
@ehmicky: a demo repo would be great. 
Sure I can do that tomorrow morning (I'm off my laptop for the night).

The repo will use the latest published version though, so won't include your first fix. But if you manually edit the dependency, you should see that this fix does not modify the behavior unfortunately.
Demo repo: https://github.com/ehmicky/no-unused-modules-bug
Thanks for the repo. As it turned out, I missed one piece of code :sweat_smile:
It works, thanks @rfermann! :tada: 



Patch:
diff --git a/src/ExportMap.js b/src/ExportMap.js
index b533946fa2..8513e3d395 100644
--- a/src/ExportMap.js
+++ b/src/ExportMap.js
@@ -405,7 +405,7 @@ ExportMap.parse = function (path, content, context) {
           importedSpecifiers.add(specifier.type)
         }
         if (specifier.type === 'ImportSpecifier') {
-          importedSpecifiers.add(specifier.local.name)
+          importedSpecifiers.add(specifier.imported.name)
         }
       })
     }


Test patch:
diff --git a/tests/files/no-unused-modules/file-h.js b/tests/files/no-unused-modules/file-h.js
index b38d70e548..60b542e179 100644
--- a/tests/files/no-unused-modules/file-h.js
+++ b/tests/files/no-unused-modules/file-h.js
@@ -4,4 +4,6 @@ function h2() {
   return 3
 }
 
-export { h1, h2 }
+const h3 = true
+
+export { h1, h2, h3 }
diff --git a/tests/files/no-unused-modules/file-p.js b/tests/files/no-unused-modules/file-p.js
new file mode 100644
index 0000000000..60f3fbae46
--- /dev/null
+++ b/tests/files/no-unused-modules/file-p.js
@@ -0,0 +1,1 @@
+import { h3 as h0 } from './file-h'
\ No newline at end of file
diff --git a/tests/src/rules/no-unused-modules.js b/tests/src/rules/no-unused-modules.js
index fa4b59b303..8069479ae5 100644
--- a/tests/src/rules/no-unused-modules.js
+++ b/tests/src/rules/no-unused-modules.js
@@ -118,7 +118,7 @@ ruleTester.run('no-unused-modules', rule, {
            filename: testFilePath('./no-unused-modules/file-g.js'),
            errors: [error(`exported declaration 'g' not used within other modules`)]}),
     test({ options: unusedExportsOptions,
-           code: 'const h1 = 3; function h2() { return 3 }; export { h1, h2 }',
+           code: 'const h1 = 3; function h2() { return 3 }; const h3 = true; export { h1, h2, h3 }',
            filename: testFilePath('./no-unused-modules/file-h.js'),
            errors: [error(`exported declaration 'h1' not used within other modules`)]}),
     test({ options: unusedExportsOptions,