pzavolinsky / ts-unused-exports

ts-unused-exports finds unused exported symbols in your Typescript project
MIT License
749 stars 49 forks source link

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

Open Sheraff opened 1 year ago

Sheraff commented 1 year ago

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

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 commented 5 months ago

Possibly this is fixed in 10.2.0 - via #300

alexander7161 commented 4 months ago

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?