Style Guide - HeladoDeBrownie/Nexus GitHub Wiki

This style guide applies to any source code included in the project, primarily Lua code. It does not apply to Markdown or other text documents.

Spacing

Indentation

Use indents of 4 spaces. No tabs and no partial indents.

if true then
    print':3'
end

Alignment

Parallel structure that occupies multiple lines may be aligned using spaces to indicate the parallelity.

local  first =  10 * 11 + 10
local second =   2 *  5 -  1
local  third = 300 * 20 +  3

Blocks

Logical blocks of multiple lines should be padded from surrounding code of the same indentation level with single blank lines. Unrelated single lines may remain next to each other with no intervening line breaks, or separated if it makes sense to do so.

local b = true
local x = 10

if b then
    print(x)
end

if x > 5 then
    print'x > 5'
end

Long Lines

Lines of code that exceed 79 characters wide should be broken up in a logical place if feasible.

Additional lines after the first for a given statement or expression should be indented one additional place. However, If there is a logical end token that matches a beginning token at the end of the initial line, the end token's line can be unindented again to keep the structure parallel, as long as the intervening lines are also parallel with each other in some useful sense.

Both of the following indentation styles are valid:

local x = math.max(1,
    2, 3)

local x = math.max(
    1,
    2,
    3
)

Strings

For single-line string literals, always use ' single quotes '; unless the string contains an actual ', in which case use " double quotes "; unless the string contains both ' and ", in which case prefer single quotes but use your discretion.

For multi-line string literals, prefer to use [ level 0 bracket quotes ](/HeladoDeBrownie/Nexus/wiki/-level-0-bracket-quotes-), but use your discretion if doing so would require escaping. When using bracket quotes, indentation style rules may be ignored as necessary.