Skip to content

Repository files navigation

Lua formatter

TestcodecovGo Report Cardcodebeat badge

Code formatting rules

Variables

The option alignment.variables will align list of variables.

locala=1-- commentlocalbb=22-- commentlocalc="short text" -- comment

Comments

Skipped space between a double hyphen and text will be revert. Semantic line (only hyphens) will not have the space.

---------------------------------- Description-- params: - input-- - output

Tables

If you create an empty table or table with only key fields or table with one field they will be written in one line.

localt= {}
localt= {"one", "two", 3, 4, 5}
localt= {a=1, b=2, c=3}

If you write more than five fields with only key then table will be written in multiline. Same behaviour will be if you write more than four fields with key and value. If the table is multiline then every field will have trailing comma.

localt= {
"one",
"two",
3,
4,
5,
"six",
}
localt= {
a=1,
b=2,
c=3,
d=4,
}

The option alignment.table will align table.

localt= {
a=1, -- comment
["bb"] ="bb", -- comment-- commentccc="ccc", -- commentdddeee="dddeee", -- commentf=function()
return1end,
g=7, -- comment-- comment
}

Newline

If return statement is inside the block with other statements then a newline will be added before it.

functionisFalse()
returnfalseendfunctioncalc(a, b)
localc=a+breturncend

If a function is inside the block with other statements then a newline will be added before it.

functionisFalse()
returnfalseendisFalse()

If a function has parameters more than max line length then every parameter will be moved to the next line.

functionvery_long_name(
very_long_name_parameter_1,
very_long_name_parameter_2,
very_long_name_parameter_3
)
-- stuffend

If a function call has parameters more than max line length then every parameter will be moved to the next line.

very_long_name_function_call(
{a=1, b=2, c=3},
very_long_name_parameter,
{
a=1,
b=2,
c=3,
d=4,
}
)

About

Code formatter for Lua

Topics

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages