Skip to content
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
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ jobs:
version: v2.1.0
args: false # Will be run as part of `make check`

- name: Install lua-language-server
run: |
curl -sL "https://github.com/LuaLS/lua-language-server/releases/download/$LUALS/lua-language-server-$LUALS-linux-x64.tar.gz" \
| tar -xz -C "$RUNNER_TEMP"
echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH"
env:
LUALS: 3.19.0

- name: Check
run: make check

Expand Down
20 changes: 20 additions & 0 deletions .luarc-typecheck.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"runtime": {
"version": "LuaJIT"
},
"workspace": {
"useGitIgnore": false,
"ignoreDir": [
".claude",
".git",
".idea",
".install",
".lua",
".luarocks",
".venv",
"build",
"dist",
"node_modules"
]
}
}
17 changes: 17 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,27 @@ make format
# Lint code
make lint

# Check LuaCATS annotations with lua-language-server
make typecheck

# Build single-file distribution
make build
```

### typecheck

`make typecheck` runs lua-language-server against a committed
`.luarc-typecheck.json` rather than whatever `.luarc.json` a developer has
locally. It catches what luacheck does not: undefined or duplicate `@alias`,
returns that disagree with `@return`, fields missing from a `@class`.

`runtime.version` in that config is load-bearing. Left unset the server defaults
to Lua 5.4 and checks this library as the wrong language, which reports a
different set of findings rather than fewer. It is pinned to LuaJIT.

Part of `check`, so CI enforces it. Clean under both 3.18.2 and 3.19.0; CI pins
3.19.0 because the findings do move between versions.

## Architecture

### Module Design
Expand Down
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,24 @@ lint:
exit 1; \
fi

# Type-check annotations with the Lua language server. Catches what luacheck does
# not: undefined or duplicate `@alias`, returns that disagree with `@return`.
#
# `runtime.version` in the pinned config is load-bearing: unset, the server
# defaults to Lua 5.4 and checks this library as the wrong language.
.PHONY: typecheck
typecheck:
@if command -v lua-language-server >/dev/null 2>&1; then \
echo "Running lua-language-server $$(lua-language-server --version)..."; \
lua-language-server --check "$(CURDIR)" --checklevel=Warning \
--configpath="$(CURDIR)/.luarc-typecheck.json" --logpath="$(CURDIR)/build/luals"; \
else \
echo "lua-language-server not found. Install with: make install-deps"; \
exit 1; \
fi

.PHONY: check
check: format-check lint
check: format-check lint typecheck
@echo "Code quality checks complete."

# Clean generated files
Expand Down Expand Up @@ -186,6 +202,7 @@ help:
@echo " make format - Format code with stylua"
@echo " make format-check - Check code formatting"
@echo " make lint - Lint code with luacheck"
@echo " make typecheck - Check annotations with lua-language-server"
@echo ""
@echo "Setup:"
@echo " make install-deps - Install development dependencies"
Expand Down
10 changes: 6 additions & 4 deletions src/bitn/_compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@ end
local bit_lib
local is_luajit = false

-- Try LuaJIT's bit library first
ok, result = pcall(require, "bit")
if ok and result then
bit_lib = result
-- Try LuaJIT's bit library first. Fresh locals rather than the pcall results
-- from the native-operator probe above: that `result` is a compiled chunk, this
-- one is a library table.
local bit_ok, bit_module = pcall(require, "bit")
if bit_ok and bit_module then
bit_lib = bit_module
is_luajit = true
else
-- Try Lua 5.2's bit32 library (use rawget to avoid recursion with our module name)
Expand Down
21 changes: 12 additions & 9 deletions src/bitn/bit64.lua
Original file line number Diff line number Diff line change
Expand Up @@ -942,20 +942,23 @@ function bit64.selftest()
for _, test in ipairs(test_vectors) do
total = total + 1
local result = test.fn(unpack_fn(test.inputs))
-- Held in a local so the type narrowing below applies to it; a table field
-- is not narrowed by a `type()` check.
local expected = test.expected

if type(test.expected) == "table" then
if type(expected) == "table" then
-- 64-bit comparison
if eq64(result, test.expected) then
if eq64(result, expected) then
print(" PASS: " .. test.name)
passed = passed + 1
else
print(" FAIL: " .. test.name)
print(" Expected: " .. fmt64(test.expected))
print(" Expected: " .. fmt64(expected))
print(" Got: " .. fmt64(result))
end
elseif type(test.expected) == "string" then
elseif type(expected) == "string" then
-- Byte string comparison
if result == test.expected then
if result == expected then
print(" PASS: " .. test.name)
passed = passed + 1
else
Expand All @@ -965,8 +968,8 @@ function bit64.selftest()
print(" Got: " .. type(result))
else
local exp_hex, got_hex = "", ""
for i = 1, #test.expected do
exp_hex = exp_hex .. string.format("%02X", string.byte(test.expected, i))
for i = 1, #expected do
exp_hex = exp_hex .. string.format("%02X", string.byte(expected, i))
end
for i = 1, #result do
got_hex = got_hex .. string.format("%02X", string.byte(result, i))
Expand All @@ -976,12 +979,12 @@ function bit64.selftest()
end
end
else
if result == test.expected then
if result == expected then
print(" PASS: " .. test.name)
passed = passed + 1
else
print(" FAIL: " .. test.name)
print(" Expected: " .. tostring(test.expected))
print(" Expected: " .. tostring(expected))
print(" Got: " .. tostring(result))
end
end
Expand Down
Loading