Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/guard.nvim.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*guard.nvim.txt* For NVIM v0.8.0 Last change: 2024 October 06
*guard.nvim.txt* For NVIM v0.8.0 Last change: 2024 October 10

==============================================================================
Table of Contents *guard.nvim-table-of-contents*
Expand Down
9 changes: 6 additions & 3 deletions lua/guard/events.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local api, uv = vim.api, vim.uv
local getopt = require('guard.util').getopt
local util = require('guard.util')
local getopt = util.getopt
local report_error = util.report_error
local au = api.nvim_create_autocmd
local iter = vim.iter
local M = {}
Expand Down Expand Up @@ -42,7 +44,8 @@ function M.watch_ft(ft)
-- check if all cmds executable before registering formatter
iter(require('guard.filetype')[ft].formatter):any(function(config)
if type(config) == 'table' and config.cmd and vim.fn.executable(config.cmd) ~= 1 then
error(config.cmd .. ' not executable', 1)
report_error(config.cmd .. ' not executable')
return false
end
return true
end)
Expand Down Expand Up @@ -94,7 +97,7 @@ local debounce_timer = nil
function M.register_lint(ft, events)
iter(require('guard.filetype')[ft].linter):any(function(config)
if config.cmd and vim.fn.executable(config.cmd) ~= 1 then
error(config.cmd .. ' not executable', 1)
report_error(config.cmd .. ' not executable')
end
return true
end)
Expand Down
11 changes: 8 additions & 3 deletions lua/guard/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ local function do_fmt(buf)
end, fmt_configs)

-- check if all cmds executable again, since user can call format manually
iter(fmt_configs):any(function(config)
local all_executable = not iter(fmt_configs):any(function(config)
if config.cmd and vim.fn.executable(config.cmd) ~= 1 then
error(config.cmd .. ' not executable', 1)
report_error(config.cmd .. ' not executable')
return true
end
return true
return false
end)

if not all_executable then
return
end

-- filter out "pure" and "impure" formatters
local pure = iter(filter(function(config)
return config.fn or (config.cmd and config.stdin)
Expand Down
12 changes: 0 additions & 12 deletions spec/filetype_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,4 @@ describe('filetype module', function()

same({ '-l', '-L', '1' }, ft.c.linter[1].args)
end)

it('can detect non executable formatters', function()
assert(not pcall(function()
ft('c'):fmt({ cmd = 'hjkl' })
end))
end)

it('can detect non executable linters', function()
assert(not pcall(function()
ft('c'):lint({ cmd = 'hjkl' })
end))
end)
end)