Skip to content

Commit a267b21

Browse files
committed
refactor: linting, naming
1 parent eb5ac7f commit a267b21

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

lua/copilot/auth/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function M.find_config_path()
153153
end
154154

155155
---@return table|nil
156-
M.get_creds = function()
156+
function M.get_creds()
157157
local filename = M.find_config_path() .. "/github-copilot/apps.json"
158158

159159
if vim.fn.filereadable(filename) == 0 then

lua/copilot/util.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function M.get_doc_params(overrides)
110110
return params
111111
end
112112

113-
M.get_plugin_path = function()
113+
function M.get_plugin_path()
114114
local copilot_path = vim.api.nvim_get_runtime_file("lua/copilot/init.lua", false)[1]
115115
if vim.fn.filereadable(copilot_path) ~= 0 then
116116
return vim.fn.fnamemodify(copilot_path, ":h:h:h")
@@ -189,7 +189,7 @@ end
189189
---@param cmd string|string[]
190190
---@param append string|string[]
191191
---@return string[]
192-
M.append_command = function(cmd, append)
192+
function M.append_command(cmd, append)
193193
local full_cmd = {}
194194

195195
-- first append the base command
Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
-- these are helper functions for testing the nodejs LSP integration
22
-- they stub out system interactions for verifying access to node and the LSP script
33

4-
Stub = {}
4+
M = {}
55

6-
Stub.default_server_path = "copilot/js/language-server.js"
7-
Stub.custom_server_path = "custom/path/to/language-server.js"
6+
M.default_server_path = "copilot/js/language-server.js"
7+
M.custom_server_path = "custom/path/to/language-server.js"
88

99
---@param stdout string the stdout that will be returned by the stubbed vim.system
1010
---@param code integer the exit code that will be returned by the stubbed vim.system
1111
---@param fail boolean if true, vim.system will error when called
1212
---@param callback function the function to call while vim.system is stubbed
1313
---@return table|nil captured_args -- the arguments vim.system was called with
14-
Stub.process = function(stdout, code, fail, callback)
14+
function M.process(stdout, code, fail, callback)
1515
local captured_args = nil
1616
local original_vim_system = vim.system
17+
18+
---@diagnostic disable-next-line: duplicate-set-field
1719
vim.system = function(cmd)
1820
captured_args = cmd
1921
if fail then
@@ -23,57 +25,63 @@ Stub.process = function(stdout, code, fail, callback)
2325
wait = function()
2426
return {
2527
stdout = stdout .. "\n",
26-
code = code
28+
code = code,
2729
}
28-
end
30+
end,
2931
}
3032
end
3133
-- wrap callback in pcall to ensure vim.system is restored if callback errors
3234
local ok, err = pcall(callback)
3335
vim.system = original_vim_system
34-
if not ok then error(err) end
36+
if not ok then
37+
error(err)
38+
end
3539
return captured_args
3640
end
3741

38-
Stub.valid_node_version = "20.0.0"
39-
Stub.invalid_node_version = "10.0.0"
42+
M.valid_node_version = "20.0.0"
43+
M.invalid_node_version = "10.0.0"
4044

4145
---Convenience wrapper for Stub.process for a valid Node.js version (>= 20)
42-
Stub.valid_node = function(callback)
43-
return Stub.process("v"..Stub.valid_node_version, 0, false, callback)
46+
function M.valid_node(callback)
47+
return M.process("v" .. M.valid_node_version, 0, false, callback)
4448
end
4549

4650
---Convenience wrapper for Stub.process for an invalid Node.js version (< 20)
47-
Stub.invalid_node = function(callback)
48-
return Stub.process("v"..Stub.invalid_node_version, 0, false, callback)
51+
function M.invalid_node(callback)
52+
return M.process("v" .. M.invalid_node_version, 0, false, callback)
4953
end
5054

5155
---@param callback function the function to call while vim.api.nvim_get_runtime_file is stubbed
5256
---@return string|nil captured_path -- the path vim.api.nvim_get_runtime_file was called with
53-
Stub.get_runtime_server_path = function(callback)
57+
function M.get_runtime_server_path(callback)
5458
local captured_path = nil
5559

5660
local original_get_file = vim.api.nvim_get_runtime_file
61+
---@diagnostic disable-next-line: duplicate-set-field
5762
vim.api.nvim_get_runtime_file = function(path)
5863
captured_path = path
59-
return { vim.fn.expand(Stub.default_server_path) }
64+
return { vim.fn.expand(M.default_server_path) }
6065
end
6166

6267
local original_filereadable = vim.fn.filereadable
68+
---@diagnostic disable-next-line: duplicate-set-field
6369
vim.fn.filereadable = function()
6470
return 1
6571
end
6672

6773
-- stub valid node version for callback so setup() succeeds
68-
Stub.valid_node(function()
74+
M.valid_node(function()
6975
-- wrap callback in pcall to ensure vim.api.nvim_get_runtime_file is restored if callback errors
7076
local ok, err = pcall(callback)
7177
vim.api.nvim_get_runtime_file = original_get_file
7278
vim.fn.filereadable = original_filereadable
73-
if not ok then error(err) end
79+
if not ok then
80+
error(err)
81+
end
7482
end)
7583

7684
return captured_path
7785
end
7886

79-
return Stub
87+
return M

tests/test_nodejs.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local eq = MiniTest.expect.equality
2-
local stub = require("tests.test_nodejs_stubs")
2+
local stub = require("tests.stubs.nodejs")
33

44
local T = MiniTest.new_set({
55
hooks = {
@@ -71,6 +71,7 @@ T["get_node_version()"]["handles vim.system failure"] = function()
7171
nodejs.setup("node")
7272

7373
local _, error = nodejs.get_node_version()
74+
error = error or ""
7475

7576
eq(error:find("Could not determine Node.js version") ~= nil, true)
7677
end)
@@ -83,6 +84,7 @@ T["get_node_version()"]["handles process with non-zero exit code"] = function()
8384
nodejs.setup("nonexistent-node")
8485

8586
local _, error = nodejs.get_node_version()
87+
error = error or ""
8688

8789
eq(error:find("Could not determine Node.js version") ~= nil, true)
8890
end)
@@ -95,6 +97,7 @@ T["get_node_version()"]["validates node version requirement"] = function()
9597
nodejs.setup("node")
9698

9799
local _, error = nodejs.get_node_version()
100+
error = error or ""
98101

99102
eq(error:find("Node.js version 20 or newer required") ~= nil, true)
100103
end)

0 commit comments

Comments
 (0)