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

Linter: enforce that we use return value of check_exp #588

Merged
merged 4 commits into from
Jun 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions run-lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

space=' '
tab=' '
ok=yes

red='\033[1;31m'
green='\033[1;32m'
reset='\033[0m'

ok=yes

error() {
printf "${red}ERROR${reset} %s\n" "$*"
ok=no
}

echo "--- Lua Lint ---"
luacheck src/ spec/ examples/ "$@" || exit 1
luacheck src/ spec/ examples/ "$@" || error "Luacheck found problems"
echo

echo "--- Other checks ---"
Expand All @@ -31,7 +32,7 @@ do
error "File $file has a line that ends in whitespace"
fi

if grep --line-number "^$tab" "$file"; then
if grep --line-number "^$space*$tab" "$file"; then
# Standardize on spaces because mixing tabs and spaces is endless pain.
error "File $file has tab-based indentation"
fi
Expand All @@ -41,6 +42,14 @@ do
fi
done

if grep --line-number -E \
"^[$space$tab]*self:(check_exp|check_var|check_initializer)" \
src/pallene/typechecker.lua;
then
# Using grep to catch this logic error isn't ideal, but it's better than nothing.
error "You should not ignore the return value here"
fi

if [ "$ok" != yes ]; then
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion src/pallene/typechecker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
--
-- IMPORTANT: For these transformations to work you should always use the return value from the
-- check_exp and check_var functions. For example, instead of just `check_exp(foo.exp)` you should
-- always write `foo.exp = check_exp(foo.exp)`.
-- always write `foo.exp = check_exp(foo.exp)`. Our linter script enforces this.

local typechecker = {}

Expand Down