@@ -212,17 +212,16 @@ need_*, should_*, must_*, in_*, not_*`` и т.п.
212
212
TODO: example
213
213
214
214
При разделении вызова функции на несколько строк аргументы функции сдвигаются
215
- на ДВА отступа, закрывающая скобка — на один относительно строки с
216
- открывающей. Открывающую скобку желательно ставить на той же строке, что и имя
215
+ на один отступ. Открывающую скобку желательно ставить на той же строке, что и имя
217
216
функции. Желательно в этом случае писать каждый аргумент функции на новой
218
217
строке. Отступы в объявлении функции оформляются аналогично.
219
218
220
219
long_function_name(
221
- with,
222
- many,
223
- many,
224
- parameters
225
- )
220
+ with,
221
+ many,
222
+ many,
223
+ parameters
224
+ )
226
225
227
226
Если при вызове функции ей передаётся единственный аргумент, и этот аргумент —
228
227
анонимная функция, создаваемая конструкцией ` function ` -` end ` непосредственно в
@@ -244,24 +243,24 @@ need_*, should_*, must_*, in_*, not_*`` и т.п.
244
243
1 )
245
244
246
245
assert(
247
- action_handlers[ action.tool] ,
248
- "unknown tool"
249
- )(
250
- manifest,
251
- cluster_info,
252
- param,
253
- machine,
254
- role_args,
255
- action
256
- )
246
+ action_handlers[ action.tool] ,
247
+ "unknown tool"
248
+ )(
249
+ manifest,
250
+ cluster_info,
251
+ param,
252
+ machine,
253
+ role_args,
254
+ action
255
+ )
257
256
258
257
2 )
259
258
260
259
machine.installed_rocks_set, machine.duplicate_rocks_set
261
260
= luarocks_parse_installed_rocks(
262
261
remote_luarocks_list_installed_rocks(
263
- machine.external_url
264
- )
262
+ machine.external_url
263
+ )
265
264
)
266
265
267
266
3 ) Допускается свешивание ` .. ` при переносах:
@@ -281,25 +280,25 @@ need_*, should_*, must_*, in_*, not_*`` и т.п.
281
280
282
281
if
283
282
long_function_name(
284
- with,
285
- many,
286
- many,
287
- parameters
288
- ) == other_long_function(
289
- the,
290
- same
291
- )
283
+ with,
284
+ many,
285
+ many,
286
+ parameters
287
+ ) == other_long_function(
288
+ the,
289
+ same
290
+ )
292
291
then
293
292
body
294
293
end
295
294
296
295
6 )
297
296
298
297
local func_name = function(
299
- param1,
300
- param2,
301
- longname3
302
- )
298
+ param1,
299
+ param2,
300
+ longname3
301
+ )
303
302
body
304
303
end
305
304
@@ -405,7 +404,7 @@ need_*, should_*, must_*, in_*, not_*`` и т.п.
405
404
log(
406
405
"bar"
407
406
.. " baz"
408
- )
407
+ )
409
408
410
409
## Избыточный синтаксис
411
410
@@ -542,17 +541,17 @@ need_*, should_*, must_*, in_*, not_*`` и т.п.
542
541
#### Штатная проверка аргументов
543
542
544
543
local is_log_enabled_raw = function(
545
- modules_config,
546
- levels_config,
547
- module_name,
548
- level
549
- )
544
+ modules_config,
545
+ levels_config,
546
+ module_name,
547
+ level
548
+ )
550
549
arguments(
551
- "table", levels_config,
552
- "table", modules_config,
553
- "string", module_name,
554
- "number", level
555
- )
550
+ "table", levels_config,
551
+ "table", modules_config,
552
+ "string", module_name,
553
+ "number", level
554
+ )
556
555
...
557
556
end
558
557
@@ -561,8 +560,8 @@ need_*, should_*, must_*, in_*, not_*`` и т.п.
561
560
local foo = function(bar)
562
561
bar = bar or BAZ
563
562
arguments(
564
- "quo", bar
565
- )
563
+ "quo", bar
564
+ )
566
565
567
566
## Конструкторы таблиц
568
567
@@ -693,11 +692,11 @@ need_*, should_*, must_*, in_*, not_*`` и т.п.
693
692
694
693
make_myobject = function(args)
695
694
return setmetatable(
696
- {
697
- private_variable_ = 42;
698
- },
699
- mt;
700
- )
695
+ {
696
+ private_variable_ = 42;
697
+ },
698
+ mt
699
+ )
701
700
end
702
701
end
703
702
@@ -893,10 +892,10 @@ need_*, should_*, must_*, in_*, not_*`` и т.п.
893
892
Не рекомендуется:
894
893
895
894
test:case "test-case-with-a-really-really-really-...-really-long-name" (
896
- function()
897
- ...
898
- end
899
- )
895
+ function()
896
+ ...
897
+ end
898
+ )
900
899
901
900
Рекомендуется:
902
901
@@ -912,10 +911,10 @@ need_*, should_*, must_*, in_*, not_*`` и т.п.
912
911
913
912
test:case "some-test-case"
914
913
:with(temporary_directory("tmpdir", "tmp", "/long/long/path/to/dir")) (
915
- function(env)
916
- ...
917
- end
918
- )
914
+ function(env)
915
+ ...
916
+ end
917
+ )
919
918
920
919
Тоже нежелательно (неправильный отступ у анонимной функции):
921
920
@@ -929,12 +928,12 @@ need_*, should_*, must_*, in_*, not_*`` и т.п.
929
928
930
929
test:case "some-test-case"
931
930
:with(
932
- temporary_directory(
933
- "tmpdir",
934
- "tmp",
935
- "/long/long/path/to/dir"
936
- )
937
- ) (function(env)
931
+ temporary_directory(
932
+ "tmpdir",
933
+ "tmp",
934
+ "/long/long/path/to/dir"
935
+ )
936
+ ) (function(env)
938
937
...
939
938
end)
940
939
@@ -969,19 +968,19 @@ need_*, should_*, must_*, in_*, not_*`` и т.п.
969
968
Пример:
970
969
971
970
ensure_returns(
972
- "some check",
973
- 2,
974
- { false, "expected error" },
975
- xpcall(
976
- function()
977
- error("expected error")
978
- end,
979
- function(msg)
980
- log_error("foo failed:", debug.traceback(foo))
981
- return foo
982
- end
983
- )
971
+ "some check",
972
+ 2,
973
+ { false, "expected error" },
974
+ xpcall(
975
+ function()
976
+ error("expected error")
977
+ end,
978
+ function(msg)
979
+ log_error("foo failed:", debug.traceback(foo))
980
+ return foo
981
+ end
984
982
)
983
+ )
985
984
986
985
## Устаревшие и запрещенные выражения языка
987
986
@@ -1121,9 +1120,9 @@ error message, необходимо в обязательном порядке
1121
1120
Неверно:
1122
1121
1123
1122
assert(
1124
- a == b,
1125
- "value of a: " .. tstr(a) .. " is not equal to value of b: " .. tstr(b)
1126
- )
1123
+ a == b,
1124
+ "value of a: " .. tstr(a) .. " is not equal to value of b: " .. tstr(b)
1125
+ )
1127
1126
1128
1127
Верно:
1129
1128
0 commit comments