You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/format_action_EN.md
+45-10Lines changed: 45 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff 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
4
2
5
3
## Basic formatting
6
4
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:**
8
16
9
17
```lua
10
18
localt=123--local
@@ -18,12 +26,13 @@ local e = a+b+c+d
18
26
functionfff(a,b,c) end
19
27
functionff2()
20
28
--[[
21
-
long comment
29
+
long description.
22
30
]]
23
31
end
24
32
```
25
33
26
-
will be formatted as:
34
+
**Formatted output:**
35
+
27
36
```lua
28
37
localt=123--local
29
38
aaa, bbbb=1123, 2342
@@ -39,15 +48,16 @@ end
39
48
40
49
functionff2()
41
50
--[[
42
-
long comment
51
+
long description.
43
52
]]
44
53
end
45
54
```
46
55
47
-
## Alignment
56
+
###Alignment
48
57
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.
50
59
60
+
**Example:**
51
61
52
62
```lua
53
63
localttt=123--first
@@ -66,7 +76,7 @@ local c = {
66
76
}
67
77
```
68
78
69
-
will be formatted as:
79
+
**Formatted output:**
70
80
71
81
```lua
72
82
localttt=123--first
@@ -84,3 +94,28 @@ local c = {
84
94
{ 1, 2, 3 }
85
95
}
86
96
```
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.
0 commit comments