mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
style.lua(9): Add some additional notes about naming and commas
camelCase tends to be preferred for function identifiers, while internal_underscores are preferred for variable identifiers. This convention makes it a little bit easier to eyeball whether variable/function usage is correct. The optional commas for final table values are preferred to reduce chances for error.
This commit is contained in:
parent
ea70c96af2
commit
11d5ba38ab
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=330012
|
@ -25,7 +25,7 @@
|
|||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd February 20, 2018
|
||||
.Dd February 25, 2018
|
||||
.Dt STYLE.LUA 9
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -83,6 +83,30 @@ Single-line conditional statements and loops should be avoided.
|
|||
.Pp
|
||||
.Ic local
|
||||
variables should be preferred to global variables in module scope.
|
||||
internal_underscores tend to be preferred for variable identifiers, while
|
||||
camelCase tends to be preferred for function identifiers.
|
||||
.Pp
|
||||
If a table definition spans multiple lines, then the final value in the table
|
||||
should include the optional terminating comma.
|
||||
For example:
|
||||
.Bd -literal
|
||||
-- No terminating comma needed for trivial table definitions
|
||||
local trivial_table = {1, 2, 3, 4}
|
||||
|
||||
local complex_table = {
|
||||
{
|
||||
id = "foo",
|
||||
func = foo_function, -- Trailing comma preferred
|
||||
},
|
||||
{
|
||||
id = "bar",
|
||||
func = bar_function,
|
||||
}, -- Trailing comma preferred
|
||||
}
|
||||
.Ed
|
||||
.Pp
|
||||
This reduces the chance for errors to be introduced when modifying more complex
|
||||
tables.
|
||||
.Pp
|
||||
Multiple local variables should not be declared
|
||||
.Sy and
|
||||
|
|
Loading…
Reference in a new issue