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
I propose adding to vfmt grouping and sorting of imports almost the same as Python isort does. For now vfmt just deletes line breaks between imports.
I found an old feature request #9353, here I describe the feature in more detail.
Use Case
The goal is to make imports more visual and nice looking.
No more:
importmarkdownimportfoobar// local moduleimportlogimportwhisker.datamodelimportwhisker.templateimportnet.httpimportcontextimportnet.htmlimportmylocalmodimportio
Proposed Solution
Groups
It is worth dividing imports into three groups:
Modules from vlib
Third-party modules, installed via v install [--git] <module>
Local modules (found in the working directory relative to v.mod)
Groups should be separated by line breaks and follow each other in the above order.
General sorting
Each group individually must be sorted by type in alphabetical order. For example:
I prefer vfmt to not sort anything at all. That can lead to subtle bugs, because modules can have init functions with side effects, and the programmer has more information about what he/she prefers, not vfmt.
I prefer vfmt to not sort anything at all. That can lead to subtle bugs, because modules can have init functions with side effects, and the programmer has more information about what he/she prefers, not vfmt.
Now I understand that a lot of official V code have not sorted the imports. I though that like in Golang, we can sort the names and later the language will call all the corresponding init() correctly. I think our eyes like to see the beginning of any V file as "nice" as possible.
In most cases the order does not matter (the modules are sorted in topological order when there are dependencies), but not in all (in the presence of side effects, inside the same file), and forcing vfmt to reorder stuff for aesthetic reasons will break that.
Describe the feature
I propose adding to vfmt grouping and sorting of imports almost the same as Python isort does. For now vfmt just deletes line breaks between imports.
I found an old feature request #9353, here I describe the feature in more detail.
Use Case
The goal is to make imports more visual and nice looking.
No more:
Proposed Solution
Groups
It is worth dividing imports into three groups:
v install [--git] <module>
Groups should be separated by line breaks and follow each other in the above order.
General sorting
Each group individually must be sorted by type in alphabetical order. For example:
Sorting imports by type
Sorting imports types in this order looks good:
Sorting selective imports
Symbols in selective imports should also be sorted:
For better look, lowercase named symbols must be placed after symbols starting with a capital letter:
Sorting precedence
The highest priority is sorting by groups. Then each group should be sorted by import type. Alphabetical sorting is performed last.
Other Information
No response
Acknowledgements
Version used
V 0.4.8 58fc4de
Environment details (OS name and version, etc.)
Not important.
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
Huly®: V_0.6-21381
The text was updated successfully, but these errors were encountered: