applying fixes can create syntactically invalid code.
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 232
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
I've been trying to use ts-fix to add annotations for isolatedDeclarations and I've run into a few cases where the fixers are not correctly merged together.
The most obvious example I've seen is when multiple imports need to be added from a module
// before fixing:
import type {
A as B,
C,
D as E,
F as H,
H,
I,
J,
} from './mod1';
// after fixing -- syntax errors and duplicate imports
import type {
A as B,
C,
D as E,
F as H,
H,
I,
J,
H // missing commas
I // missing commas
J // missing commas
K // missing commas
L // missing commas
M,
} from './mod1';
import { N } from './mod2';
import { JSX } from 'react/jsx-runtime';
import { O, P } from './mod3';
import { N } from './mod2'; // duplicate import
This of course makes at-scale codemodding difficult because many files will need to be fixed up by hand.
It's worth noting that if I manually open the file in VSCode and select the Add all missing type annotations quick fix:
Then the resulting file is syntactically correct.
Which suggests that TS has a built-in mechanism for merging the fixes to produce valid code.
It would be great if we could switch to use this mechanism.
Contributor guide
No contributing guide indexed for this repository
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 reproducing the multiple-import example through the ts-fix CLI and compare it with VSCode's “Add all missing type annotations” quick fix. Investigate how multiple fixes are merged, then verify that the output remains syntactically valid and does not contain missing commas or duplicate imports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100