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

[BUG] import/no-unused-modules does not work with import { name as otherName } #1339

Closed
ehmicky opened this issue Apr 21, 2019 · 7 comments · Fixed by #1340 or #1342
Closed

[BUG] import/no-unused-modules does not work with import { name as otherName } #1339

ehmicky opened this issue Apr 21, 2019 · 7 comments · Fixed by #1340 or #1342

Comments

@ehmicky
Copy link

ehmicky commented Apr 21, 2019

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:

import { test as testTwo } from './file.js'

src/file.js:

export const test = true

.eslintrc.json:

{
  "parserOptions": {
    "ecmaVersion": 2019,
    "sourceType": "module"
  },
  "plugins": ["import"],
  "rules": {
    "import/no-unused-modules": [
      2,
      {
        "unusedExports": true,
        "ignoreExports": ["src/main.js"]
      }
    ]
  }
}

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

@ljharb
Copy link
Member

ljharb commented Apr 21, 2019

cc @rfermann

@ehmicky
Copy link
Author

ehmicky commented Apr 21, 2019

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.

@rfermann
Copy link
Contributor

@ehmicky: a demo repo would be great.

@ljharb ljharb reopened this Apr 21, 2019
@ehmicky
Copy link
Author

ehmicky commented Apr 21, 2019

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.

@ehmicky
Copy link
Author

ehmicky commented Apr 22, 2019

Demo repo: https://github.com/ehmicky/no-unused-modules-bug

@rfermann
Copy link
Contributor

Thanks for the repo. As it turned out, I missed one piece of code 😅

@ehmicky
Copy link
Author

ehmicky commented Apr 23, 2019

It works, thanks @rfermann! 🎉

@ehmicky ehmicky closed this as completed Apr 23, 2019
@ljharb ljharb reopened this Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment