Skip to content

Commit 6bbbfb0

Browse files
committed
提供英文文档
1 parent f00b4b4 commit 6bbbfb0

File tree

4 files changed

+762
-0
lines changed

4 files changed

+762
-0
lines changed

README_EN.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# EmmyLuaCodeStyle
2+
3+
If possible, you can help me improve the English document
4+
5+
## Project Introduction
6+
7+
This project is an example of Lua code analysis\formatting\code diagnosis algorithm library and language service based on C++
8+
9+
The main pursuit of this project is reasonable formatting and diagnosis of various code styles
10+
11+
In addition to providing language service examples, the project also provides an independent command line tool CodeFormat, which can be used for batch code formatting and code style checking (there are still many problems, you can modify it yourself).
12+
13+
## 文档
14+
15+
* [Introduction to formatting behavior](docs/format_action_EN.md)
16+
* [How to configure formatting](docs/format_config_EN.md)
17+
* [Code diagnosis configuration](docs/diagnosis_config_EN.md)
18+
19+
# Contribute
20+
21+
Any pr or issue are welcome
22+
23+
## Build
24+
25+
If you want to compile the project yourself, make sure that your compiler can basically support C++20:
26+
* VS2019 16.10以上
27+
* gcc 10以上
28+
* clang 10以上
29+
30+
```
31+
mkdir build && cd build
32+
cmake ..
33+
cmake --build .
34+
35+
```
36+
37+
## Developed By
38+
39+
[**@CppCXY**](https://github.com/CppCXY)
40+
41+
**Contributors**
42+
43+
44+
## License
45+
46+
no License

docs/diagnosis_config_EN.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Diagnostic options
2+
3+
Most of the formatting options have diagnostic attributes. In addition, there are additional options for diagnostics. These options do not affect formatting.
4+
## enable_check_codestyle
5+
6+
Whether to enable code diagnosis The optional value is true/false.
7+
8+
## max_line_length
9+
10+
Represents the maximum line width detection. This option does not affect formatting. The default value is 120.
11+
12+
## insert_final_newline
13+
14+
This option indicates whether the Lua document should end with a new line. The name of this option comes from the standard definition of editorconfig. The default value is true. The code formatting algorithm must end with a new line, so this option is only used for diagnosis.
15+
16+
# Naming style check
17+
18+
The algorithm supports basic style checking for the name definition, and the more complex verification logic can be opened after the plug-in system is designed. All check logics can be represented by'|' or' operation. The basic check logic includes:
19+
* off do nothing
20+
* camel_case little camel case nomenclature
21+
* pascal_case big hump nomenclature
22+
* snake_case snake nomenclature
23+
* upper_snake_case snake nomenclature in all uppercase
24+
25+
The complex verification logic is expressed in the form of a function:
26+
1. same(arg1, arg2) This form means that the form of arg2 is the same as arg1. The only variables supported by arg2 are:
27+
* snake_case in a snake-like way
28+
* pascal_case is in the form of big hump nomenclature
29+
* camel_case in the form of small camel case nomenclature
30+
31+
The methods supported by arg1 are:
32+
33+
* filename means the same as the current file name, the same way is not necessarily congruent, it can be in the form of arg2
34+
* first_param means the same as the first parameter of the related calling function, and it is also allowed to act in the form specified by arg2
35+
* String constant means equal to a string constant, such as same('_M'), when arg1 is a string constant, the arg2 parameter is invalid
36+
37+
## enable_name_style_check
38+
39+
This option is false by default, which means whether to enable naming style checking
40+
41+
## local_name_define_style
42+
43+
This option indicates what naming rules the names in the local name definition list should conform to. The default value is snake_case
44+
45+
## function_param_name_style
46+
47+
This option indicates that the default value of the parameter naming rule during function definition is snake_case
48+
49+
## function_name_define_style
50+
51+
This option indicates the naming rules for function definitions. The function definition referred to here only contains the following forms:
52+
* function fff() end
53+
* function ttt:ffff() end
54+
55+
The default value of the option is snake_case
56+
57+
## local_function_name_define_style
58+
59+
This option indicates the naming rule when the local function is defined. The only supported form here is: local function fff() end
60+
61+
The default value of the option is snake_case
62+
63+
## table_field_name_define_style
64+
65+
This option indicates the naming rule of the field of the table, and the classification may be evolved later. The currently supported forms are:
66+
67+
```lua
68+
local t = { aa = 1312}
69+
70+
t.bbb = 123
71+
```
72+
73+
The default value is snake_case, but the names of all meta-methods are not within the rules.
74+
75+
## global_variable_name_define_style
76+
77+
Indicates the name definition style of global variables. The default value is snake_case|upper_snake_case
78+
79+
## module_name_define_style
80+
81+
Indicates the name definition style of the module, and the identification rules for module variables are:
82+
Take the name of any local definition in the file scope as the first parameter of the return statement in the file scope.
83+
84+
The default option is same('m')|same(filename, snake_case)
85+
86+
## require_module_name_style
87+
88+
Indicates the name defined in the import statement of the module. The statement recognition principle is:
89+
Shaped like
90+
```lua
91+
local m = require "aaa.bbb.ccc"
92+
```
93+
The m in the lua statement, the supported functions currently include require and import
94+
95+
96+
The default value is same(first_param, snake_case)
97+
98+
## class_name_define_style
99+
100+
Represents the naming rules of class definitions. The recognition principles of class definitions are:
101+
Shaped like
102+
```lua
103+
local c = class "c"
104+
```
105+
The c in the lua statement, the supported functions currently include Class and class
106+
107+
The default value is same(filename, snake_case)

docs/format_action_EN.md

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
# Introduction to formatting behavior
2+
3+
## Basic Statement
4+
5+
The algorithm itself will use more reasonable principles to do basic code layout optimization:
6+
* All logos/keywords/literal expressions usually keep a space or relative line spacing with the next element
7+
* Binocular/monocular operators will keep a space with the operand or keep relative line spacing, there is no space between the comma and the previous element and the next element keeps a space
8+
* Short statement blocks can (but not necessarily) remain on the same line. This principle is valid for all function/do/while/repeat/if statements
9+
* The algorithm will not automatically interrupt a single-line statement that is too long. The algorithm seldom actively wraps. The algorithm will try to ensure that the line spacing of all elements is the same as before.
10+
* The algorithm does not remove any visible elements, such as semicolons. Do not format if there is a syntax error
11+
* The algorithm will not typeset the content of the comment, for example, all the parts of the long comment that are considered to be comments will not increase the indentation
12+
13+
```lua
14+
local t=123 --local
15+
aaa,bbbb = 1123, 2342
16+
local f =function() end
17+
local d = {
18+
-- comment
19+
aa = 213, --comment
20+
};
21+
local e = a+b+c+d
22+
function fff(a,b,c) end
23+
function ff2()
24+
--[[
25+
long comment
26+
]]
27+
end
28+
```
29+
30+
Will be formatted as:
31+
32+
```lua
33+
local t = 123 --local
34+
aaa, bbbb = 1123, 2342
35+
local f = function() end
36+
local d = {
37+
-- comment
38+
aa = 213, --comment
39+
};
40+
local e = a + b + c + d
41+
function fff(a, b, c) end
42+
43+
function ff2()
44+
--[[
45+
long comment
46+
]]
47+
end
48+
```
49+
50+
## Continuous assignment statement
51+
52+
For consecutive assignments or local statements, when the algorithm recognizes that the code tries to align to the equal sign, it will typeset in the manner of aligning to the equal sign. The basic principle of identifying alignment is:
53+
54+
* For consecutive assignment/local/comment statements, when the equal sign of the first assignment/local statement is more than 1 space away from the element to its left, the consecutive assignment/local statement will be aligned to the equal sign.
55+
* The definition of continuous alignment here is: no more than 2 lines between statements
56+
* Alignment will be aligned to the furthest equal sign
57+
58+
```lua
59+
local ttt = 123 --first
60+
cd = 345 --second
61+
```
62+
63+
格式化后:
64+
65+
```lua
66+
local ttt = 123 --first
67+
cd = 345 --second
68+
```
69+
70+
## Table layout
71+
72+
For common table expressions, the default formatting method is:
73+
* The field in the table will be spaced a blank from the braces of the table or keep relative line spacing
74+
* Different fields in the table will keep their relative positions unchanged
75+
* If all the fields are in different rows and are in the form of key = value, when different fields try to align to the equal sign, the algorithm will align to the equal sign
76+
* The basic principle of trying to align to the equal sign is key = value/comment field. When the distance between the equal sign of the first line of field and the element to its left is greater than 1 space, the key = value field in the table will be aligned to the equal sign
77+
78+
```lua
79+
local t = {1,2,3}
80+
local c = {
81+
aaa, bbb, eee
82+
}
83+
local d = {
84+
aa =123,
85+
bbbb = 4353,
86+
eee = 131231,
87+
}
88+
```
89+
90+
格式化后:
91+
92+
```lua
93+
local t = { 1, 2, 3 }
94+
local c = {
95+
aaa, bbb, eee
96+
}
97+
local d = {
98+
aa = 123,
99+
bbbb = 4353,
100+
eee = 131231,
101+
}
102+
```
103+
104+
## Long expression list
105+
106+
If the long expression list and the long expression have more than one line, except for the first line, the remaining lines will be indented by one continuation line:
107+
108+
For example:
109+
110+
```lua
111+
local aaa = 13131, bbbb,
112+
ccc, 123131, ddddd,
113+
eeee, fff
114+
115+
return aaa, bbb, dddd
116+
or cccc
117+
118+
if aaa and bbb
119+
or ccc() then
120+
121+
end
122+
123+
```
124+
125+
## Statements containing statement blocks
126+
127+
For if statement, repeat statement, while statement, do statement, for statement and function definition statement they all have the following formatting characteristics:
128+
129+
* When the statement containing the statement block is only one line, the algorithm will keep them in one line
130+
* For statements that usually contain statement blocks, there will be one more indentation in the statement block
131+
* The statement containing the statement block and the next statement are usually separated by at least 1 line
132+
133+
For example:
134+
135+
```lua
136+
do return end
137+
function f(x,y) return x<y end
138+
function fff()
139+
local t =123
140+
end
141+
```
142+
143+
Will be formatted as:
144+
145+
```lua
146+
do return end
147+
148+
function f(x, y) return x < y end
149+
150+
function fff()
151+
local t = 123
152+
end
153+
154+
```
155+
156+
## Function definition parameters and function call parameters
157+
158+
The definition parameters of function definition statements have the following principles:
159+
* By default, if the definition parameter of the function wraps, it will be aligned to the first parameter after the wrap
160+
161+
For example:
162+
163+
```lua
164+
function ffff(a, b, c,
165+
callback)
166+
end
167+
```
168+
169+
After formatting:
170+
171+
```lua
172+
function ffff(a, b, c,
173+
callback)
174+
end
175+
176+
```
177+
178+
The parameters of function call have the following principles:
179+
* If the function has multiple parameters, if the parameter list itself changes lines, except for the first line, the remaining lines will be indented by one more continuation line
180+
* If the function call is a single parameter without parentheses, there will be a space between the function identifier and the parameter
181+
182+
For example:
183+
184+
```lua
185+
print(aaa, bbbb, eeee, ffff,
186+
ggggg, hhhhh,
187+
lllll)
188+
require "code_format"
189+
```
190+
After formatting:
191+
192+
```lua
193+
print(aaa, bbbb, eeee, ffff,
194+
ggggg, hhhhh,
195+
lllll)
196+
require "code_format"
197+
```
198+
199+
## Comment statements and inline comments
200+
201+
Comment statements are divided into long comments and single-line short comments and inline comments
202+
* When the comment statement is formatted, the short comment will not make any changes, keeping the same line spacing as the next statement, while the large blank text of the long comment is considered part of the comment, so no changes will be made, and the same Same line spacing in the next statement
203+
* Inline comments, using the principle of keeping a space with the previous text, if the next element is still on the same line, it will also keep a space
204+
205+
```lua
206+
--[[
207+
208+
]]
209+
210+
---@param f number
211+
---@return number
212+
function ffff(f)
213+
end
214+
215+
local t = 123 --fffff
216+
local c = {
217+
aaa = 123, --[[ffff]] dddd,
218+
ccc = 456
219+
}
220+
```
221+
222+
格式化后:
223+
224+
```lua
225+
--[[
226+
227+
]]
228+
229+
---@param f number
230+
---@return number
231+
function ffff(f)
232+
end
233+
234+
local t = 123 --fffff
235+
local c = {
236+
aaa = 123, --[[ffff]] dddd,
237+
ccc = 456
238+
}
239+
```
240+

0 commit comments

Comments
 (0)