Microsoft/TypeScript

Update import/export specifier sort on rename

Open

#57.975 aperta il 27 mar 2024

Vedi su GitHub
 (7 commenti) (1 reazione) (0 assegnatari)TypeScript (6726 fork)batch import
Experience EnhancementHelp WantedSuggestion

Metriche repository

Star
 (48.455 star)
Metriche merge PR
 (Merge medio 6g 17h) (9 PR mergiate in 30 g)

Descrizione

🔍 Search Terms

organizeImports import sort rename

✅ Viability Checklist

⭐ Suggestion

Renaming an exported function that is imported as one of many named imports can make that list of import specifiers become unsorted. When we execute auto-imports, we try to detect how/whether an existing list of named imports is currently sorted and insert the new specifier in the correct spot. We could do something similar when updating an import or export specifier during a Rename command.

📃 Motivating Example

We have an eslint rule that enforces import sort order. I just renamed a function impliedNodeFormatForEmit to getImpliedNodeFormatForEmit, and afterwards I had to go fix the eslint rule failure in 6 different files. It would be nice not to have to do that.

💻 Use Cases

  1. What do you want to use this for? Easier refactoring that doesn't make linters mad
  2. What shortcomings exist with current approaches? They require me to do a lot of tedious clicking around
  3. What workarounds are you using in the meantime? A lot of tedious clicking around

Guida contributor