Skip to content

Commit 0a87e0c

Browse files
committed
Fix: Update luacheckrc to properly handle spec files
1 parent 0861aba commit 0a87e0c

File tree

2 files changed

+57
-20
lines changed

2 files changed

+57
-20
lines changed

.luacheckrc

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ files["tests/**/*.lua"] = {
4646
-- Test helpers
4747
"test", "expect",
4848
-- Global test state (allow modification)
49-
"_G",
49+
"_G", "package",
5050
},
5151

5252
-- Define fields for assert from luassert
@@ -70,14 +70,38 @@ files["tests/**/*.lua"] = {
7070
-- In tests, we're not concerned about these
7171
max_cyclomatic_complexity = false,
7272

73-
-- Don't report accessing/mutating globals that are needed for test frameworks
74-
read_globals = {
75-
"_G", -- Global environment
76-
"package", -- Package management
73+
-- For test files only, ignore unused arguments as they're often used for mock callbacks
74+
unused_args = false,
75+
}
76+
77+
-- Special configuration for spec files
78+
files["spec/**/*.lua"] = {
79+
-- Allow common globals used in testing
80+
globals = {
81+
-- Common busted globals
82+
"describe", "it", "before_each", "after_each", "teardown", "pending", "spy", "stub", "mock",
83+
-- Lua standard utilities used in tests
84+
"print", "dofile",
85+
-- Luassert
86+
"assert",
87+
-- Global state that specs might modify
88+
"_G", "vim", "package",
7789
},
7890

79-
-- For test files only, ignore unused arguments as they're often used for mock callbacks
91+
-- Allow modification of globals in spec files
92+
allow_defined_top = true,
93+
94+
-- Disable module checking in specs
95+
module = false,
96+
97+
-- In specs, we're not concerned about these
98+
max_cyclomatic_complexity = false,
99+
100+
-- For specs, ignore unused arguments
80101
unused_args = false,
102+
103+
-- Set all standard globals as writable in specs
104+
std = "+busted",
81105
}
82106

83107
-- Allow unused self arguments of methods

spec/laravel_helper_spec.lua

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,28 @@ describe("Laravel Helper", function()
66

77
before_each(function()
88
-- Mock vim namespace for testing
9-
_G.vim = _G.vim or {}
10-
_G.vim.fn = _G.vim.fn or {}
11-
_G.vim.fn.filereadable = _G.vim.fn.filereadable
9+
---@diagnostic disable: lowercase-global
10+
---@diagnostic disable: duplicate-set-field
11+
---@diagnostic disable: inject-field
12+
vim = vim or {}
13+
vim.fn = vim.fn or {}
14+
vim.fn.filereadable = vim.fn.filereadable
1215
or function(path)
1316
-- Simply return 1 for artisan files, 0 otherwise
1417
return path:match("artisan$") and 1 or 0
1518
end
16-
_G.vim.fn.getcwd = _G.vim.fn.getcwd or function()
19+
vim.fn.getcwd = vim.fn.getcwd or function()
1720
return "/test/project"
1821
end
19-
_G.vim.fn.exists = _G.vim.fn.exists or function()
22+
vim.fn.exists = vim.fn.exists or function()
2023
return 0
2124
end
22-
_G.vim.g = _G.vim.g or {}
23-
_G.vim.notify = _G.vim.notify or function() end
24-
_G.vim.api = _G.vim.api or {}
25-
_G.vim.api.nvim_create_autocmd = _G.vim.api.nvim_create_autocmd or function() end
26-
_G.vim.log = _G.vim.log or { levels = { INFO = 2, WARN = 3, ERROR = 4 } }
27-
_G.vim.tbl_deep_extend = _G.vim.tbl_deep_extend
25+
vim.g = vim.g or {}
26+
vim.notify = vim.notify or function() end
27+
vim.api = vim.api or {}
28+
vim.api.nvim_create_autocmd = vim.api.nvim_create_autocmd or function() end
29+
vim.log = vim.log or { levels = { INFO = 2, WARN = 3, ERROR = 4 } }
30+
vim.tbl_deep_extend = vim.tbl_deep_extend
2831
or function(_, tbl1, tbl2)
2932
local result = {}
3033
for k, v in pairs(tbl1 or {}) do
@@ -36,20 +39,28 @@ describe("Laravel Helper", function()
3639
return result
3740
end
3841

39-
_G.vim.validate = function() end
42+
vim.validate = function() end
4043

41-
_G.vim.deepcopy = function(obj)
44+
vim.deepcopy = function(obj)
4245
if type(obj) ~= "table" then
4346
return obj
4447
end
4548
local res = {}
4649
for k, v in pairs(obj) do
47-
res[k] = _G.vim.deepcopy(v)
50+
res[k] = vim.deepcopy(v)
4851
end
4952
return res
5053
end
54+
---@diagnostic enable: inject-field
55+
---@diagnostic enable: duplicate-set-field
56+
---@diagnostic enable: lowercase-global
5157

5258
-- Reset modules to ensure clean testing
59+
---@diagnostic disable: inject-field
60+
---@diagnostic disable: lowercase-global
61+
-- luacheck: ignore 122
62+
package = package or {}
63+
package.loaded = package.loaded or {}
5364
package.loaded["laravel-helper"] = nil
5465
package.loaded["laravel-helper.core"] = nil
5566
package.loaded["laravel-helper.commands"] = nil
@@ -79,6 +90,8 @@ describe("Laravel Helper", function()
7990
}
8091

8192
package.loaded["laravel-helper.config"] = {
93+
---@diagnostic enable: inject-field
94+
---@diagnostic enable: lowercase-global
8295
setup = function() end,
8396
parse_config = function(user_config)
8497
local config = {

0 commit comments

Comments
 (0)