Skip to content

Commit

Permalink
Merge pull request #588 from pallene-lang/lint-check-exp
Browse files Browse the repository at this point in the history
Linter: enforce that we use return value of check_exp
  • Loading branch information
hugomg committed Jun 13, 2023
2 parents ac953c3 + cd71262 commit b1c0c87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions run-lint
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
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

0 comments on commit b1c0c87

Please sign in to comment.