From a3e3e0e2966a9fa477bbc86487e920ee0c34f133 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli <506791+stevearc@users.noreply.github.com> Date: Fri, 10 May 2024 21:56:40 -0600 Subject: [PATCH] fix(isort): explicitly pass line endings (#395) --- lua/conform/formatters/isort.lua | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lua/conform/formatters/isort.lua b/lua/conform/formatters/isort.lua index 9b02c4e3..72368736 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",