Skip to content

Commit fb38d3b

Browse files
committed
test: improve typing
1 parent e895b81 commit fb38d3b

8 files changed

Lines changed: 44 additions & 57 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Run Test
5454
run: make test
5555

56-
stylua:
56+
format:
5757
runs-on: ubuntu-latest
5858
steps:
5959
- name: Checkout
@@ -62,8 +62,8 @@ jobs:
6262
- name: Download stylua
6363
run: make stylua
6464

65-
- name: Lint
66-
run: make stylua-check
65+
- name: Format
66+
run: make format-check
6767

6868
emmylua:
6969
runs-on: ubuntu-latest

AGENTS.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
# Repository Guidelines
22

33
## Project Structure & Module Organization
4-
Core Lua modules live in `lua/gitsigns/` (config, handlers, utilities) and should stay pure so specs can require them directly.
5-
User-facing commands and autocmds are wired in `plugin/gitsigns.vim`, while help files under `doc/` get regenerated by `gen_help.lua`.
6-
Specs plus fixtures sit in `test/`, relying on helpers in `test/gs_helpers.lua`.
7-
Tooling binaries (Stylua, nvim-test, EmmyLua) are cached in `deps/`.
4+
- Core Lua modules live in `lua/gitsigns/` (config, handlers, utilities).
5+
- User-facing commands are wired in `plugin/gitsigns.vim`
6+
- Help files under `doc/` get regenerated by `gen_help.lua`.
7+
- Specs plus fixtures sit in `test/`, relying on helpers in `test/gs_helpers.lua`.
8+
- Tooling binaries (Stylua, nvim-test, EmmyLua) are cached in `deps/`.
89

910
## Build, Test, and Development Commands
1011
- `make build`: run Stylua over `lua/` + `test/`, then regenerate help files before committing.
1112
- `make test [FILTER=pattern]`: execute the functional suite via nvim-test with the default Neovim runner.
1213
- `make test-010`, `make test-011`, `make test-nightly`: confirm compatibility with multiple Neovim versions.
1314
- `make doc` / `make doc-check`: regenerate help from `lua/gitsigns/config.lua` and fail if docs drift.
14-
- `make stylua-check` or `make stylua-run`: lint or autoformat Lua sources.
15+
- `make format-check` or `make format`: lint or autoformat Lua sources.
1516
- `make emmylua-check`: run optional static analysis after fetching the analyzer.
1617

1718
## Coding Style & Naming Conventions
18-
Stylua enforces 2-space indentation, 100-character columns, Unix line endings, and `auto_prefer_single` quotes (`.stylua.toml`).
19-
Public modules export tables named after their file (e.g., `require('gitsigns.diff')`); local helpers stay snake_case.
20-
Keep API naming aligned with existing commands (`setup`, `attach`, `preview_hunk`) and prefer keyed tables over positional args.
21-
Wrap Neovim APIs in utility functions when tests need to mock them, and run `make stylua-run` before pushing.
19+
- Lua code must have emmylua/LuaCATS type annotations
20+
- 2-space indentation, 100-character columns, single quotes for strings.
21+
- Run `make format` after changing any code
2222

2323
## Testing Guidelines
24-
Specs reside in `test/*_spec.lua` and run under the `nvim-test` harness, which provisions a headless Neovim plus RPC helpers.
25-
Every bug fix must include a spec that reproduces the regression and asserts the desired buffer state, co-located with related modules (for example, `hunk_spec.lua` for hunk logic).
26-
Use `test/gs_helpers.lua` utilities instead of shelling out to Git, and reset repo fixtures between assertions.
27-
Keep tests deterministic by guarding optional Git features and running the version matrix (`make test-010 && make test-nightly`) when Neovim internals are touched.
24+
- Every bug fix must include a spec that reproduces the regression and asserts the desired buffer state, co-located with related modules (for example, `hunk_spec.lua` for hunk logic).
25+
- Keep tests deterministic by guarding optional Git features and running the version matrix (`make test-010 && make test-nightly`) when Neovim internals are touched.
2826

2927
## Commit & Pull Request Guidelines
30-
History follows a lightweight Conventional Commit style: `<type>(<scope>): <verb phrase>` (for instance, `fix(blame): close blame window on bufhidden`), so match that pattern and keep subjects under 72 characters.
31-
Each PR should recap the bug, list manual or automated verification, link upstream issues, and mention doc help updates when behavior changes.
32-
Ensure `make build`, the relevant `make test-*`, and `make doc-check` all pass locally.
28+
- History follows a Conventional Commit style: `<type>(<scope>): <verb phrase>` (for instance, `fix(blame): close blame window on bufhidden`), so match that pattern and keep subjects under 72 characters.
29+
- Ensure `make build`, the relevant `make test-*`, and `make doc-check` all pass locally.

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ endif
1010
.DEFAULT_GOAL := build
1111

1212
.PHONY: build
13-
build: doc stylua-run
13+
build: doc format
1414

1515
################################################################################
1616
# nvim-test
@@ -99,12 +99,12 @@ $(STYLUA): $(STYLUA_ZIP)
9999

100100
LUA_FILES := $(shell git ls-files lua test)
101101

102-
.PHONY: stylua-check
103-
stylua-check: $(STYLUA)
102+
.PHONY: format-check
103+
format-check: $(STYLUA)
104104
$(STYLUA) --check $(LUA_FILES)
105105

106-
.PHONY: stylua-run
107-
stylua-run: $(STYLUA)
106+
.PHONY: format
107+
format: $(STYLUA)
108108
$(STYLUA) $(LUA_FILES)
109109

110110
################################################################################

test/actions_spec.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ end
5151

5252
local delay = 10
5353

54+
--- @param cmd string
5455
local function command(cmd)
5556
helpers.sleep(delay)
5657
helpers.api.nvim_command(cmd)
@@ -72,7 +73,7 @@ local function retry(f)
7273
if ok then
7374
return
7475
end
75-
delay = delay * 1.6
76+
delay = math.ceil(delay * 1.6)
7677
print('failed, retrying with delay', delay)
7778
end
7879

test/gitsigns_spec.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ helpers.env()
3333

3434
---@param bufnr? integer
3535
local function wait_for_attach(bufnr)
36-
helpers.expectf(function()
36+
expectf(function()
3737
return exec_lua(function(bufnr0)
3838
return vim.b[bufnr0 or 0].gitsigns_status_dict.gitdir ~= nil
3939
end, bufnr)
@@ -770,7 +770,12 @@ describe('gitsigns (with screen)', function()
770770
signs = { changed = 1, added = 4 },
771771
})
772772

773-
exec_lua('require("gitsigns.actions").stage_hunk()')
773+
-- Minor delay to avoid the test being flaky
774+
helpers.sleep(50)
775+
776+
exec_lua(function()
777+
require('gitsigns.actions').stage_hunk()
778+
end)
774779

775780
check({
776781
status = { head = 'HEAD(rebasing)', added = 0, changed = 0, removed = 0 },
@@ -1038,7 +1043,7 @@ describe('gitsigns attach', function()
10381043
eq('gitsigns://' .. scratch .. '/.git//:0:sub/test', api.nvim_buf_get_name(0))
10391044

10401045
local gfile, toplevel, gitdir, abbrev_head = exec_lua(function()
1041-
local git_obj = require('gitsigns.cache').cache[1].git_obj
1046+
local git_obj = assert(require('gitsigns.cache').cache[1]).git_obj
10421047
return git_obj.file, git_obj.repo.toplevel, git_obj.repo.gitdir, git_obj.repo.abbrev_head
10431048
end)
10441049

test/gs_helpers.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ function M.expectf(cond, interval)
113113
local duration = 0
114114
interval = interval or 1
115115
while duration < timeout do
116-
--- @type boolean, boolean?
117116
local ok, ret = pcall(cond)
118117
if ok and (ret == nil or ret == true) then
119118
return
@@ -286,7 +285,7 @@ local function check_signs(signs, bufnr)
286285
local buf_signs = {} --- @type string[]
287286
local buf_marks = helpers.api.nvim_buf_get_extmarks(bufnr, -1, 0, -1, { details = true })
288287
for _, s in ipairs(buf_marks) do
289-
buf_signs[#buf_signs + 1] = s[4].sign_hl_group
288+
buf_signs[#buf_signs + 1] = assert(s[4]).sign_hl_group
290289
end
291290

292291
--- @type table<string,integer>

test/highlights_spec.lua

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ describe('highlights', function()
5656
it('get set up correctly', function()
5757
command('set termguicolors')
5858

59-
config.signs.add.hl = nil
60-
config.signs.change.hl = nil
61-
config.signs.delete.hl = nil
62-
config.signs.changedelete.hl = nil
63-
config.signs.topdelete.hl = nil
6459
config.numhl = true
6560
config.linehl = true
6661
config._test_mode = true
@@ -84,14 +79,7 @@ describe('highlights', function()
8479

8580
it('update when colorscheme changes', function()
8681
command('set termguicolors')
87-
88-
config.signs.add.hl = nil
89-
config.signs.change.hl = nil
90-
config.signs.delete.hl = nil
91-
config.signs.changedelete.hl = nil
92-
config.signs.topdelete.hl = nil
9382
config.linehl = true
94-
9583
setup_gitsigns(config)
9684
end)
9785
end)

test/hunk_spec.lua

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,32 @@ local eq = helpers.eq
66
helpers.env()
77

88
--- @param hunks [string,integer,integer,integer,integer][]
9-
--- @return [string,integer,integer][]
9+
--- @return [string,integer,integer?][]
1010
local function calc_signs(hunks)
11+
local hunks1 = {} --- @type Gitsigns.Hunk.Hunk[]
1112
for i, hunk in ipairs(hunks) do
12-
if hunk[1] then
13-
hunks[i] = {
14-
added = { count = hunk[4], start = hunk[5] },
15-
removed = { count = hunk[2], start = hunk[3] },
16-
type = hunk[1],
17-
}
18-
end
13+
hunks1[i] = {
14+
added = { count = hunk[4], start = hunk[5] },
15+
removed = { count = hunk[2], start = hunk[3] },
16+
type = hunk[1],
17+
}
1918
end
2019

21-
--- @type Gitsigns.Sign[]
2220
local signs = exec_lua(
2321
--- @param hunks0 Gitsigns.Hunk.Hunk[]
24-
--- @return Gitsigns.Sign[]
2522
function(hunks0)
2623
local Hunks = require('gitsigns.hunks')
27-
local signs = {}
24+
local signs0 = {} --- @type Gitsigns.Sign[]
2825
for i, hunk in ipairs(hunks0) do
2926
local prev_hunk, next_hunk = hunks0[i - 1], hunks0[i + 1]
30-
vim.list_extend(signs, Hunks.calc_signs(prev_hunk, hunk, next_hunk))
27+
vim.list_extend(signs0, Hunks.calc_signs(prev_hunk, hunk, next_hunk))
3128
end
32-
return signs
29+
return signs0
3330
end,
34-
hunks
31+
hunks1
3532
)
3633

37-
local r = {} --- @type [string,integer,integer][]
34+
local r = {} --- @type [string,integer,integer?][]
3835
for i, s in ipairs(signs) do
3936
r[i] = { s.type, s.lnum, s.count }
4037
end

0 commit comments

Comments
 (0)