Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

Is it possible to exclude results that are used within the same file? #38

Closed
mildfuzz opened this issue Jul 19, 2019 · 14 comments · Fixed by #74
Closed

Is it possible to exclude results that are used within the same file? #38

mildfuzz opened this issue Jul 19, 2019 · 14 comments · Fixed by #74
Labels
enhancement New feature or request released

Comments

@mildfuzz
Copy link

I have a lot of what I would consider to be false positives. A method is not being used as in import anywhere, but it being used within the same file. Is there a way to filter these out?

@nadeesha
Copy link
Owner

Thanks for the issue @mildfuzz. Although you might have a legitimate reason to export something that's not being imported elsewhere, the objective of this package is to find unused imports. If you feel like this is a worthwhile addition, I'm keen to hear your reasons.

@emlai
Copy link

emlai commented Jul 24, 2019

+1. I think most users (including me) want to use ts-prune to find dead code. Exported entities used within the same file are not dead code, so we don't care about those cases.

In my opinion, detecting redundant usages of the export keyword doesn't add much value because those cases rarely indicate bugs (in my experience). It just means we need to manually remove the export keyword, which is slightly annoying if we don't care about them. An automatic fix mode as outlined in #23 would make it less of a problem though.

@nadeesha
Copy link
Owner

I'm more than happy to find a way to incorporate this feature if there's enough interest.

@nadeesha nadeesha added the enhancement New feature or request label Jul 28, 2019
@nadeesha
Copy link
Owner

Since I'm not sure we have a viable use-case that might benefit from implementing this, I'm closing it for now.

@thehappycoder
Copy link

I'd like this feature. It's a shame this issue got closed.

@JustFly1984
Copy link

just remove export, if it is not imported anywhere.

@nadeesha
Copy link
Owner

I'd second what @JustFly1984 said. If you're not using it anywhere, I'm not sure why the export keyword should be used.

@mildfuzz
Copy link
Author

mildfuzz commented Jan 26, 2020 via email

@emlai
Copy link

emlai commented Jan 26, 2020

In a large enough codebase, there can be hundreds or thousands of unnecessary exports. Going through all of them manually (due to lack of automatic fixing, #23) to check which ones can safely be removed is not always viable.

@danvk
Copy link
Contributor

danvk commented May 21, 2020

@nadeesha is there an alternative tool you'd recommend for finding unused code (rather than unused exports)?

@nadeesha
Copy link
Owner

@danvk Unfortunately not. That seems to be a much bigger problem :)

@nadeesha
Copy link
Owner

@mildfuzz @emlai I want to bring closure to this issue since it seems I might have closed it a bit prematurely.

The goal of this package is to find unused exports. If the export is used within the same file, there's no reason to export it, IMHO. But I can see that it could be useful to ignore these exports. But on the flip side, someone using this package to find unused exports might expect to find the unnecessary exports as well. For that person, this behaviour change would mean they no longer can find a properly unused export.

The second (unrelated) feature request here is automatic fixing as requested by #23. It's a big enough undertaking and goes against the goal of this package to not modify the source repository in any way. The reason why this is a goal is that due to the limitation of the static analysis, it's impossible to be 100% confident that an import is in-fact, unused. Faulty logic in this package, faulty logic in a dependency, Typescript introducing new syntax would all spell disastrous outcomes for someone who doesn't use a version control properly. Therefore, going by the "first do no harm" principle, I'm not going to attempt it until Typescript supports proper static analysis.

@danvk
Copy link
Contributor

danvk commented May 24, 2020

But I can see that it could be useful to ignore these exports. But on the flip side, someone using this package to find unused exports might expect to find the unnecessary exports as well. For that person, this behaviour change would mean they no longer can find a properly unused export.

@nadeesha are flags against your design goals for this tool? That's a fine choice if they are. But this seems like the sort of dilemma that could be resolved by one.

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 0.7.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants