You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: preserve user content in all modes + address audit 4 bugs
Golden rule: never silently delete user code or comments.
Code preservation:
- Preserve non-comment code between imports (moved after organized block)
- Both modes now keep code that was between import statements
Comment preservation (planned difference from old extension):
- Stop stripping specifier comments in legacy mode
- Old extension lost comments because its parser couldn't parse them
- Our parser (ts-morph) can, so stripping is unnecessary content deletion
- Comments now trigger multiline wrapping in all modes
Audit 4 bug fixes:
- B1: Fix greedy regex in extractSpecifierComments (.+ → .+?)
- B2: Only write legacyMode to workspace folders that had old settings
- B3: findFiles now respects files.exclude (undefined instead of null)
- B4: Multiline wrap threshold measures full import line, not just braces
- B5+B6: Support .mts/.cts/.mjs/.cjs file extensions
Updated comparison tests to reflect planned differences.
Documented golden rule exceptions in CLAUDE.md.
Copy file name to clipboardExpand all lines: CLAUDE.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -501,6 +501,24 @@ All commands are prefixed with `miniTypescriptHero`:
501
501
**New Users**: Get `legacyMode: false` by default for modern best practices (1 blank line, correct sorting, proper merge timing)
502
502
**Note**: See README for specific behaviors replicated and exceptions. Both old and new extensions merge imports by default; legacy mode preserves the old merge-before-removeTrailingIndex timing that can create duplicates.
503
503
504
+
### 5. Planned Differences from Old Extension (Golden Rule: Never Delete User Content)
505
+
506
+
Legacy mode replicates old formatting behaviors, but we **intentionally diverge** where the old behavior is harmful. The golden rule is: **never silently delete user code or comments**.
| Specifier comments lost (`// comment`, `/* comment */` next to specifiers) |**Preserved** — comments stay with their specifiers, trigger multiline wrapping | Old parser (typescript-parser) couldn't parse specifier comments; our parser (ts-morph) can, so stripping is unnecessary deletion of user content |
511
+
| Non-comment code between import statements silently deleted during reorganization |**Preserved** — code is moved after the organized import block | Old extension deletes imports individually (preserving gaps), our whole-range replacement is a regression without this fix |
512
+
| Crashes on certain edge cases (shebangs, directives, empty files) |**Gracefully handled**| Already documented — crash prevention is always correct |
513
+
514
+
**Legacy mode DOES replicate these formatting-only behaviors:**
515
+
- Strip `import type` keywords (matches old output format, TypeScript 3.8+ wasn't supported)
516
+
- Strip specifier-level `type` modifiers (matches old output format)
517
+
- Within-group sorting always by library name (never by first specifier)
518
+
- Blank line preservation mode (special handling for headers and leading blanks)
519
+
- Merge timing: merge before removeTrailingIndex (matches old quirk)
520
+
- 4-space indentation from VS Code editor.tabSize default
0 commit comments