Skip to content

Commit

Permalink
style: fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mochaaP committed Jul 17, 2024
1 parent 41de9de commit 8b5d417
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
17 changes: 8 additions & 9 deletions lua/null-ls/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,20 @@ end

-- assume 1-indexed ranges
local convert_range = function(diagnostic)
local row = tonumber(diagnostic.row or 1)
local col = tonumber(diagnostic.col or 1)
local end_row = tonumber(diagnostic.end_row or row)
local end_col = tonumber(diagnostic.end_col or 1)
local format = function(...)
return ("cannot convert %s to number"):format(...)
end

local row = assert(tonumber(diagnostic.row or 1), format(diagnostic.row))
local col = assert(tonumber(diagnostic.col or 1), format(diagnostic.col))
local end_row = assert(tonumber(diagnostic.end_row or row), format(diagnostic.end_row or row))
local end_col = assert(tonumber(diagnostic.end_col or 1), format(diagnostic.end_col))
-- wrap to next line
if end_row == row and end_col <= col then
end_row = end_row + 1
end_col = 1
end

assert(row)
assert(col)
assert(end_row)
assert(end_col)

return u.range.to_lsp({ row = row, col = col, end_row = end_row, end_col = end_col })
end

Expand Down
3 changes: 1 addition & 2 deletions lua/null-ls/helpers/range_formatting_args_factory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ local range_formatting_args_factory = function(base_args, start_arg, end_arg, op
return args
end

local range = params.range
assert(range)
local range = assert(params.range, "params.range is nil")
local row, col, end_row, end_col = range.row, range.col, range.end_row, range.end_col
if opts.row_offset then
row = row + opts.row_offset
Expand Down
16 changes: 12 additions & 4 deletions lua/null-ls/loop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,18 @@ end
M.read_file = function(path)
local content
local ok, err = pcall(function()
local fd = uv.fs_open(path, "r", 438)
assert(fd)
local stat = uv.fs_fstat(fd)
assert(stat)
local err_name, err_msg
local fd
local stat

local fmt = function(...)
return ("[Error %s]: %s"):format(...)
end

fd, err_name, err_msg = uv.fs_open(path, "r", 438)
assert(fd, fmt(err_name, err_msg))
stat, err_name, err_msg = uv.fs_fstat(fd)
assert(stat, fmt(err_name, err_msg))
content = uv.fs_read(fd, stat.size, 0)
uv.fs_close(fd)
end)
Expand Down
14 changes: 6 additions & 8 deletions lua/null-ls/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ M.make_conditional_utils = function()
return false
end,
root_has_file_matches = function(pattern)
local handle = vim.uv.fs_scandir(root)
assert(handle)
local handle = assert(vim.uv.fs_scandir(root), "Unable to scan " .. root)
local entry = vim.uv.fs_scandir_next(handle)

while entry do
Expand Down Expand Up @@ -229,15 +228,14 @@ M.get_root = function()
if not root then
local fname = api.nvim_buf_get_name(0)
if fname ~= "" then
local v = require("null-ls.config").get().root_dir(fname)
assert(v)
local v = assert(require("null-ls.config").get().root_dir(fname), "cannot infer root_dir")
root = v
end
end

-- fall back to cwd
local cwd = vim.uv.cwd()
assert(cwd)
local cwd, err_name, err_msg = vim.uv.cwd()
assert(cwd, string.format("[Error %s]: %s", err_name, err_msg))

return root or cwd
end
Expand Down Expand Up @@ -366,8 +364,8 @@ end
---@return string|nil
M.get_vcs_root = function()
local uv = vim.uv
local cwd = uv.cwd()
assert(cwd)
local cwd, err_name, err_msg = uv.cwd()
assert(cwd, string.format("[Error %s]: %s", err_name, err_msg))
local vcs_root = M.root_pattern(".git", ".hg", ".svn", ".bzr")(cwd)
return vcs_root
end
Expand Down

0 comments on commit 8b5d417

Please sign in to comment.