Skip to content

Commit af3f696

Browse files
committed
Code style fixes.
1 parent 24e9db0 commit af3f696

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+510
-501
lines changed

.github/workflows/whitespace_checks.yml

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,16 @@ jobs:
3434
- uses: actions/checkout@v4
3535
# Line endings are already ensured by .gitattributes
3636
- name: Check trailing whitespaces
37-
run: if git ls-files | grep -E '\.txt$|\.md$|\.[ch]$|\.cpp$|\.hpp$|\.sh$|\.cmake$|\.glsl$' | xargs grep -n '\s$'; then echo -e "\033[0;31mFound trailing whitespace"; (exit 1); else (exit 0); fi
37+
run: |
38+
if git ls-files |\
39+
grep -E '\.txt$|\.md$|\.[ch]$|\.cpp$|\.hpp$|\.sh$|\.cmake$|\.glsl$' |\
40+
xargs grep -n '\s$';\
41+
then\
42+
echo -e "\033[0;31mFound trailing whitespace";\
43+
(exit 1);\
44+
else\
45+
(exit 0);\
46+
fi
3847
3948
indent_spaces:
4049
runs-on: ubuntu-latest
@@ -46,28 +55,64 @@ jobs:
4655
# So lines like: "/* */ /*" or "*/ a = 5; /*" will result in error
4756
- name: Check for unsupported multiline comments
4857
run: |
49-
if git ls-files | grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' | xargs grep -n '\*/.*/\*'; then echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line."; (exit 1); else (exit 0); fi
50-
if git ls-files | grep -E '\.lua$' | xargs grep -n -e '\]\].*--\[\['; then echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line."; (exit 1); else (exit 0); fi
58+
if git ls-files |\
59+
grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' |\
60+
xargs grep -n '\*/.*/\*';\
61+
then
62+
echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line.";\
63+
(exit 1);\
64+
else\
65+
(exit 0);\
66+
fi
67+
if git ls-files |\
68+
grep -E '\.lua$' |\
69+
xargs grep -n -e '\]\].*--\[\[';\
70+
then
71+
echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line.";\
72+
(exit 1);\
73+
else\
74+
(exit 0);\
75+
fi
5176
# This prepare files for final check
5277
# See python script ./util/ci/indent_tab_preprocess.py for details.
5378
- name: Preprocess files
5479
run: |
55-
git ls-files | grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' | xargs -L 1 -P $(($(nproc) + 1)) python3 ./util/ci/indent_tab_preprocess.py "/*" "*/"
56-
git ls-files | grep -E '\.lua$' | xargs -L 1 -P $(($(nproc) + 1)) python3 ./util/ci/indent_tab_preprocess.py "--[[" "]]"
80+
git ls-files |\
81+
grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' |\
82+
xargs -L 1 -P $(($(nproc) + 1)) \
83+
python3 ./util/ci/indent_tab_preprocess.py "/*" "*/"
84+
git ls-files |\
85+
grep -E '\.lua$' |\
86+
xargs -L 1 -P $(($(nproc) + 1)) \
87+
python3 ./util/ci/indent_tab_preprocess.py "--[[" "]]"
5788
# Check for bad indent.
5889
# This runs over preprocessed files.
5990
# If there is any remaining space on line beginning or after tab,
6091
# error is generated
6192
- name: Check indent spaces
6293
run: |
63-
if git ls-files | grep -E '^src/.*\.cpp$|^src/.*\.[ch]$|\.lua' | xargs grep -n -P '^\t*[ ]'; then echo -e "\033[0;31mFound incorrect indent whitespaces"; (exit 1); else (exit 0); fi
94+
if git ls-files |\
95+
grep -E '^src/.*\.cpp$|^src/.*\.[ch]$|\.lua' |\
96+
xargs grep -n -P '^\t*[ ]';\
97+
then\
98+
echo -e "\033[0;31mFound incorrect indent whitespaces";\
99+
(exit 1);\
100+
else\
101+
(exit 0);\
102+
fi
64103
65104
tabs_lua_api_files:
66105
runs-on: ubuntu-latest
67106
steps:
68107
- uses: actions/checkout@v4
69108
# Some files should not contain tabs
70109
- name: Check tabs in Lua API files
71-
run: if grep -n $'\t' doc/lua_api.md doc/client_lua_api.md; then echo -e "\033[0;31mFound tab in markdown file"; (exit 1); else (exit 0); fi
72-
110+
run: |
111+
if grep -n $'\t' doc/lua_api.md doc/client_lua_api.md;\
112+
then\
113+
echo -e "\033[0;31mFound tab in markdown file";\
114+
(exit 1);\
115+
else\
116+
(exit 0);\
117+
fi
73118

builtin/common/vector.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ function vector.random_direction()
389389
local x, y, z, l2
390390
repeat -- expected less than two attempts on average (volume sphere vs. cube)
391391
x, y, z = math.random() * 2 - 1, math.random() * 2 - 1, math.random() * 2 - 1
392-
l2 = x*x + y*y + z*z
392+
l2 = x*x + y*y + z*z
393393
until l2 <= 1 and l2 >= 1e-6
394394
-- normalize
395395
local l = math.sqrt(l2)

builtin/fstk/buttonbar.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ local function buttonbar_formspec(self)
3838
-- `BASE_SPACING` is used as the minimum spacing, like `gap` in CSS Flexbox.
3939

4040
-- The number of buttons per page is always calculated as if the scroll
41-
-- buttons were visible.
41+
-- buttons were visible.
4242
local avail_space = self.size.x - 2*BASE_SPACING - 2*get_scroll_btn_width()
4343
local btns_per_page = math.floor((avail_space - BASE_SPACING) / (btn_size + BASE_SPACING))
4444

builtin/game/falling.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ core.register_entity(":__builtin:falling_node", {
7878
self.floats = core.get_item_group(node.name, "float") ~= 0
7979

8080
-- Save liquidtype for falling water
81-
self.liquidtype = def.liquidtype
81+
self.liquidtype = def.liquidtype
8282

8383
-- Set entity visuals
8484
if def.drawtype == "torchlike" or def.drawtype == "signlike" then

builtin/game/misc_s.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ end
3636

3737

3838
function core.setting_get_pos(name)
39-
return core.settings:get_pos(name)
39+
return core.settings:get_pos(name)
4040
end
4141

4242

builtin/mainmenu/dlg_clients_list.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ end
3232

3333
local function clients_list_buttonhandler(this, fields)
3434
if fields.quit then
35-
this:delete()
35+
this:delete()
3636
return true
3737
end
3838
return false

builtin/mainmenu/dlg_server_list_mods.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ end
7676

7777
local function buttonhandler(this, fields)
7878
if fields.quit then
79-
this:delete()
79+
this:delete()
8080
return true
8181
end
8282

games/devtest/mods/soundstuff/racecar.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ local drive_distance = 30
44

55
core.register_entity("soundstuff:racecar", {
66
initial_properties = {
7-
physical = false,
8-
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
9-
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
10-
visual = "upright_sprite",
11-
visual_size = {x = 1, y = 1, z = 1},
12-
textures = {"soundstuff_racecar.png", "soundstuff_racecar.png^[transformFX"},
13-
static_save = false,
14-
},
7+
physical = false,
8+
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
9+
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
10+
visual = "upright_sprite",
11+
visual_size = {x = 1, y = 1, z = 1},
12+
textures = {"soundstuff_racecar.png", "soundstuff_racecar.png^[transformFX"},
13+
static_save = false,
14+
},
1515

1616
on_activate = function(self, _staticdata, _dtime_s)
1717
self.min_x = self.object:get_pos().x - drive_distance * 0.5

games/devtest/mods/testentities/selectionbox.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ core.register_globalstep(function()
6868
hud_ids[pname] = hud_id or player:hud_add({
6969
type = "text", -- See HUD element types
7070
position = {x=0.5, y=0.5},
71-
text = "X",
71+
text = "X",
7272
number = 0xFF0000,
7373
alignment = {x=0, y=0},
7474
})

games/devtest/mods/testitems/init.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ core.register_craftitem("testitems:telescope_stick", {
110110
-- Tree spawners
111111

112112
local tree_def={
113-
axiom="Af",
114-
rules_a="TT[&GB][&+GB][&++GB][&+++GB]A",
115-
rules_b="[+GB]fB",
116-
trunk="basenodes:tree",
117-
leaves="basenodes:leaves",
118-
angle=90,
119-
iterations=4,
120-
trunk_type="single",
121-
thin_branches=true,
113+
axiom="Af",
114+
rules_a="TT[&GB][&+GB][&++GB][&+++GB]A",
115+
rules_b="[+GB]fB",
116+
trunk="basenodes:tree",
117+
leaves="basenodes:leaves",
118+
angle=90,
119+
iterations=4,
120+
trunk_type="single",
121+
thin_branches=true,
122122
}
123123

124124
core.register_craftitem("testitems:tree_spawner", {

games/devtest/mods/tiled/init.lua

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,38 @@ local align_help = "Texture spans over a space of 8×8 nodes"
22
local align_help_n = "Tiles looks the same for every node"
33

44
core.register_node("tiled:tiled", {
5-
description = "Tiled Node (world-aligned)".."\n"..align_help,
6-
tiles = {{
7-
name = "tiled_tiled.png",
8-
align_style = "world",
9-
scale = 8,
10-
}},
11-
groups = {cracky=3},
5+
description = "Tiled Node (world-aligned)".."\n"..align_help,
6+
tiles = {{
7+
name = "tiled_tiled.png",
8+
align_style = "world",
9+
scale = 8,
10+
}},
11+
groups = {cracky=3},
1212
})
1313

1414
core.register_node("tiled:tiled_rooted", {
15-
description = "Tiled 'plantlike_rooted' Node (world-aligned)".."\n"..
16-
"Base node texture spans over a space of 8×8 nodes".."\n"..
17-
"A plantlike thing grows on top",
18-
paramtype = "light",
19-
drawtype = "plantlike_rooted",
20-
tiles = {{
21-
name = "tiled_tiled.png",
22-
align_style = "world",
23-
scale = 8,
24-
}},
25-
special_tiles = {"tiled_tiled_node.png"},
26-
groups = {cracky=3},
15+
description =
16+
"Tiled 'plantlike_rooted' Node (world-aligned)".."\n"..
17+
"Base node texture spans over a space of 8×8 nodes".."\n"..
18+
"A plantlike thing grows on top",
19+
paramtype = "light",
20+
drawtype = "plantlike_rooted",
21+
tiles = {{
22+
name = "tiled_tiled.png",
23+
align_style = "world",
24+
scale = 8,
25+
}},
26+
special_tiles = {"tiled_tiled_node.png"},
27+
groups = {cracky=3},
2728
})
2829

2930
core.register_node("tiled:tiled_n", {
30-
description = "Tiled Node (node-aligned)".."\n"..align_help_n,
31-
tiles = {{
32-
name = "tiled_tiled_node.png",
33-
align_style = "node",
34-
}},
35-
groups = {cracky=3},
31+
description = "Tiled Node (node-aligned)".."\n"..align_help_n,
32+
tiles = {{
33+
name = "tiled_tiled_node.png",
34+
align_style = "node",
35+
}},
36+
groups = {cracky=3},
3637
})
3738

3839
stairs.register_stair_and_slab("tiled_n", "tiled:tiled_n",
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
local function assert_colors_equal(c1, c2)
2-
if type(c1) == "table" and type(c2) == "table" then
3-
assert(c1.r == c2.r and c1.g == c2.g and c1.b == c2.b and c1.a == c2.a)
4-
else
5-
assert(c1 == c2)
6-
end
2+
if type(c1) == "table" and type(c2) == "table" then
3+
assert(c1.r == c2.r and c1.g == c2.g and c1.b == c2.b and c1.a == c2.a)
4+
else
5+
assert(c1 == c2)
6+
end
77
end
88

99
local function test_color_conversion()
10-
assert_colors_equal(core.colorspec_to_table("#fff"), {r = 255, g = 255, b = 255, a = 255})
11-
assert_colors_equal(core.colorspec_to_table(0xFF00FF00), {r = 0, g = 255, b = 0, a = 255})
12-
assert_colors_equal(core.colorspec_to_table("#00000000"), {r = 0, g = 0, b = 0, a = 0})
13-
assert_colors_equal(core.colorspec_to_table("green"), {r = 0, g = 128, b = 0, a = 255})
14-
assert_colors_equal(core.colorspec_to_table("gren"), nil)
10+
assert_colors_equal(core.colorspec_to_table("#fff"), {r = 255, g = 255, b = 255, a = 255})
11+
assert_colors_equal(core.colorspec_to_table(0xFF00FF00), {r = 0, g = 255, b = 0, a = 255})
12+
assert_colors_equal(core.colorspec_to_table("#00000000"), {r = 0, g = 0, b = 0, a = 0})
13+
assert_colors_equal(core.colorspec_to_table("green"), {r = 0, g = 128, b = 0, a = 255})
14+
assert_colors_equal(core.colorspec_to_table("gren"), nil)
1515
end
1616

1717
unittests.register("test_color_conversion", test_color_conversion)
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11

22
unittests.register("test_get_version", function()
3-
local version = core.get_version()
4-
assert(type(version) == "table")
5-
assert(type(version.project) == "string")
6-
assert(type(version.string) == "string")
7-
assert(type(version.proto_min) == "number")
8-
assert(type(version.proto_max) == "number")
9-
assert(version.proto_max >= version.proto_min)
10-
assert(type(version.is_dev) == "boolean")
11-
if version.is_dev then
12-
assert(type(version.hash) == "string")
13-
else
14-
assert(version.hash == nil)
15-
end
3+
local version = core.get_version()
4+
assert(type(version) == "table")
5+
assert(type(version.project) == "string")
6+
assert(type(version.string) == "string")
7+
assert(type(version.proto_min) == "number")
8+
assert(type(version.proto_max) == "number")
9+
assert(version.proto_max >= version.proto_min)
10+
assert(type(version.is_dev) == "boolean")
11+
if version.is_dev then
12+
assert(type(version.hash) == "string")
13+
else
14+
assert(version.hash == nil)
15+
end
1616
end)

games/devtest/mods/unittests/raycast.lua

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
local function raycast_with_pointabilities(start_pos, end_pos, pointabilities)
22
local ray = core.raycast(start_pos, end_pos, nil, nil, pointabilities)
33
for hit in ray do
4-
if hit.type == "node" then
5-
return hit.under
6-
end
4+
if hit.type == "node" then
5+
return hit.under
6+
end
77
end
8-
return nil
8+
return nil
99
end
1010

1111
local function test_raycast_pointabilities(player, pos1)
12-
local pos2 = pos1:offset(0, 0, 1)
13-
local pos3 = pos1:offset(0, 0, 2)
12+
local pos2 = pos1:offset(0, 0, 1)
13+
local pos3 = pos1:offset(0, 0, 2)
1414

15-
local oldnode1 = core.get_node(pos1)
16-
local oldnode2 = core.get_node(pos2)
17-
local oldnode3 = core.get_node(pos3)
18-
core.swap_node(pos1, {name = "air"})
19-
core.swap_node(pos2, {name = "testnodes:not_pointable"})
20-
core.swap_node(pos3, {name = "testnodes:pointable"})
15+
local oldnode1 = core.get_node(pos1)
16+
local oldnode2 = core.get_node(pos2)
17+
local oldnode3 = core.get_node(pos3)
18+
core.swap_node(pos1, {name = "air"})
19+
core.swap_node(pos2, {name = "testnodes:not_pointable"})
20+
core.swap_node(pos3, {name = "testnodes:pointable"})
2121

22-
local p = nil
23-
assert(raycast_with_pointabilities(pos1, pos3, p) == pos3)
22+
local p = nil
23+
assert(raycast_with_pointabilities(pos1, pos3, p) == pos3)
2424

25-
p = core.registered_items["testtools:blocked_pointing_staff"].pointabilities
26-
assert(raycast_with_pointabilities(pos1, pos3, p) == nil)
25+
p = core.registered_items["testtools:blocked_pointing_staff"].pointabilities
26+
assert(raycast_with_pointabilities(pos1, pos3, p) == nil)
2727

28-
p = core.registered_items["testtools:ultimate_pointing_staff"].pointabilities
29-
assert(raycast_with_pointabilities(pos1, pos3, p) == pos2)
28+
p = core.registered_items["testtools:ultimate_pointing_staff"].pointabilities
29+
assert(raycast_with_pointabilities(pos1, pos3, p) == pos2)
3030

31-
core.swap_node(pos1, oldnode1)
32-
core.swap_node(pos2, oldnode2)
33-
core.swap_node(pos3, oldnode3)
31+
core.swap_node(pos1, oldnode1)
32+
core.swap_node(pos2, oldnode2)
33+
core.swap_node(pos3, oldnode3)
3434
end
3535

3636
unittests.register("test_raycast_pointabilities", test_raycast_pointabilities, {map=true})

games/devtest/mods/util_commands/init.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ core.register_chatcommand("dump_wear_bar", {
234234
})
235235

236236
core.register_chatcommand("set_saturation", {
237-
params = "<saturation>",
238-
description = "Set the saturation for current player.",
239-
func = function(player_name, param)
240-
local saturation = tonumber(param)
241-
core.get_player_by_name(player_name):set_lighting({saturation = saturation })
242-
end
237+
params = "<saturation>",
238+
description = "Set the saturation for current player.",
239+
func = function(player_name, param)
240+
local saturation = tonumber(param)
241+
core.get_player_by_name(player_name):set_lighting({saturation = saturation })
242+
end
243243
})

0 commit comments

Comments
 (0)