Skip to content

Commit abdea2d

Browse files
authored
Merge pull request #178 from AlWoSp/awa/namestyle-docs
Add codesamples for namestyles to docs
2 parents e4028f6 + 7e6c6d3 commit abdea2d

File tree

2 files changed

+284
-4
lines changed

2 files changed

+284
-4
lines changed

docs/name_style.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,141 @@
9696
]
9797
```
9898

99+
## 可配置项示例
100+
101+
以下列表显示了每个可配置项针对的元素,并提供了一个小代码示例,同时列出了默认配置。
102+
103+
### `local_name_style`
104+
105+
> 默认值:`snake_case`
106+
107+
在以下示例中,检查的名称是 `result`。请注意,由于作用域的原因,`some_value` 是由 `module_local_name_style` 检查的。
108+
109+
```Lua
110+
local some_value = 42
111+
112+
local function sum(first_value, second_value)
113+
local result = first_value + second_value
114+
return result
115+
end
116+
```
117+
118+
### `function_param_name_style`
119+
120+
> 默认值:`snake_case`
121+
122+
在以下示例中,检查的名称是 `first_value``second_value`
123+
124+
```Lua
125+
local function sum(first_value, second_value)
126+
local result = first_value + second_value
127+
return result
128+
end
129+
```
130+
131+
### `function_name_style`
132+
133+
> 默认值:`snake_case`
134+
135+
在以下示例中,检查的名称是 `some_action`
136+
137+
```Lua
138+
function some_action()
139+
return 0
140+
end
141+
```
142+
143+
### `local_function_name_style`
144+
145+
> 默认值:`snake_case`
146+
147+
在以下示例中,检查的名称是 `calculate_square`
148+
149+
```Lua
150+
local function calculate_square(x)
151+
return x * x
152+
end
153+
```
154+
155+
### `table_field_name_style`
156+
157+
> 默认值:`snake_case`
158+
159+
在以下示例中,检查的名称是 `first_name``last_name`
160+
161+
```Lua
162+
local person = {}
163+
person.first_name = "John"
164+
person.last_name = "Doe"
165+
```
166+
167+
### `global_variable_name_style`
168+
169+
> 默认值:`snake_case``upper_snake_case`
170+
171+
在以下示例中,检查的名称是 `MAX_ELEMENTS`
172+
173+
```Lua
174+
MAX_ELEMENTS = 100
175+
```
176+
177+
### `module_name_style`
178+
179+
> 默认值:`snake_case`
180+
181+
在以下示例中,检查的名称是 `my_module`
182+
183+
```Lua
184+
local my_module = {}
185+
186+
-- [...]
187+
188+
return my_module
189+
```
190+
191+
### `require_module_name_style`
192+
193+
> 默认值:`snake_case``pascal_case`
194+
195+
在以下示例中,检查的名称是 `util_module`
196+
197+
```Lua
198+
local util_module = require("util_module")
199+
local data_module = import("data_module")
200+
```
201+
202+
### `class_name_style`
203+
204+
> 默认值:`snake_case``pascal_case`
205+
206+
在以下示例中,检查的名称是 `person`
207+
208+
```Lua
209+
local person = Class()
210+
```
211+
212+
### `const_variable_name_style`
213+
214+
> 默认值:`snake_case``upper_snake_case`
215+
216+
在以下示例中,检查的名称是 `PI`
217+
218+
```Lua
219+
local PI <const> = 3.14
220+
```
221+
222+
### `module_local_name_style`
223+
224+
> 默认值:回退到当前的 `local_name_style` 配置
225+
226+
在以下示例中,检查的名称是 `some_value``data`
227+
228+
```Lua
229+
local some_value = 42
230+
local data = {}
231+
232+
local function sum(first_value, second_value)
233+
local result = first_value + second_value
234+
return result
235+
end
236+
```

docs/name_style_EN.md

Lines changed: 146 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Naming style checking supports checking based on basic nomenclature and regular
77
* upper-snake-case
88
* pattern
99

10-
## configuration
10+
## Configuration
1111

12-
To enable naming style checking, you need to add configuration in settings:
12+
To enable naming style checking, you need to add the following configuration in the settings:
1313
```json
1414
"emmylua.lint.nameStyle": true
1515
```
@@ -81,7 +81,9 @@ Regular expressions support capture groups and then match basic nomenclature:
8181

8282
Where `"$1": "camel_case"` means that the content of the first capture group needs to match the `camel_case` nomenclature
8383

84-
* Supports mixed arrays of table structures and strings For example:
84+
* Supports mixed arrays of table structures and strings
85+
86+
For example:
8587

8688
```json
8789
"local_name_style": [
@@ -94,4 +96,144 @@ Where `"$1": "camel_case"` means that the content of the first capture group nee
9496
"$1": "camel_case"
9597
}
9698
]
97-
```
99+
```
100+
101+
## Examples for the configurable items
102+
103+
The following list shows which elements each configurable item targets with a small code example, and lists the default configuration.
104+
105+
### `local_name_style`
106+
107+
> Default: `snake_case`
108+
109+
Checked name in the following example is `result`. Note that
110+
`some_value` is checked by `module_local_name_style` because of its scope.
111+
112+
```Lua
113+
local some_value = 42
114+
115+
local function sum(first_value, second_value)
116+
local result = first_value + second_value
117+
return result
118+
end
119+
```
120+
121+
### `function_param_name_style`
122+
123+
> Default: `snake_case`
124+
125+
Checked names in the following example are `first_value` and `second_value`.
126+
127+
```Lua
128+
local function sum(first_value, second_value)
129+
local result = first_value + second_value
130+
return result
131+
end
132+
```
133+
134+
### `function_name_style`
135+
136+
> Default: `snake_case`
137+
138+
Checked name in the following example is `some_action`.
139+
140+
```Lua
141+
function some_action()
142+
return 0
143+
end
144+
```
145+
146+
### `local_function_name_style`
147+
148+
> Default: `snake_case`
149+
150+
Checked name in the following example is `calculate_square`.
151+
152+
```Lua
153+
local function calculate_square(x)
154+
return x * x
155+
end
156+
```
157+
158+
### `table_field_name_style`
159+
160+
> Default: `snake_case`
161+
162+
Checked names in the following example are `first_name` and `last_name`.
163+
164+
```Lua
165+
local person = {}
166+
person.first_name = "John"
167+
person.last_name = "Doe"
168+
```
169+
170+
### `global_variable_name_style`
171+
172+
> Default: `snake_case` and `upper_snake_case`
173+
174+
Checked name in the following example is `MAX_ELEMENTS`.
175+
176+
```Lua
177+
MAX_ELEMENTS = 100
178+
```
179+
180+
### `module_name_style`
181+
182+
> Default: `snake_case`
183+
184+
Checked name in the following example is `my_module`.
185+
186+
```Lua
187+
local my_module = {}
188+
189+
-- [...]
190+
191+
return my_module
192+
```
193+
194+
### `require_module_name_style`
195+
196+
> Default: `snake_case` and `pascal_case`
197+
198+
Checked name in the following example is `util_module`.
199+
200+
```Lua
201+
local util_module = require("util_module")
202+
local data_module = import("data_module")
203+
```
204+
205+
### `class_name_style`
206+
207+
> Default: `snake_case` and `pascal_case`
208+
209+
Checked name in the following example is `person`.
210+
211+
```Lua
212+
local person = Class()
213+
```
214+
215+
### `const_variable_name_style`
216+
217+
> Default: `snake_case` and `upper_snake_case`
218+
219+
Checked name in the following example is `PI`.
220+
221+
```Lua
222+
local PI <const> = 3.14
223+
```
224+
225+
### `module_local_name_style`
226+
227+
> Default: Fallback on current `local_name_style` configuration
228+
229+
Checked names in the following example are `some_value` and `data`.
230+
231+
```Lua
232+
local some_value = 42
233+
local data = {}
234+
235+
local function sum(first_value, second_value)
236+
local result = first_value + second_value
237+
return result
238+
end
239+
```

0 commit comments

Comments
 (0)