Skip to content

Commit

Permalink
fix(isort): explicitly pass line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed May 6, 2024
1 parent 12b3995 commit 0d34c72
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lua/conform/formatters/isort.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@ return {
description = "Python utility / library to sort imports alphabetically and automatically separate them into sections and by type.",
},
command = "isort",
args = {
"--stdout",
"--filename",
"$FILENAME",
"-",
},
args = function(self, ctx)
-- isort doesn't do a good job of auto-detecting the line endings.
local line_ending
local file_format = vim.bo[ctx.buf].fileformat
if file_format == "dos" then
line_ending = "\r\n"
elseif file_format == "mac" then
line_ending = "\r"
else
line_ending = "\n"
end
return {
"--stdout",
"--line-ending",
line_ending,
"--filename",
"$FILENAME",
"-",
}
end,
cwd = util.root_file({
-- https://pycqa.github.io/isort/docs/configuration/config_files.html
".isort.cfg",
Expand Down

0 comments on commit 0d34c72

Please sign in to comment.