pzavolinsky / ts-unused-exports

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

feat: get all files by their exports are unused #254

Closed brandonxiang closed 1 year ago

brandonxiang commented 1 year ago

253

mrseanryan commented 1 year ago

Thank you for the PR.

Can you please add an itest to cover.

This involves adding another example under ./example and then adding a call in:

ispec/run.sh


Also, please add an entry at top of CHANGELOG.md

mrseanryan commented 1 year ago

Also to show the output - need to extend cli.ts

Unless the silent option is on, then we should display the "completely unused files".

Those can be shown, after the existing messages.

mrseanryan commented 1 year ago

TODO - fix so the itests pass

(should not need to change the itests)

Probably this can be fixed by updating cli.ts

brandonxiang commented 1 year ago

OK, I will spend some time to refactor that code.

mrseanryan commented 1 year ago

good, I will look again when you push

brandonxiang commented 1 year ago
image

I have a confused whether I should put the completelyUnused attribute inside the Analysis Object.

Whether I should use the original analysis function?

mrseanryan commented 1 year ago

I have a confused whether I should put the completelyUnused attribute inside the Analysis Object. Whether I should use the original analysis function?

Let's add it to the Analysis type, as optional. Like:

export interface Analysis {
  [index: string]: ExportNameAndLocation[];
  unusedFiles?: string[]; // <<<<<<
}

Then, we can still just export 1 function, as before:

export default (
  files: File[],
  extraOptions?: ExtraCommandLineOptions,
): Analysis => {
 // (existing code)
 // ...

 if (extraOptions.findCompletelyUnusedFiles) // <<<
   analysis.unusedFiles = getUnusedFiles(files, extraOptions);  // <<<

return analysis;
}

This extends the API rather than changes it, which is less risky and is easier for users to pick up...

mrseanryan commented 1 year ago

TODO:

brandonxiang commented 1 year ago
  1. I have put the unusedFiles logic into the analysis function. All calculation is only only.
  2. I have written the itest by cucumber-js and finished the doc
mrseanryan commented 1 year ago
mrseanryan commented 1 year ago

hi brandonxiang

There were a couple of things I wanted to tidy up (and also avoid adding lodash) so I just made a new PR.

It is merged!

Will release shortly, as new Major version.

Thank you for contributing !