Skip to content

Commit 8735890

Browse files
authored
Merge pull request #210 from waddie96/patch-2
Revise formatting behavior documentation
2 parents 2610ef3 + c9f26ce commit 8735890

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

docs/format_action_EN.md

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
# Introduction to formatting behavior
2-
3-
The formatter is highly configurable, supports simple extended syntax, has a variety of styles, and is extremely performant. Suitable for formatting configuration files, formatting large code bases, etc. Suitable for a unified code style within the project, or individual developers with special preferences.
1+
# 📚 Formatting behavior
42

53
## Basic formatting
64

7-
The basic formatting principle of the code is mainly to add basic whitespace on both sides of the symbol, achieve correct indentation for the statement block, set the appropriate spacing between different statements, keep the token in the sequential position will not change, and clean up the excess space at the end of the line.
5+
EmmyLuaCodeStyle applies a consistent set of rules to ensure readability and maintainability of Lua source code. Its core formatting principles include:
6+
7+
- Adding appropriate whitespace around symbols
8+
- Ensuring correct indentation for statement blocks
9+
- Maintaining consistent spacing between statements
10+
- Preserving token order to avoid semantic changes
11+
- Removing trailing whitespace at the end of lines
12+
13+
These rules guarantee a uniform code structure across projects while respecting the logical flow of Lua syntax.
14+
15+
**Example:**
816

917
```lua
1018
local t=123 --local
@@ -18,12 +26,13 @@ local e = a+b+c+d
1826
function fff(a,b,c) end
1927
function ff2()
2028
--[[
21-
long comment
29+
long description.
2230
]]
2331
end
2432
```
2533

26-
will be formatted as:
34+
**Formatted output:**
35+
2736
```lua
2837
local t = 123 --local
2938
aaa, bbbb = 1123, 2342
@@ -39,15 +48,16 @@ end
3948

4049
function ff2()
4150
--[[
42-
long comment
51+
long description.
4352
]]
4453
end
4554
```
4655

47-
## Alignment
56+
### Alignment
4857

49-
On top of basic requirements, formatting tools provide satisfaction for advanced aesthetic needs, and code alignment is an important component.
58+
Beyond basic formatting, it supports advanced alignment features to improve clarity and readability. Adequate alignment helps developers easily scan related code elements and maintain a clean, consistent structure.
5059

60+
**Example:**
5161

5262
```lua
5363
local ttt = 123 --first
@@ -66,7 +76,7 @@ local c = {
6676
}
6777
```
6878

69-
will be formatted as:
79+
**Formatted output:**
7080

7181
```lua
7282
local ttt = 123 --first
@@ -84,3 +94,28 @@ local c = {
8494
{ 1, 2, 3 }
8595
}
8696
```
97+
98+
The formatter aligns assignment operators, table fields, and array elements in a way that balances readability with minimal unnecessary whitespace. Alignment can be configured or disabled entirely, per project coding conventions.
99+
100+
### Line wrapping
101+
102+
EmmyLua provides flexible line wrapping rules through configuration options such as `max_line_length = 120` and `continuation_indent = 4`. Long expressions, function parameters, and table constructors are automatically wrapped according to the configurable maximum line length.
103+
104+
**Example:**
105+
106+
```lua
107+
local function longFunctionNameWithManyParameters(param1, param2, param3, param4, param5, param6)
108+
-- function body
109+
end
110+
```
111+
112+
**Formatted output:**
113+
114+
```lua
115+
local function longFunctionName(
116+
with_many_parameters, param_two, param_three,
117+
configurable, continuation_indent
118+
)
119+
-- function body
120+
end
121+
```

0 commit comments

Comments
 (0)