diff options
-rw-r--r-- | lua/conform/formatters/isort.lua | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/lua/conform/formatters/isort.lua b/lua/conform/formatters/isort.lua index 9b02c4e..7236873 100644 --- a/lua/conform/formatters/isort.lua +++ b/lua/conform/formatters/isort.lua @@ -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", |