build: replace luacheck with selene, add nix devshell and pre-commit (#20)
* build: replace luacheck with selene Problem: luacheck is unmaintained (last release 2018) and required suppressing four warning classes to avoid false positives. It also lacks first-class vim/neovim awareness. Solution: switch to selene with std='vim' for vim-aware linting. Replace the luacheck CI job with selene, update the Makefile lint target, and delete .luacheckrc. * build: add nix devshell and pre-commit hooks Problem: oil.nvim had no reproducible dev environment. The .envrc set up a Python venv for the now-removed docgen pipeline, and there were no pre-commit hooks for local formatting checks. Solution: add flake.nix with stylua, selene, and prettier in the devshell. Replace the stale Python .envrc with 'use flake'. Add .pre-commit-config.yaml with stylua and prettier hooks matching other plugins in the repo collection. * fix: format with stylua * build(selene): configure lints and add inline suppressions Problem: selene fails on 5 errors and 3 warnings from upstream code patterns that are intentional (mixed tables in config API, unused callback parameters, identical if branches for readability). Solution: globally allow mixed_table and unused_variable (high volume, inherent to the codebase design). Add inline selene:allow directives for the 8 remaining issues: if_same_then_else (4), mismatched_arg_count (1), empty_if (2), global_usage (1). Remove .envrc from tracking. * build: switch typecheck action to mrcjkb/lua-typecheck-action Problem: oil.nvim used stevearc/nvim-typecheck-action, which required cloning the action repo locally for the Makefile lint target. All other plugins in the collection use mrcjkb/lua-typecheck-action. Solution: swap to mrcjkb/lua-typecheck-action@v0 for consistency. Remove the nvim-typecheck-action git clone from the Makefile and .gitignore. Drop LuaLS from the local lint target since it requires a full language server install — CI handles it.
This commit is contained in:
parent
df53b172a9
commit
86f553cd0a
72 changed files with 2762 additions and 2649 deletions
|
|
@ -1,6 +1,6 @@
|
|||
local config = require("oil.config")
|
||||
local layout = require("oil.layout")
|
||||
local util = require("oil.util")
|
||||
local config = require('oil.config')
|
||||
local layout = require('oil.layout')
|
||||
local util = require('oil.util')
|
||||
|
||||
---@class (exact) oil.sshCommand
|
||||
---@field cmd string|string[]
|
||||
|
|
@ -24,12 +24,12 @@ local function output_extend(agg, output)
|
|||
local start = #agg
|
||||
if vim.tbl_isempty(agg) then
|
||||
for _, line in ipairs(output) do
|
||||
line = line:gsub("\r", "")
|
||||
line = line:gsub('\r', '')
|
||||
table.insert(agg, line)
|
||||
end
|
||||
else
|
||||
for i, v in ipairs(output) do
|
||||
v = v:gsub("\r", "")
|
||||
v = v:gsub('\r', '')
|
||||
if i == 1 then
|
||||
agg[#agg] = agg[#agg] .. v
|
||||
else
|
||||
|
|
@ -53,7 +53,7 @@ local function get_last_lines(bufnr, num_lines)
|
|||
vim.api.nvim_buf_get_lines(bufnr, end_line - need_lines, end_line, false),
|
||||
lines
|
||||
)
|
||||
while not vim.tbl_isempty(lines) and lines[#lines]:match("^%s*$") do
|
||||
while not vim.tbl_isempty(lines) and lines[#lines]:match('^%s*$') do
|
||||
table.remove(lines)
|
||||
end
|
||||
end_line = end_line - need_lines
|
||||
|
|
@ -66,14 +66,14 @@ end
|
|||
function SSHConnection.create_ssh_command(url)
|
||||
local host = url.host
|
||||
if url.user then
|
||||
host = url.user .. "@" .. host
|
||||
host = url.user .. '@' .. host
|
||||
end
|
||||
local command = {
|
||||
"ssh",
|
||||
'ssh',
|
||||
host,
|
||||
}
|
||||
if url.port then
|
||||
table.insert(command, "-p")
|
||||
table.insert(command, '-p')
|
||||
table.insert(command, url.port)
|
||||
end
|
||||
return command
|
||||
|
|
@ -84,8 +84,8 @@ end
|
|||
function SSHConnection.new(url)
|
||||
local command = SSHConnection.create_ssh_command(url)
|
||||
vim.list_extend(command, {
|
||||
"/bin/sh",
|
||||
"-c",
|
||||
'/bin/sh',
|
||||
'-c',
|
||||
-- HACK: For some reason in my testing if I just have "echo READY" it doesn't appear, but if I echo
|
||||
-- anything prior to that, it *will* appear. The first line gets swallowed.
|
||||
"echo '_make_newline_'; echo '===READY==='; exec /bin/sh",
|
||||
|
|
@ -112,7 +112,7 @@ function SSHConnection.new(url)
|
|||
})
|
||||
end)
|
||||
self.term_id = term_id
|
||||
vim.api.nvim_chan_send(term_id, string.format("ssh %s\r\n", url.host))
|
||||
vim.api.nvim_chan_send(term_id, string.format('ssh %s\r\n', url.host))
|
||||
util.hack_around_termopen_autocmd(mode)
|
||||
|
||||
-- If it takes more than 2 seconds to connect, pop open the terminal
|
||||
|
|
@ -125,7 +125,7 @@ function SSHConnection.new(url)
|
|||
local jid = vim.fn.jobstart(command, {
|
||||
pty = true, -- This is require for interactivity
|
||||
on_stdout = function(j, output)
|
||||
pcall(vim.api.nvim_chan_send, self.term_id, table.concat(output, "\r\n"))
|
||||
pcall(vim.api.nvim_chan_send, self.term_id, table.concat(output, '\r\n'))
|
||||
---@diagnostic disable-next-line: invisible
|
||||
local new_i_start = output_extend(self._stdout, output)
|
||||
self:_handle_output(new_i_start)
|
||||
|
|
@ -134,12 +134,12 @@ function SSHConnection.new(url)
|
|||
pcall(
|
||||
vim.api.nvim_chan_send,
|
||||
self.term_id,
|
||||
string.format("\r\n[Process exited %d]\r\n", code)
|
||||
string.format('\r\n[Process exited %d]\r\n', code)
|
||||
)
|
||||
-- Defer to allow the deferred terminal output handling to kick in first
|
||||
vim.defer_fn(function()
|
||||
if code == 0 then
|
||||
self:_set_connection_error("SSH connection terminated gracefully")
|
||||
self:_set_connection_error('SSH connection terminated gracefully')
|
||||
else
|
||||
self:_set_connection_error(
|
||||
'Unknown SSH error\nTo see more, run :lua require("oil.adapters.ssh").open_terminal()'
|
||||
|
|
@ -156,23 +156,23 @@ function SSHConnection.new(url)
|
|||
else
|
||||
self.jid = jid
|
||||
end
|
||||
self:run("id -u", function(err, lines)
|
||||
self:run('id -u', function(err, lines)
|
||||
if err then
|
||||
vim.notify(string.format("Error fetching ssh connection user: %s", err), vim.log.levels.WARN)
|
||||
vim.notify(string.format('Error fetching ssh connection user: %s', err), vim.log.levels.WARN)
|
||||
else
|
||||
assert(lines)
|
||||
self.meta.user = vim.trim(table.concat(lines, ""))
|
||||
self.meta.user = vim.trim(table.concat(lines, ''))
|
||||
end
|
||||
end)
|
||||
self:run("id -G", function(err, lines)
|
||||
self:run('id -G', function(err, lines)
|
||||
if err then
|
||||
vim.notify(
|
||||
string.format("Error fetching ssh connection user groups: %s", err),
|
||||
string.format('Error fetching ssh connection user groups: %s', err),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
else
|
||||
assert(lines)
|
||||
self.meta.groups = vim.split(table.concat(lines, ""), "%s+", { trimempty = true })
|
||||
self.meta.groups = vim.split(table.concat(lines, ''), '%s+', { trimempty = true })
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
@ -197,7 +197,7 @@ function SSHConnection:_handle_output(start_i)
|
|||
if not self.connected then
|
||||
for i = start_i, #self._stdout - 1 do
|
||||
local line = self._stdout[i]
|
||||
if line == "===READY===" then
|
||||
if line == '===READY===' then
|
||||
if self.term_winid then
|
||||
if vim.api.nvim_win_is_valid(self.term_winid) then
|
||||
vim.api.nvim_win_close(self.term_winid, true)
|
||||
|
|
@ -215,7 +215,7 @@ function SSHConnection:_handle_output(start_i)
|
|||
for i = start_i, #self._stdout - 1 do
|
||||
---@type string
|
||||
local line = self._stdout[i]
|
||||
if line:match("^===BEGIN===%s*$") then
|
||||
if line:match('^===BEGIN===%s*$') then
|
||||
self._stdout = util.tbl_slice(self._stdout, i + 1)
|
||||
self:_handle_output(1)
|
||||
return
|
||||
|
|
@ -223,15 +223,15 @@ function SSHConnection:_handle_output(start_i)
|
|||
-- We can't be as strict with the matching (^$) because since we're using a pty the stdout and
|
||||
-- stderr can be interleaved. If the command had an error, the stderr may interfere with a
|
||||
-- clean print of the done line.
|
||||
local exit_code = line:match("===DONE%((%d+)%)===")
|
||||
local exit_code = line:match('===DONE%((%d+)%)===')
|
||||
if exit_code then
|
||||
local output = util.tbl_slice(self._stdout, 1, i - 1)
|
||||
local cb = self.commands[1].cb
|
||||
self._stdout = util.tbl_slice(self._stdout, i + 1)
|
||||
if exit_code == "0" then
|
||||
if exit_code == '0' then
|
||||
cb(nil, output)
|
||||
else
|
||||
cb(exit_code .. ": " .. table.concat(output, "\n"), output)
|
||||
cb(exit_code .. ': ' .. table.concat(output, '\n'), output)
|
||||
end
|
||||
table.remove(self.commands, 1)
|
||||
self:_handle_output(1)
|
||||
|
|
@ -244,16 +244,17 @@ function SSHConnection:_handle_output(start_i)
|
|||
local function check_last_line()
|
||||
local last_lines = get_last_lines(self.term_bufnr, 1)
|
||||
local last_line = last_lines[1]
|
||||
if last_line:match("^Are you sure you want to continue connecting") then
|
||||
if last_line:match('^Are you sure you want to continue connecting') then
|
||||
self:open_terminal()
|
||||
elseif last_line:match("Password:%s*$") then
|
||||
-- selene: allow(if_same_then_else)
|
||||
elseif last_line:match('Password:%s*$') then
|
||||
self:open_terminal()
|
||||
elseif last_line:match(": Permission denied %(.+%)%.") then
|
||||
self:_set_connection_error(last_line:match(": (Permission denied %(.+%).)"))
|
||||
elseif last_line:match("^ssh: .*Connection refused%s*$") then
|
||||
self:_set_connection_error("Connection refused")
|
||||
elseif last_line:match("^Connection to .+ closed by remote host.%s*$") then
|
||||
self:_set_connection_error("Connection closed by remote host")
|
||||
elseif last_line:match(': Permission denied %(.+%)%.') then
|
||||
self:_set_connection_error(last_line:match(': (Permission denied %(.+%).)'))
|
||||
elseif last_line:match('^ssh: .*Connection refused%s*$') then
|
||||
self:_set_connection_error('Connection refused')
|
||||
elseif last_line:match('^Connection to .+ closed by remote host.%s*$') then
|
||||
self:_set_connection_error('Connection closed by remote host')
|
||||
end
|
||||
end
|
||||
-- We have to defer this so the terminal buffer has time to update
|
||||
|
|
@ -273,12 +274,12 @@ function SSHConnection:open_terminal()
|
|||
local row = math.floor((total_height - height) / 2)
|
||||
local col = math.floor((vim.o.columns - width) / 2)
|
||||
self.term_winid = vim.api.nvim_open_win(self.term_bufnr, true, {
|
||||
relative = "editor",
|
||||
relative = 'editor',
|
||||
width = width,
|
||||
height = height,
|
||||
row = row,
|
||||
col = col,
|
||||
style = "minimal",
|
||||
style = 'minimal',
|
||||
border = config.ssh.border,
|
||||
})
|
||||
vim.cmd.startinsert()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue