Skip to content

Commit

Permalink
Merge pull request #503 from dragonhunt02/linter
Browse files Browse the repository at this point in the history
Add linter to check assert/printerr
  • Loading branch information
fire authored Feb 18, 2025
2 parents 6e143c6 + e12cb0c commit 4b792d5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/code_style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ jobs:

- name: Run pre-commit
run: pre-commit run --all-files

- name: Run custom linter
run: bash .github/workflows/custom_linter.sh
45 changes: 45 additions & 0 deletions .github/workflows/custom_linter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
set -e

# Exclude files/directories with regex
EXCLUDE="./addons/vrm/.*
"

# Start
PATTERNS=''
while IFS= read -r line; do
PATTERNS="${PATTERNS}${line}|"
done <<< ${EXCLUDE:0:-1}
PATTERNS="${PATTERNS:0:-1}"

echo "Linter: Starting custom linter...";
match_error=false;

echo -e "Exclusion Pattern: $PATTERNS\n"

# Decision https://github.com/V-Sekai/v-sekai-game/issues/474#issuecomment-2603661420
# Forbid assert() for game code. Usage in third-party addons is allowed after review of side-effects.
matches=$( bash -c "find . -type f -regextype egrep -name '*.gd' -and -not -regex \"${PATTERNS}\" -exec grep -nH 'assert(' {} \;" )
if [ -n "$matches" ]; then
echo 'Linter: "assert()" usage is forbidden (assert checks are skipped in release versions causing potential undefined behaviour)';
echo 'Linter: use constructs like "if not ...: push_error(...); return" instead';
echo -e "$matches\n\n";
match_error=true;
fi

# Decision https://github.com/V-Sekai/v-sekai-game/issues/475#issue-2802564439
# Forbid printerr()
matches=$( bash -c "find . -type f -regextype egrep -name '*.gd' -and -not -regex \"${PATTERNS}\" -exec grep -nH 'printerr(' {} \;" )
if [ -n "$matches" ]; then
echo 'Linter: "printerr()" usage is forbidden (error output won'\''t be shown in Godot Debug panel)';
echo 'Linter: use "push_error()" instead';
echo -e "$matches\n\n";
match_error=true;
fi

if [ "$match_error" == 'true' ]; then
echo 'Linter: Solve errors and run again';
exit 1;
else
echo "Linter: All checks passed!"
fi
8 changes: 4 additions & 4 deletions addons/canvas_plane/canvas_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func _set_billboard_mode(p_billboard_mode: BillboardMode) -> void:
func _setup_canvas_item() -> void:
if !control_root.resized.is_connected(self._resized):
if control_root.resized.connect(self._resized) != OK:
printerr("Failed to connect control_root.resized signal.")
push_error("Failed to connect control_root.resized signal.")
return

original_canvas_rid = control_root.get_canvas()
Expand Down Expand Up @@ -259,11 +259,11 @@ func _ready() -> void:

# FIXME: No on_pointer_release or on_pointer_pressed here. Do we copy from canvas_plane.gd?
# if pointer_receiver.pointer_pressed.connect(self.on_pointer_pressed) != OK:
# printerr("Failed to connect pointer_receiver.pointer_pressed signal.")
# push_error("Failed to connect pointer_receiver.pointer_pressed signal.")
# return

# if pointer_receiver.pointer_release.connect(self.on_pointer_release) != OK:
# printerr("Failed to connect pointer_receiver.pointer_release signal.")
# push_error("Failed to connect pointer_receiver.pointer_release signal.")
# return

pointer_receiver.collision_mask = collision_mask
Expand Down Expand Up @@ -310,4 +310,4 @@ func _ready() -> void:

if Engine.is_editor_hint():
if get_tree().tree_changed.connect(self._tree_changed) != OK:
printerr("Could not connect tree_changed")
push_error("Could not connect tree_changed")

0 comments on commit 4b792d5

Please sign in to comment.