From 66cb419db893ffe0242b27fba1e9fc87ed6715e5 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Wed, 2 Mar 2022 09:51:55 -0800 Subject: [PATCH] build: Add action for running luacheck Run luacheck on CI to catch subtle errors. Add a luacheckrc that ensures current code issues no warnings. We should eventually try to remove many of these ignores. --- .github/workflows/luacheck.yml | 26 +++++++++++++++++++ .luacheckrc | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 .github/workflows/luacheck.yml create mode 100644 .luacheckrc diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml new file mode 100644 index 0000000..723729d --- /dev/null +++ b/.github/workflows/luacheck.yml @@ -0,0 +1,26 @@ +name: Linting + +on: [push, pull_request] + +jobs: + luacheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + # Subdirectory to avoid linting luarocks code. Use same dir as testy. + path: batteries + - name: Setup Lua + uses: leafo/gh-actions-lua@v8 + with: + luaVersion: 5.4 + - name: Setup Lua Rocks + uses: leafo/gh-actions-luarocks@v4 + - name: Setup luacheck + run: luarocks install luacheck + - name: Run Code Linter + run: | + cd batteries + luacheck . diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..d3aad24 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,46 @@ +return { + std = "lua51+love", + ignore = { + "143", -- Accessing an undefined field of a global variable. + "211", -- Unused local variable. + "212", -- Unused argument. + "212/self", -- Unused argument self. + "213", -- Unused loop variable. + "231", -- Local variable is set but never accessed. + "311", -- Value assigned to a local variable is unused. + "412", -- Redefining an argument. + "413", -- Redefining a loop variable. + "421", -- Shadowing a local variable. + "422", -- Shadowing an argument. + "423", -- Shadowing a loop variable. + "423", -- Shadowing a loop variable. + "432", -- Shadowing an upvalue argument. + "611", -- A line consists of nothing but whitespace. + "612", -- A line contains trailing whitespace. + "614", -- Trailing whitespace in a comment. + "631", -- Line is too long. + }, + files = { + ["tests.lua"] = { + ignore = { + "211", -- Unused local variable. (testy will find these local functions) + }, + }, + ["assert.lua"] = { + ignore = { + "121", -- Setting a read-only global variable. (we clobber assert) + }, + }, + ["init.lua"] = { + ignore = { + "111", -- Setting an undefined global variable. (batteries and ripairs) + "121", -- Setting a read-only global variable. (we clobber assert) + }, + }, + ["sort.lua"] = { + ignore = { + "142", -- Setting an undefined field of a global variable. (inside export) + }, + }, + } +}