pzavolinsky / ts-unused-exports

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

Results not reported from Messages.ts file #278

Closed vsobotka closed 1 year ago

vsobotka commented 1 year ago

We have a src/Messages.ts file, containing all localisation messages used in the app in a format like this:

import { defineMessage } from "react-intl";

export const messageLogIn = defineMessage({
  id: "Account.logIn",
  defaultMessage: "Log In",
});

export const messageLogOut = defineMessage({
  id: "Account.logOut",
  defaultMessage: "Log Out",
});

We have a tsconfig

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "jsx": "react-jsx",
    "jsxImportSource": "@emotion/react",
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "allowJs": true,
    "removeComments": true,
    "noEmit": true,
    "isolatedModules": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "useUnknownInCatchVariables": true,
    "alwaysStrict": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "allowUnusedLabels": true,
    "allowUnreachableCode": false,
    "skipDefaultLibCheck": true,
    "skipLibCheck": true
  },
  "include": ["src"]
}

And we run it like npx ts-unused-exports ./tsconfig.json in the root dir. The result does not contain that file, while the IDE can detect more than 150 unused messages.

The Messages.ts has over 10k lines. Maybe that is an issue? Why am I not seeing any results from this file?

mrseanryan commented 1 year ago

hi @vsobotka - thanks for reporting this.

question: how is 'messages.ts' being imported?

For example, does the import statement include the .ts extension? In which case, this could be #281

The file is a bit big - although that should not really be an issue...

vsobotka commented 1 year ago

@mrseanryan Thanks for the reply. I just tried several things to give your more details with examples, and I realized, thanks to your question, we might have had one import * in the project for convenience. After removing that, it works as expected. Obviously. Silly me. Thanks!

vsobotka commented 1 year ago

ts-prune seems to be working with this import though, so it might be a possible feature