Skip to content

Commit

Permalink
fix: splitting crlf lines (#137)
Browse files Browse the repository at this point in the history
* fix: crlf lines

* fix: crlf for formatting
  • Loading branch information
xiaoshihou514 authored Jan 13, 2024
1 parent 6a27c57 commit 383883a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
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 January 12
*guard.nvim.txt* For NVIM v0.8.0 Last change: 2024 January 13

==============================================================================
Table of Contents *guard.nvim-table-of-contents*
Expand Down
3 changes: 2 additions & 1 deletion lua/guard/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ local function update_buffer(bufnr, prev_lines, new_lines)
return
end
local views = save_views(bufnr)
new_lines = vim.split(new_lines, '\n')
-- \r\n for windows compatibility
new_lines = vim.split(new_lines, '\r?\n')
if new_lines[#new_lines] == '' then
new_lines[#new_lines] = nil
end
Expand Down
7 changes: 4 additions & 3 deletions lua/guard/lint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ local function from_json(opts)
local diags, offences = {}, {}

if opts.lines then
-- \r\n for windows compatibility
vim.tbl_map(function(line)
offences[#offences + 1] = opts.get_diagnostics(line)
end, vim.split(result, '\n', { trimempty = true }))
end, vim.split(result, '\r?\n', { trimempty = true }))
else
offences = opts.get_diagnostics(result)
end
Expand Down Expand Up @@ -176,8 +177,8 @@ local function from_regex(opts)

return function(result, buf)
local diags, offences = {}, {}

local lines = vim.split(result, '\n', { trimempty = true })
-- \r\n for windows compatibility
local lines = vim.split(result, '\r?\n', { trimempty = true })

for _, line in ipairs(lines) do
local offence = {}
Expand Down

0 comments on commit 383883a

Please sign in to comment.