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

[no-unused-modules] Dynamic import doesn't mark exports as used #1951

Closed
phaux opened this issue Nov 19, 2020 · 3 comments · Fixed by #1660
Closed

[no-unused-modules] Dynamic import doesn't mark exports as used #1951

phaux opened this issue Nov 19, 2020 · 3 comments · Fixed by #1660

Comments

@phaux
Copy link

phaux commented Nov 19, 2020

Repro:

// foo.ts
export const foo = "foo"

// index.ts
async function test() {
  const { foo } = await import("./foo")
  const foo2 = await import("./foo").then(mod => mod.foo)
  const mod = await import("./foo") // should mark all non-type exports as used
}

My specific use case is:

import { lazy } from "react"
const Foo = lazy(() => import("./Foo"))

exported declaration 'foo' not used within other modules

Config:

{
  "extends": [
    "plugin:import/recommended",
    "plugin:import/typescript",
    // and more ...
  ],
  "rules": {
    "import/no-unused-modules": ["error", { "unusedExports": true }],
  },
}

Versions:

@typescript-eslint/parser: 4.8.0
eslint: 7.13.0
eslint-plugin-import: 2.22.1
@ljharb
Copy link
Member

ljharb commented Jan 22, 2021

This was intentional during the design of the rule (#1142, cc @rfermann).

When a dynamic import is done with a static, hardcoded path, it does seem possible for this plugin to detect it, but it would have to ignore any other forms of import(). A PR that detects these would be appreciated.

@taoliujun
Copy link

me too.
components are lazy imported.

@silverwind
Copy link
Contributor

Related PR: #1660

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

Successfully merging a pull request may close this issue.

4 participants