diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0204588..8f1be26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,26 @@ jobs: - name: Check formatting run: make fmt-check + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Lua and LuaRocks + uses: leafo/gh-actions-lua@v11 + with: + luaVersion: "5.1" + + - name: Setup LuaRocks + uses: leafo/gh-actions-luarocks@v5 + + - name: Install luacheck + run: luarocks install luacheck + + - name: Run lint + run: make lint + test: name: Test runs-on: ubuntu-latest diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..311dc9d --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,19 @@ +std = "lua51" + +globals = { + "vim", +} + +files["tests/**/*.lua"] = { + globals = { + "vim", + "describe", + "it", + "before_each", + "after_each", + "setup", + "teardown", + "pending", + "assert", + }, +} diff --git a/Makefile b/Makefile index 3f2226a..f925c83 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: test test-file clean fmt fmt-check +.PHONY: test test-file clean fmt fmt-check lint # Test runner PLENARY_DIR ?= /tmp/plenary.nvim @@ -39,3 +39,7 @@ fmt: # Check Lua formatting fmt-check: stylua --check lua plugin tests + +# Lint Lua files +lint: + luacheck lua plugin tests diff --git a/README.md b/README.md index 94d8caf..8c3e587 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,12 @@ make fmt make fmt-check ``` +* Run lint: + +```sh +make lint +``` + * Run tests: ```sh diff --git a/lua/comment-translate/commands.lua b/lua/comment-translate/commands.lua index 4e51aee..f98f6fc 100644 --- a/lua/comment-translate/commands.lua +++ b/lua/comment-translate/commands.lua @@ -181,7 +181,7 @@ end local function disable_all_buffers() ui.virtual_text.clear_all() - for buf, state in pairs(immersive_state) do + for _, state in pairs(immersive_state) do state.enabled = false bump_token(state) end diff --git a/tests/integration_spec.lua b/tests/integration_spec.lua index c091f3d..26f9d09 100644 --- a/tests/integration_spec.lua +++ b/tests/integration_spec.lua @@ -291,7 +291,6 @@ describe('integration', function() describe('manual hover mode', function() local config - local commands before_each(function() for name, _ in pairs(package.loaded) do @@ -312,7 +311,7 @@ describe('integration', function() }, }) - commands = require('comment-translate.commands') + require('comment-translate.commands') end) it('should have auto hover disabled in config', function() diff --git a/tests/llm_spec.lua b/tests/llm_spec.lua index 8d7f898..e22f408 100644 --- a/tests/llm_spec.lua +++ b/tests/llm_spec.lua @@ -33,7 +33,7 @@ describe('translate.llm', function() } local FakeJob = {} - function FakeJob:new(opts) + function FakeJob.new(_, opts) job_state.new_calls = job_state.new_calls + 1 job_state.last_opts = opts return setmetatable({ @@ -43,11 +43,11 @@ describe('translate.llm', function() result = function() return { job_state.stdout } end, - start = function(self) + start = function(job) for _, line in ipairs(job_state.stderr_lines or {}) do - self._opts.on_stderr(nil, line) + job._opts.on_stderr(nil, line) end - self._opts.on_exit(self, job_state.exit_code) + job._opts.on_exit(job, job_state.exit_code) end, }, }) diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua index dc2114a..5018f00 100644 --- a/tests/minimal_init.lua +++ b/tests/minimal_init.lua @@ -1,5 +1,7 @@ ---Minimal init for running tests ----Usage: nvim --headless -u tests/minimal_init.lua -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal_init.lua'}" +---Usage: +---nvim --headless -u tests/minimal_init.lua +---Then run PlenaryBustedDirectory with this minimal_init. local plenary_dir = os.getenv('PLENARY_DIR') or '/tmp/plenary.nvim' local is_not_a_directory = vim.fn.isdirectory(plenary_dir) == 0