Skip to content
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

Better import organization #16

Closed
aruZeta opened this issue Sep 2, 2022 · 7 comments
Closed

Better import organization #16

aruZeta opened this issue Sep 2, 2022 · 7 comments
Labels
roadmap This ISSUE or PR is part of the roadmap of the project.

Comments

@aruZeta
Copy link
Owner

aruZeta commented Sep 2, 2022

There are some messy imports around, and I would like to rewrite them all in the same way. I think this is the best approach, which I encountered while doing #14:

import
  "."/[a, b, c],
  ".."/[e, f ,g],
  std/[h, i, j]
@aruZeta
Copy link
Owner Author

aruZeta commented Sep 2, 2022

If one import does not fit in one line, it should be divided at convenience, but trying to make it not look very bad, for example:

This is prefered:

import
  "."/[reallyLongName,
       reallyReallyLongName,
       reallyReallyReallyLongName]

To this:

import
  "."/[reallyLongName, reallyReallyLongName,
       reallyReallyReallyLongName]

@aruZeta
Copy link
Owner Author

aruZeta commented Sep 2, 2022

Also, if the module to be imported can be separated by / (like std/foo or ".."/foo) always put the modules imported, even if it's one, between [], so:

import
  std/[foo]

And not:

import
  std/foo

@aruZeta
Copy link
Owner Author

aruZeta commented Sep 2, 2022

Always separate the import keyword and the imported modules by a new line, even if it's only one.

@aruZeta
Copy link
Owner Author

aruZeta commented Sep 2, 2022

As can be seen from previous rules and examples, there can only be 1 import statement in each module.

@aruZeta
Copy link
Owner Author

aruZeta commented Sep 2, 2022

Imports should be ordered alphabetically, both the part before the / and the items inside the []. When ordering alphabetically, uppercase letters go before lowercase letters and . goes before .. which goes before any other alphabetical character:

import
  ".."/[A, a, B, b]

@aruZeta
Copy link
Owner Author

aruZeta commented Sep 2, 2022

If importing a nimble package, pkg should be used as a prefix, the same way as done with std.

Check https://nim-lang.org/docs/manual.html#modules-pseudo-importslashinclude-paths.

@aruZeta
Copy link
Owner Author

aruZeta commented Sep 2, 2022

Regarding exporting only the newline, ordering and only one statement per module rules should be followed while also, if possible, writing the fully qualified name of what's exported (exception being when exporting a whole module). Each exported symbol should be on a different line for better differentiation.

aruZeta added a commit that referenced this issue Sep 2, 2022
@aruZeta aruZeta closed this as completed Sep 2, 2022
@aruZeta aruZeta mentioned this issue Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
roadmap This ISSUE or PR is part of the roadmap of the project.
Projects
No open projects
Status: DONE
Development

No branches or pull requests

1 participant