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

ignoreLocallyUsed doesn't always work, depends on *where* it is locally used #299

Open
Sheraff opened this issue Nov 15, 2023 · 5 comments

Comments

@Sheraff
Copy link

Sheraff commented Nov 15, 2023

TL;DR: ignoreLocallyUsed does not work when the export is used in

  • { foo: a };
  • ${a};
  • <div>{a}</div>;

Reproduction: https://stackblitz.com/edit/ts-unused-exports-object-key-yuxcdk?file=src%2Fexports.jsx

Example:

export const a = 1

export default function hello() {
  return { foo: a }
}

In the code sample above, if a is not imported anywhere, even with the --ignoreLocallyUsed option it will be reported as unused.


PS: I'm willing to work on a PR, I'm used to playing with ASTs, but only those like ESLint's and not the ts stuff. So I'd love a little guidance for where to look.

@mrseanryan
Copy link
Collaborator

hi @Sheraff thank you for reporting

A PR would be great.

There are BDD style tests here for that feature
so that’s probably a place to start

https://github.com/pzavolinsky/ts-unused-exports/blob/master/features/ignore-locally-used.feature

Additionally there are e2e tests here that we add for some cases

https://github.com/pzavolinsky/ts-unused-exports/tree/master/example

thank you
sean

@Sheraff
Copy link
Author

Sheraff commented Nov 15, 2023

@mrseanryan How do you run the tests? Sorry I'm mostly familiar with the jest/vitest/playwright family of test syntax. I tried making a failing test (in both the cucumber syntax and the shell E2E syntax) and couldn't make them fail...

@mrseanryan
Copy link
Collaborator

to run the tests see https://github.com/pzavolinsky/ts-unused-exports/blob/master/CONTRIBUTING.md

if you get stuck, push a pr anyway, i could have a look at weekend

@mrseanryan
Copy link
Collaborator

Possibly this is fixed in 10.2.0 - via #300

@alexander7161
Copy link

For me upgrading to 10.1.0 caused ts-unused-exports to stop reporting any unused exports when ignoreLocallyUsed is enabled. I had to downgrade to 10.0.1

Anyone else have the same issue?

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

No branches or pull requests

3 participants