Skip to content

Commit 6b12e00

Browse files
authored
chore: fix formatting (#342)
Co-authored-by: Oli Morris <olimorris@users.noreply.github.com>
1 parent 48451b7 commit 6b12e00

File tree

5 files changed

+123
-115
lines changed

5 files changed

+123
-115
lines changed

.github/workflows/format.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Format
2-
on: [push, pull_request]
2+
on: [pull_request]
33

44
jobs:
55
stylua:
@@ -10,4 +10,4 @@ jobs:
1010
with:
1111
token: ${{ secrets.GITHUB_TOKEN }}
1212
version: latest
13-
args: --check .
13+
args: tests/ lua/ --check .

examples/lua.lua

Lines changed: 109 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ NeotestAdapter.root = lib.files.match_root_pattern("Gemfile", ".rspec", ".gitign
2020
---@param file_path string
2121
---@return boolean
2222
function NeotestAdapter.is_test_file(file_path)
23-
return vim.endswith(file_path, "_spec.rb")
23+
return vim.endswith(file_path, "_spec.rb")
2424
end
2525

2626
---Given a file path, parse all the tests within it.
2727
---@async
2828
---@param file_path string Absolute file path
2929
---@return neotest.Tree | nil
3030
function NeotestAdapter.discover_positions(path)
31-
local query = [[
31+
local query = [[
3232
((call
3333
method: (identifier) @func_name (#match? @func_name "^(describe|context|feature)$")
3434
arguments: (argument_list (_) @namespace.name)
@@ -45,89 +45,95 @@ function NeotestAdapter.discover_positions(path)
4545
)) @test.definition
4646
]]
4747

48-
return lib.treesitter.parse_positions(path, query, {
49-
nested_tests = true,
50-
require_namespaces = true,
51-
position_id = "require('neotest-rspec.utils').generate_treesitter_id",
52-
})
48+
return lib.treesitter.parse_positions(path, query, {
49+
nested_tests = true,
50+
require_namespaces = true,
51+
position_id = "require('neotest-rspec.utils').generate_treesitter_id",
52+
})
5353
end
5454

5555
---@param test_name string
5656
---@return string
5757
local function clean_test_name(test_name)
58-
if string.sub(test_name, -1) == '"' or string.sub(test_name, -1) == "'" then test_name = test_name:sub(1, -2) end
59-
if string.sub(test_name, 1, 1) == '"' or string.sub(test_name, 1, 1) == "'" then
60-
test_name = test_name:sub(2, #test_name)
61-
end
62-
return test_name
58+
if string.sub(test_name, -1) == '"' or string.sub(test_name, -1) == "'" then
59+
test_name = test_name:sub(1, -2)
60+
end
61+
if string.sub(test_name, 1, 1) == '"' or string.sub(test_name, 1, 1) == "'" then
62+
test_name = test_name:sub(2, #test_name)
63+
end
64+
return test_name
6365
end
6466

6567
---@return string
6668
local function get_rspec_cmd()
67-
return vim.tbl_flatten({
68-
"bundle",
69-
"exec",
70-
"rspec",
71-
})
69+
return vim.tbl_flatten({
70+
"bundle",
71+
"exec",
72+
"rspec",
73+
})
7274
end
7375

7476
---@param args neotest.RunArgs
7577
---@return neotest.RunSpec | nil
7678
function NeotestAdapter.build_spec(args)
77-
local position = args.tree:data()
78-
local results_path = async.fn.tempname()
79-
80-
local script_args = vim.tbl_flatten({
81-
"-f",
82-
"json",
83-
"-o",
84-
results_path,
85-
"-f",
86-
"progress",
87-
})
88-
89-
local function run_by_filename()
90-
table.insert(script_args, position.path)
91-
end
92-
93-
local function run_by_test_name()
94-
table.insert(
95-
script_args,
96-
vim.tbl_flatten({
97-
"-e",
98-
clean_test_name(position.name),
99-
})
100-
)
101-
end
102-
103-
local function run_by_line_number()
104-
table.insert(
105-
script_args,
106-
vim.tbl_flatten({
107-
position.path .. ":" .. tonumber(position.range[1] + 1),
108-
})
109-
)
110-
end
111-
112-
if position.type == "file" then run_by_filename() end
113-
114-
if position.type == "test" or (position.type == "namespace" and vim.bo.filetype ~= "neotest-summary") then
115-
run_by_line_number()
116-
end
117-
118-
if position.type == "dir" and vim.bo.filetype == "neotest-summary" then run_by_filename() end
119-
120-
local command = vim.tbl_flatten({
121-
get_rspec_cmd(),
122-
script_args,
123-
})
124-
125-
return {
126-
command = command,
127-
context = {
128-
results_path = results_path,
129-
},
130-
}
79+
local position = args.tree:data()
80+
local results_path = async.fn.tempname()
81+
82+
local script_args = vim.tbl_flatten({
83+
"-f",
84+
"json",
85+
"-o",
86+
results_path,
87+
"-f",
88+
"progress",
89+
})
90+
91+
local function run_by_filename()
92+
table.insert(script_args, position.path)
93+
end
94+
95+
local function run_by_test_name()
96+
table.insert(
97+
script_args,
98+
vim.tbl_flatten({
99+
"-e",
100+
clean_test_name(position.name),
101+
})
102+
)
103+
end
104+
105+
local function run_by_line_number()
106+
table.insert(
107+
script_args,
108+
vim.tbl_flatten({
109+
position.path .. ":" .. tonumber(position.range[1] + 1),
110+
})
111+
)
112+
end
113+
114+
if position.type == "file" then
115+
run_by_filename()
116+
end
117+
118+
if position.type == "test" or (position.type == "namespace" and vim.bo.filetype ~= "neotest-summary") then
119+
run_by_line_number()
120+
end
121+
122+
if position.type == "dir" and vim.bo.filetype == "neotest-summary" then
123+
run_by_filename()
124+
end
125+
126+
local command = vim.tbl_flatten({
127+
get_rspec_cmd(),
128+
script_args,
129+
})
130+
131+
return {
132+
command = command,
133+
context = {
134+
results_path = results_path,
135+
},
136+
}
131137
end
132138

133139
---@async
@@ -136,44 +142,44 @@ end
136142
---@param tree neotest.Tree
137143
---@return neotest.Result[]
138144
function NeotestAdapter.results(spec, result, tree)
139-
local output_file = spec.context.results_path
140-
141-
local ok, data = pcall(lib.files.read, output_file)
142-
if not ok then
143-
logger.error("No test output file found:", output_file)
144-
return {}
145-
end
146-
147-
local ok, parsed_data = pcall(vim.json.decode, data, { luanil = { object = true } })
148-
if not ok then
149-
logger.error("Failed to parse test output:", output_file)
150-
return {}
151-
end
152-
153-
local ok, results = pcall(utils.parse_json_output, parsed_data, output_file)
154-
if not ok then
155-
logger.error("Failed to get test results:", output_file)
156-
return {}
157-
end
158-
159-
return results
145+
local output_file = spec.context.results_path
146+
147+
local ok, data = pcall(lib.files.read, output_file)
148+
if not ok then
149+
logger.error("No test output file found:", output_file)
150+
return {}
151+
end
152+
153+
local ok, parsed_data = pcall(vim.json.decode, data, { luanil = { object = true } })
154+
if not ok then
155+
logger.error("Failed to parse test output:", output_file)
156+
return {}
157+
end
158+
159+
local ok, results = pcall(utils.parse_json_output, parsed_data, output_file)
160+
if not ok then
161+
logger.error("Failed to get test results:", output_file)
162+
return {}
163+
end
164+
165+
return results
160166
end
161167

162168
local is_callable = function(obj)
163-
return type(obj) == "function" or (type(obj) == "table" and obj.__call)
169+
return type(obj) == "function" or (type(obj) == "table" and obj.__call)
164170
end
165171

166172
setmetatable(NeotestAdapter, {
167-
__call = function(_, opts)
168-
if is_callable(opts.rspec_cmd) then
169-
get_rspec_cmd = opts.rspec_cmd
170-
elseif opts.rspec_cmd then
171-
get_rspec_cmd = function()
172-
return opts.rspec_cmd
173-
end
174-
end
175-
return NeotestAdapter
176-
end,
173+
__call = function(_, opts)
174+
if is_callable(opts.rspec_cmd) then
175+
get_rspec_cmd = opts.rspec_cmd
176+
elseif opts.rspec_cmd then
177+
get_rspec_cmd = function()
178+
return opts.rspec_cmd
179+
end
180+
end
181+
return NeotestAdapter
182+
end,
177183
})
178184

179185
return NeotestAdapter

lua/onedarkpro/config.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ function M.setup(opts)
195195
if M.config.options.cursorline then
196196
vim.wo.cursorline = true
197197
end
198-
if opts and opts.filetypes then
198+
if opts.filetypes then
199199
M.config.filetypes = load_files(M.config.filetypes, opts.filetypes)
200200
end
201-
if opts and opts.plugins then
201+
if opts.plugins then
202202
M.config.plugins = load_files(M.config.plugins, opts.plugins)
203203
end
204204

plugin/onedarkpro.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
if vim.g.loaded_onedarkpro then return end
1+
if vim.g.loaded_onedarkpro then
2+
return
3+
end
24

35
local cmds = require("onedarkpro.commands")
46
for _, cmd in ipairs(cmds) do
5-
vim.api.nvim_create_user_command(cmd.cmd, cmd.callback, cmd.opts)
7+
vim.api.nvim_create_user_command(cmd.cmd, cmd.callback, cmd.opts)
68
end
79

810
vim.g.loaded_onedarkpro = true

scripts/minimal_init.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ require("mini.test").setup()
88

99
-- Install and setup Tree-sitter
1010
require("nvim-treesitter").setup({
11-
install_dir = "deps/parsers",
11+
install_dir = "deps/parsers",
1212
})
1313

1414
require("nvim-treesitter")
15-
.install({
16-
"lua",
17-
"python",
18-
}, { force = true, summary = true, generate = true })
19-
:pwait(300000)
15+
.install({
16+
"lua",
17+
"python",
18+
}, { force = true, summary = true, generate = true })
19+
:pwait(300000)

0 commit comments

Comments
 (0)