aruZeta / QRgen

A QR code generation library.
https://aruzeta.github.io/QRgen/
MIT License
103 stars 8 forks source link

Better import organization #16

Closed aruZeta closed 2 years ago

aruZeta commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

aruZeta commented 2 years ago

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

aruZeta commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.