Skip to content

Commit

Permalink
Normalize paths in from_pattern before comparing them (#539)
Browse files Browse the repository at this point in the history
Fix consistency issues on Windows when some linters use a single
backslash, some use a double (escaped) backslash, and some still use a
forward slash.

This fix is confirmed to fix issues with Mypy on Windows, and it
probably affects other linters as well.

Fixes #480.

Co-authored-by: Joshua T <[email protected]>
  • Loading branch information
mfussenegger and replicaJunction authored Feb 20, 2024
1 parent 431eb3f commit cab1de0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lua/lint/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ function M.from_errorformat(efm, skeleton)
end
end

local normalize = (vim.fs ~= nil and vim.fs.normalize ~= nil)
and vim.fs.normalize
or function(path) return path end


--- Parse a linter's output using a Lua pattern
---
Expand Down Expand Up @@ -69,7 +73,7 @@ function M.from_pattern(pattern, groups, severity_map, defaults, opts)
else
path = vim.fn.simplify(linter_cwd .. '/' .. captures.file)
end
if path ~= buffer_path then
if normalize(path) ~= normalize(buffer_path) then
return nil
end
end
Expand Down

0 comments on commit cab1de0

Please sign in to comment.