It only has to check for imports on the top level declarations of a file since odin enforces them to only be there.
Then it keeps track of the index of imports it sees.
When a different declaration is found or when an import is found but it is preceded by an empty line, it sorts the declarations by the full import path and inserts them into the document.
Also adds a new key into the odinfmt.json called sort_imports which can be set to false to turn this off.
Something like this will be kept in tact, because of the grouping with an empty line:
This PR adds sorting imports to the formatter.
It only has to check for imports on the top level declarations of a file since odin enforces them to only be there. Then it keeps track of the index of imports it sees. When a different declaration is found or when an import is found but it is preceded by an empty line, it sorts the declarations by the full import path and inserts them into the document.
Also adds a new key into the
odinfmt.json
calledsort_imports
which can be set tofalse
to turn this off.Something like this will be kept in tact, because of the grouping with an empty line:
Example diff: