-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #503 from dragonhunt02/linter
Add linter to check assert/printerr
- Loading branch information
Showing
3 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters