Skip to content

Commit

Permalink
fix(format): enhance formatter check and logging for undefined format…
Browse files Browse the repository at this point in the history
…ters

Closed #215
  • Loading branch information
jellydn committed Dec 7, 2024
1 parent 18d3e68 commit 53fb537
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lua/hurl/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,16 @@ M.format = function(body, type)
xml = { 'tidy', '-xml', '-i', '-q' },
}

-- If no formatter is defined, return the body
if not formatters[type] then
-- If no formatter is defined or empty, return the body
if not formatters[type] or #formatters[type] == 0 then
M.log_info('no formatter defined for type ' .. type .. ', skipping formatting')
return vim.split(body, '\n')
end

-- Check if formatter executable exists
local formatter_cmd = formatters[type][1]
if vim.fn.executable(formatter_cmd) ~= 1 then
M.log_info('formatter ' .. formatter_cmd .. ' not found, skipping formatting')
return vim.split(body, '\n')
end

Expand Down

0 comments on commit 53fb537

Please sign in to comment.