pzavolinsky / ts-unused-exports

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

False positive with path aliases and sub-folders #154

Closed ilyin371 closed 1 year ago

ilyin371 commented 4 years ago

Steps to reproduce with example\with-paths:

  1. Move utils\src\calculations.ts into a new sub-folder utils\src\sub\calculations.ts.
  2. Update import statement in math.ts to import {calculations} from 'utils/sub/calculations';
  3. Run ts-unused-exports example\with-paths\tsconfig.json
  4. utils\src\sub\calculations.ts: calculations is falsely reported as unused.
mrseanryan commented 4 years ago

Thank you for reporting it

mrseanryan commented 4 years ago

hi @ilyin371 - I cannot repro this issue.

I pushed a branch where I try the above, but it seems to work OK for me!

branch = scratch/path-alias-issue-154

cd example/with-paths
node ../../bin/ts-unused-exports tsconfig.json

OUTPUT:

.../example/with-paths/math.ts: add1

(calculations.ts does NOT appear as unused)

mrseanryan commented 4 years ago

@ilyin371 is there something about your tsconfig.json file ? :thinking:

mrseanryan commented 4 years ago

My tsconfig.json is:

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "es5",
    "noEmit": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "moduleResolution": "node",
    "paths": {
      "utils": ["utils/src"],
      "utils/*": ["utils/src/*"]
    }
  }
}
kevinoliveira commented 4 years ago

same issue here, I can confirm it's due to path aliases. i can create a reproducible environment later today.

PS: awesome project

mrseanryan commented 4 years ago

@kevinoliveira if you can post example or even better make a fork with working example, that would be great!

kevinoliveira commented 4 years ago

@mrseanryan i hope this can be useful https://github.com/kevinoliveira/ts-unused-exports-issue-154-example

mrseanryan commented 4 years ago

cheers @kevinoliveira

I think it is related to the #customAlias part:

import { sayHelloWorldInJapanese } from "#customAlias/helpers";

This helps a lot!

mrseanryan commented 4 years ago

@ilyin371 @kevinoliveira have a fix here:

https://github.com/pzavolinsky/ts-unused-exports/pull/176

If you have the time, it would great to get feedback before we merge and release.

Branch is:

fix/path-aliases-and-sub-folders

mrseanryan commented 4 years ago

fixed in 7.0.0

kevinoliveira commented 4 years ago

@mrseanryan sorry for the delay, there are no more false positives.

aryzing commented 1 year ago

@mrseanryan has it been resolved? I seem to be having the same issue with the latest version.

In the repro below, there's a single export foo being reported as unused, despite it clearly being used, https://github.com/aryzing/practice-ts-unused-exports

aryzing commented 1 year ago

Seems to be related to the fact that the file imported is the index file. I've noticed that in the past there have been several issues related to index-related false positives, so may be a regression?

mrseanryan commented 1 year ago

@aryzing thanks for reporting. This is about the @ part of the import which is not something supported.

import { foo } from "@foo/index";

Opening as a new issue ...

mrseanryan commented 1 year ago

UPDATE:

Ineed, the problem is the file being imported is index Another very similar file other works OK.

but at this point its simpler for me to manage, as a separate related issue.