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

Feature request: --fix mode to automatically remove unused exports #23

Closed
emlai opened this issue Jun 26, 2019 · 7 comments
Closed

Feature request: --fix mode to automatically remove unused exports #23

emlai opened this issue Jun 26, 2019 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@emlai
Copy link

emlai commented Jun 26, 2019

No description provided.

@nadeesha
Copy link
Owner

Thanks for reporting this. Unfortunately, any kind of source file manipulation is a non-goal of this package.

Typescript compiler APIs have gaps when trying to infer unused-ness already. I'm wary of changing source files when we have potentially incorrect information. See #22 and #14.

@emlai
Copy link
Author

emlai commented Jun 27, 2019

False positives are not a huge issue as the changes can be reviewed using version control, and the incorrect removals can easily be reverted, and also TypeScript type-checking will let us know if we removed something that's actually still used somewhere. But I can understand if this is a non-goal, especially at this point. 👍

@pelotom
Copy link

pelotom commented Jul 15, 2019

Just to clarify @nadeesha, is this a non-goal because it is a larger undertaking than you personally want to invest in, or is it truly something you think should not be within scope for this project? The real question being, would you accept an outside contribution which added this feature? I think @emlai is correct that there is relatively low risk in such a feature even in the presence of false positives, due to type checking + version control. It would be a huge time saver if instead of having to go through hundreds of exports and remove them by hand, the task was to restore a handful of erroneously removed exports until everything compiled.

@nadeesha nadeesha reopened this Jul 15, 2019
@nadeesha
Copy link
Owner

@pelotom I did initially see this as a non-goal. But I see more and more people like yourself and @emlai using this in larger projects. Therefore, I do see the value in making this a goal, of sorts.

So, yes, I'd accept a PR if this was done cautiously.

@nadeesha nadeesha added the enhancement New feature or request label Jul 15, 2019
@pelotom
Copy link

pelotom commented Jul 15, 2019

Not saying I have time to do this either at the moment, but I didn't want potential contributors to see this issue and be discouraged from making a PR unless you were really against it 🙂

@nadeesha
Copy link
Owner

nadeesha commented Oct 19, 2019

I'll accept a PR for this - if done correctly. However, due to the limitations of the APIs, we're only heuristically matching certain use cases. Therefore, I'm not sure we can ever have a exhaustive list and cover all of the scenarios to make sure a --fix option would be safe.

Another option would be to implement a --fix that

  1. Comments out the imports with a prefix // ts-prune-fix
  2. Does a compile step
  3. After the compile step:
    • On successful compile removes all the // ts-prune-fix or,
    • On failure, reports the errors and uncomments the // ts-prune-fix lines

But that's a much bigger undertaking.

I'm open to anyone jumping on this thread, or opening a new one if there's enough interest. Closing for now.

@phiresky
Copy link
Contributor

phiresky commented Jul 3, 2020

I didn't see this issue when I implemented it, but there's a working implementation in #67. Putting this here so it's cross-linked. It doesn't fulfill all the above mentioned properties, but it's still useful enough.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants