diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index ebf124e3..93717463 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -8,6 +8,7 @@ on: - "*.lua" - ".stylua.toml" - ".luacheckrc" + - ".pre-commit-config.yaml" - "lux.toml" - "lux.lock" - ".github/workflows/static-analysis.yml" @@ -19,32 +20,45 @@ on: - "*.lua" - ".stylua.toml" - ".luacheckrc" + - ".pre-commit-config.yaml" - "lux.toml" - "lux.lock" - ".github/workflows/static-analysis.yml" - ".github/workflows/lux.yml" jobs: - luacheck: + lint: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v7 - - name: Luacheck - uses: lunarmodules/luacheck@v1.2.0 + - name: Install Lux + uses: lumen-oss/gh-actions-lux@v1 + with: + version: 0.46.0 + # lux's auto-installed static Lua can't dlopen C modules + # (`lfs.so: undefined symbol: lua_gettop`), which `lx lint` + # needs via luacheck → luafilesystem. A distro Lua links + # liblua dynamically, so luafilesystem loads fine when lux + # detects and uses the system interpreter instead. + - name: Install system Lua 5.1 + run: sudo apt-get update && sudo apt-get install -y lua5.1 liblua5.1-0-dev + - name: Lint with lux + run: lx --lua-version 5.1 lint - stylua: + fmt: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v7 - - name: Stylua - uses: JohnnyMorganz/stylua-action@v5 + - name: Install Lux + uses: lumen-oss/gh-actions-lux@v1 with: - token: ${{ secrets.GITHUB_TOKEN }} - version: latest # NOTE: we recommend pinning to a specific version in case of formatting changes - # CLI arguments - args: --check . + version: 0.46.0 + - name: Check formatting with lux + run: | + lx --lua-version 5.1 fmt + git diff --exit-code lua-language-server: runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 81ad7b7b..7feb70bc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,19 +40,19 @@ repos: - repo: local hooks: - - id: stylua_check - name: Stylua Check - entry: stylua + - id: lux_fmt + name: Lux Fmt + entry: lx --lua-version 5.1 fmt language: system - pass_filenames: true + pass_filenames: false types_or: [lua] stages: [pre-commit] - - id: luacheck - name: Luacheck - entry: luacheck + - id: lux_lint + name: Lux Lint + entry: lx --lua-version 5.1 lint language: system - pass_filenames: true + pass_filenames: false types_or: [lua] stages: [pre-commit] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 15af9acf..f208ad1d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,13 +22,22 @@ You will need: - Java JDK 17 or 21 - The following tools available in your terminal: - pre-commit () - - `stylua` - - `luacheck` - - `make` - - `git` - `lx` () — for package management (`lux.toml` is the single source of truth - for the luarocks package) + for the luarocks package), formatting (`lx fmt`) + and linting (`lx lint`) + - `make` + - `git` + +> On Linux, `lx lint` needs a dynamically-linked Lua 5.1, +> otherwise luacheck's `luafilesystem` module fails to load +> (`lfs.so: undefined symbol: lua_gettop`): +> +> ```bash +> sudo apt-get install lua5.1 liblua5.1-0-dev +> ``` +> +> macOS works out of the box. #### First build @@ -108,6 +117,9 @@ make lux-sync # Build the project make lux-build +# Format via lux (stylua) +make lux-fmt + # Lint via lux (luacheck) make lux-lint diff --git a/Makefile b/Makefile index b8c6e361..36924914 100755 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: clean test test-fail-fast test-e2e lux-sync lux-build lux-lint lux-test +.PHONY: clean test test-fail-fast test-e2e lux-sync lux-build lux-fmt lux-lint lux-test all: hooks test @@ -67,6 +67,9 @@ lux-sync: lux-build: lx --lua-version 5.1 build +lux-fmt: + lx --lua-version 5.1 fmt + lux-lint: lx --lua-version 5.1 lint