mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-04 09:42:30 +02:00
Finalize styleguide (#396)
* Add styleguide * Encourage full luadoc * @param and @return in code blocks * Add multi-line table comma rule
This commit is contained in:
parent
691d47cbd0
commit
4d3ecd5527
65
docs/STYLEGUIDE.md
Normal file
65
docs/STYLEGUIDE.md
Normal file
@ -0,0 +1,65 @@
|
||||
|
||||
# RedMew style guide
|
||||
|
||||
Not strictly enforced, but we appreciate if you try to remain consistent with our standards.
|
||||
|
||||
* Include at least a brief one-line summary in a LuaDoc (a comment with 3 dashes `---`) before each public-facing function
|
||||
|
||||
* A LuaDoc with extended summary, `@params`, and `@return` is encouraged. ([LuaDoc Manual][1])
|
||||
|
||||
* Tabs are 4 spaces
|
||||
|
||||
* Keep each line of code to a readable length. Under 140 characters when reasonable.
|
||||
|
||||
* Never leave trailing whitespace.
|
||||
|
||||
* End each file with a newline.
|
||||
|
||||
* Newlines are unix `\n`
|
||||
|
||||
* Strings should normally be encased in `'` single-quotes. For strings with single quotes inside them, `"` double-quotes can be used.
|
||||
|
||||
* Use spaces around operators, after commas, colons, and semicolons.
|
||||
|
||||
```lua
|
||||
sum = 1 + 2
|
||||
a, b = 1, 2
|
||||
if 1 < 2 then
|
||||
game.print("Hi")
|
||||
end
|
||||
```
|
||||
|
||||
* No spaces after `(`, `[`, `{` or before `]`, `)`, `}`.
|
||||
|
||||
```lua
|
||||
table = {1, 2, 3}
|
||||
table[1]
|
||||
```
|
||||
|
||||
* Use empty lines between `functions` and to break up functions into logical paragraphs.
|
||||
|
||||
```lua
|
||||
local function some_function()
|
||||
local data = global.data
|
||||
local format = global.string_format
|
||||
local string = Utils.manipulate(data, format)
|
||||
|
||||
game.print(string)
|
||||
end
|
||||
|
||||
local function say_hello()
|
||||
game.print("Hello")
|
||||
end
|
||||
```
|
||||
|
||||
* When creating a table over multiple lines, include a trailing comma after the last item.
|
||||
|
||||
```lua
|
||||
myTable ={
|
||||
'item1',
|
||||
'item2',
|
||||
'item3',
|
||||
}
|
||||
```
|
||||
|
||||
[1]:[http://keplerproject.github.io/luadoc/manual.htm]
|
Loading…
Reference in New Issue
Block a user