-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(fmt): add sort_imports config #5442
Conversation
hey @meetmangukiya i think this is good! do you plan on finishing this, or should we take over? |
Will get back to this when I find time. In the mean time if you want to take over it's also fine. |
I also am interested in a feature for sorting functions by receive, fallback, visibility, mutability, payable, etc. as here. Which I think could be done similarly? Maybe could reuse some parts from here too. |
Hello This is a great feature. |
a59aeba
to
c65fe8d
Compare
I completed this by taking the original approach and merely modifying the group detection. This currently only sorts individual import groups (separated by newline) and does not reorder groups. I guess we could reorder groups as well but this should be a separate setting. there's a limitation when a group contains a comment, but we can live with that for now. |
🐐 |
c65fe8d
to
711388b
Compare
9593f0c
to
cc69fa8
Compare
Motivation
Sorting imports is a desirable feature.
Closes #3396. I didn't check the issues first and went head first into the implementation because I wanted import sorts but see now that @rkrasiuk is already assigned to the issue 😅 .
Solution
Sorts the
SourceUnitPart::Import
parts before running it through the formatter. Sort works but blanks and slicing need to be fixed. Also, as I built this I have realized few things:SourceUnitPart::Import
wont be correct because blank lines do not have aSourceUnit
entry. Need to useself.blank_lines
somewhere to better determine the slice boundaries.blank_lines
to determine if there should be a space between formatted units, need to fix it. I am thinking maybe there is a way to use theneeds_space
callback in conjunction with theimport_slices
to determine the blank spaces to add correctly.Opening a WIP PR, because it might not be the best or even a correct way to do this.