Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no squash] Check for indent spaces #15002

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 76 additions & 3 deletions .github/workflows/whitespace_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- '**.sh'
- '**.cmake'
- '**.glsl'
- '**.lua'
pull_request:
paths:
- '**.txt'
Expand All @@ -24,6 +25,7 @@ on:
- '**.sh'
- '**.cmake'
- '**.glsl'
- '**.lua'

jobs:
trailing_whitespaces:
Expand All @@ -32,14 +34,85 @@ jobs:
- uses: actions/checkout@v4
# Line endings are already ensured by .gitattributes
- name: Check trailing whitespaces
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
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

indent_spaces:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Line endings are already ensured by .gitattributes
# Multiple multline comments in one line is not supported by this check
# and there is no reason to use them
# So lines like: "/* */ /*" or "*/ a = 5; /*" will result in error
- name: Check for unsupported multiline comments
run: |
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
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
# This prepare files for final check
# See python script ./util/ci/indent_tab_preprocess.py for details.
- name: Preprocess files
run: |
git ls-files |\
grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' |\
xargs -L 1 -P $(($(nproc) + 1)) \
python3 ./util/ci/indent_tab_preprocess.py "/*" "*/"
git ls-files |\
grep -E '\.lua$' |\
xargs -L 1 -P $(($(nproc) + 1)) \
python3 ./util/ci/indent_tab_preprocess.py "--[[" "]]"
# Check for bad indent.
# This runs over preprocessed files.
# If there is any remaining space on line beginning or after tab,
# error is generated
- name: Check indent spaces
run: |
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

tabs_lua_api_files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Some files should not contain tabs
- name: Check tabs in Lua API files
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

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

2 changes: 1 addition & 1 deletion builtin/common/vector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ function vector.random_direction()
local x, y, z, l2
repeat -- expected less than two attempts on average (volume sphere vs. cube)
x, y, z = math.random() * 2 - 1, math.random() * 2 - 1, math.random() * 2 - 1
l2 = x*x + y*y + z*z
l2 = x*x + y*y + z*z
until l2 <= 1 and l2 >= 1e-6
-- normalize
local l = math.sqrt(l2)
Expand Down
2 changes: 1 addition & 1 deletion builtin/fstk/buttonbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ local function buttonbar_formspec(self)
-- `BASE_SPACING` is used as the minimum spacing, like `gap` in CSS Flexbox.

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

Expand Down
2 changes: 1 addition & 1 deletion builtin/game/falling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ core.register_entity(":__builtin:falling_node", {
self.floats = core.get_item_group(node.name, "float") ~= 0

-- Save liquidtype for falling water
self.liquidtype = def.liquidtype
self.liquidtype = def.liquidtype

-- Set entity visuals
if def.drawtype == "torchlike" or def.drawtype == "signlike" then
Expand Down
2 changes: 1 addition & 1 deletion builtin/game/misc_s.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ end


function core.setting_get_pos(name)
return core.settings:get_pos(name)
return core.settings:get_pos(name)
end


Expand Down
2 changes: 1 addition & 1 deletion builtin/mainmenu/dlg_clients_list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end

local function clients_list_buttonhandler(this, fields)
if fields.quit then
this:delete()
this:delete()
return true
end
return false
Expand Down
2 changes: 1 addition & 1 deletion builtin/mainmenu/dlg_server_list_mods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ end

local function buttonhandler(this, fields)
if fields.quit then
this:delete()
this:delete()
return true
end

Expand Down
16 changes: 8 additions & 8 deletions games/devtest/mods/soundstuff/racecar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ local drive_distance = 30

core.register_entity("soundstuff:racecar", {
initial_properties = {
physical = false,
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
visual = "upright_sprite",
visual_size = {x = 1, y = 1, z = 1},
textures = {"soundstuff_racecar.png", "soundstuff_racecar.png^[transformFX"},
static_save = false,
},
physical = false,
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
visual = "upright_sprite",
visual_size = {x = 1, y = 1, z = 1},
textures = {"soundstuff_racecar.png", "soundstuff_racecar.png^[transformFX"},
static_save = false,
},

on_activate = function(self, _staticdata, _dtime_s)
self.min_x = self.object:get_pos().x - drive_distance * 0.5
Expand Down
2 changes: 1 addition & 1 deletion games/devtest/mods/testentities/selectionbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ core.register_globalstep(function()
hud_ids[pname] = hud_id or player:hud_add({
type = "text", -- See HUD element types
position = {x=0.5, y=0.5},
text = "X",
text = "X",
number = 0xFF0000,
alignment = {x=0, y=0},
})
Expand Down
18 changes: 9 additions & 9 deletions games/devtest/mods/testitems/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ core.register_craftitem("testitems:telescope_stick", {
-- Tree spawners

local tree_def={
axiom="Af",
rules_a="TT[&GB][&+GB][&++GB][&+++GB]A",
rules_b="[+GB]fB",
trunk="basenodes:tree",
leaves="basenodes:leaves",
angle=90,
iterations=4,
trunk_type="single",
thin_branches=true,
axiom="Af",
rules_a="TT[&GB][&+GB][&++GB][&+++GB]A",
rules_b="[+GB]fB",
trunk="basenodes:tree",
leaves="basenodes:leaves",
angle=90,
iterations=4,
trunk_type="single",
thin_branches=true,
}

core.register_craftitem("testitems:tree_spawner", {
Expand Down
51 changes: 26 additions & 25 deletions games/devtest/mods/tiled/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,38 @@ local align_help = "Texture spans over a space of 8×8 nodes"
local align_help_n = "Tiles looks the same for every node"

core.register_node("tiled:tiled", {
description = "Tiled Node (world-aligned)".."\n"..align_help,
tiles = {{
name = "tiled_tiled.png",
align_style = "world",
scale = 8,
}},
groups = {cracky=3},
description = "Tiled Node (world-aligned)".."\n"..align_help,
tiles = {{
name = "tiled_tiled.png",
align_style = "world",
scale = 8,
}},
groups = {cracky=3},
})

core.register_node("tiled:tiled_rooted", {
description = "Tiled 'plantlike_rooted' Node (world-aligned)".."\n"..
"Base node texture spans over a space of 8×8 nodes".."\n"..
"A plantlike thing grows on top",
paramtype = "light",
drawtype = "plantlike_rooted",
tiles = {{
name = "tiled_tiled.png",
align_style = "world",
scale = 8,
}},
special_tiles = {"tiled_tiled_node.png"},
groups = {cracky=3},
description =
"Tiled 'plantlike_rooted' Node (world-aligned)".."\n"..
"Base node texture spans over a space of 8×8 nodes".."\n"..
"A plantlike thing grows on top",
paramtype = "light",
drawtype = "plantlike_rooted",
tiles = {{
name = "tiled_tiled.png",
align_style = "world",
scale = 8,
}},
special_tiles = {"tiled_tiled_node.png"},
groups = {cracky=3},
})

core.register_node("tiled:tiled_n", {
description = "Tiled Node (node-aligned)".."\n"..align_help_n,
tiles = {{
name = "tiled_tiled_node.png",
align_style = "node",
}},
groups = {cracky=3},
description = "Tiled Node (node-aligned)".."\n"..align_help_n,
tiles = {{
name = "tiled_tiled_node.png",
align_style = "node",
}},
groups = {cracky=3},
})

stairs.register_stair_and_slab("tiled_n", "tiled:tiled_n",
Expand Down
20 changes: 10 additions & 10 deletions games/devtest/mods/unittests/color.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
local function assert_colors_equal(c1, c2)
if type(c1) == "table" and type(c2) == "table" then
assert(c1.r == c2.r and c1.g == c2.g and c1.b == c2.b and c1.a == c2.a)
else
assert(c1 == c2)
end
if type(c1) == "table" and type(c2) == "table" then
assert(c1.r == c2.r and c1.g == c2.g and c1.b == c2.b and c1.a == c2.a)
else
assert(c1 == c2)
end
end

local function test_color_conversion()
assert_colors_equal(core.colorspec_to_table("#fff"), {r = 255, g = 255, b = 255, a = 255})
assert_colors_equal(core.colorspec_to_table(0xFF00FF00), {r = 0, g = 255, b = 0, a = 255})
assert_colors_equal(core.colorspec_to_table("#00000000"), {r = 0, g = 0, b = 0, a = 0})
assert_colors_equal(core.colorspec_to_table("green"), {r = 0, g = 128, b = 0, a = 255})
assert_colors_equal(core.colorspec_to_table("gren"), nil)
assert_colors_equal(core.colorspec_to_table("#fff"), {r = 255, g = 255, b = 255, a = 255})
assert_colors_equal(core.colorspec_to_table(0xFF00FF00), {r = 0, g = 255, b = 0, a = 255})
assert_colors_equal(core.colorspec_to_table("#00000000"), {r = 0, g = 0, b = 0, a = 0})
assert_colors_equal(core.colorspec_to_table("green"), {r = 0, g = 128, b = 0, a = 255})
assert_colors_equal(core.colorspec_to_table("gren"), nil)
end

unittests.register("test_color_conversion", test_color_conversion)
26 changes: 13 additions & 13 deletions games/devtest/mods/unittests/get_version.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

unittests.register("test_get_version", function()
local version = core.get_version()
assert(type(version) == "table")
assert(type(version.project) == "string")
assert(type(version.string) == "string")
assert(type(version.proto_min) == "number")
assert(type(version.proto_max) == "number")
assert(version.proto_max >= version.proto_min)
assert(type(version.is_dev) == "boolean")
if version.is_dev then
assert(type(version.hash) == "string")
else
assert(version.hash == nil)
end
local version = core.get_version()
assert(type(version) == "table")
assert(type(version.project) == "string")
assert(type(version.string) == "string")
assert(type(version.proto_min) == "number")
assert(type(version.proto_max) == "number")
assert(version.proto_max >= version.proto_min)
assert(type(version.is_dev) == "boolean")
if version.is_dev then
assert(type(version.hash) == "string")
else
assert(version.hash == nil)
end
end)
42 changes: 21 additions & 21 deletions games/devtest/mods/unittests/raycast.lua
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
local function raycast_with_pointabilities(start_pos, end_pos, pointabilities)
local ray = core.raycast(start_pos, end_pos, nil, nil, pointabilities)
for hit in ray do
if hit.type == "node" then
return hit.under
end
if hit.type == "node" then
return hit.under
end
end
return nil
return nil
end

local function test_raycast_pointabilities(player, pos1)
local pos2 = pos1:offset(0, 0, 1)
local pos3 = pos1:offset(0, 0, 2)
local pos2 = pos1:offset(0, 0, 1)
local pos3 = pos1:offset(0, 0, 2)

local oldnode1 = core.get_node(pos1)
local oldnode2 = core.get_node(pos2)
local oldnode3 = core.get_node(pos3)
core.swap_node(pos1, {name = "air"})
core.swap_node(pos2, {name = "testnodes:not_pointable"})
core.swap_node(pos3, {name = "testnodes:pointable"})
local oldnode1 = core.get_node(pos1)
local oldnode2 = core.get_node(pos2)
local oldnode3 = core.get_node(pos3)
core.swap_node(pos1, {name = "air"})
core.swap_node(pos2, {name = "testnodes:not_pointable"})
core.swap_node(pos3, {name = "testnodes:pointable"})

local p = nil
assert(raycast_with_pointabilities(pos1, pos3, p) == pos3)
local p = nil
assert(raycast_with_pointabilities(pos1, pos3, p) == pos3)

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

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

core.swap_node(pos1, oldnode1)
core.swap_node(pos2, oldnode2)
core.swap_node(pos3, oldnode3)
core.swap_node(pos1, oldnode1)
core.swap_node(pos2, oldnode2)
core.swap_node(pos3, oldnode3)
end

unittests.register("test_raycast_pointabilities", test_raycast_pointabilities, {map=true})
Expand Down
Loading
Loading