Import Sorting
GitAuto automatically sorts import statements alphabetically after the model writes code. The sorter routes to language-specific implementations for Python and JavaScript/TypeScript, ensuring each language's conventions are respected.
Why This Exists
Many projects enforce alphabetical import ordering through linters like ESLint's sort-imports rule or Python's isort. The model generates imports in whatever order it thinks of them, which is almost never alphabetical. Without auto-sorting, the generated code would fail linting on the first CI run, wasting an entire agent iteration just to reorder imports. By sorting after generation, GitAuto avoids this entirely.
Why Models Don't Sort Imports
Models generate code line-by-line in sequence. Maintaining alphabetical order requires global awareness of all imports before writing any of them. The model writes the first import, then the second, and so on - it does not go back and reorder. If it thinks of a new import mid-generation, it appends it where it thinks of it, not where it alphabetically belongs. No benchmark checks import order - a correct solution with unsorted imports scores identically to one with sorted imports.
How It Works
After code generation, GitAuto detects the file language from its extension and routes to the appropriate sorter. For JavaScript and TypeScript, it groups imports by type (external packages, internal modules, relative paths) and sorts alphabetically within each group. For Python, it follows the standard convention of grouping stdlib, third-party, and local imports. The sorting preserves any comments attached to import lines.
Related Features
- Trailing Space Removal - Another formatting fix applied before committing
- Lint Disable Headers - Adds lint-disable comments that complement sorted imports
Need Help?
Have questions or suggestions? We're here to help you get the most out of GitAuto.
Contact us with your questions or feedback!