microsoft / microsoft/TypeScript
Add TS server command for removing all unused code in a file
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search terms
- code action
- source action
- getCombinedCodeFix
Feature request
Add a new TS Server command that removes all unused code in a file. This should only perform 'safe' removals, such as:
- Unreachable code
- Unused imports
- Unused declarations
We should likely not remove unused parameters. Not sure about removing unused variable since removing them can also have side effects
Use case
VS Code allows users to configure code actions that are run on save. One of the supported code actions is source.removeUnused which attempts to remove unused code in a file
On the VS Code side, we can't implement this very well since unused code often ends up overlapping with other unused code and we don't have much insight into what is "safe" to remove and what is not
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing TS Server commands and the getCombinedCodeFix path mentioned in the issue, then compare how VS Code invokes source.removeUnused. Done means a command removes only safe unreachable code, unused imports, and unused declarations while leaving parameters and potentially side-effectful variables untouched.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100