diff options
author | Steven Arcangeli <506791+stevearc@users.noreply.github.com> | 2024-05-10 21:56:40 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-10 21:56:40 -0600 |
commit | a3e3e0e2966a9fa477bbc86487e920ee0c34f133 (patch) | |
tree | 318cfcde16cdd2e63c768bf4c610c5112266eb21 /lua/conform/formatters | |
parent | d2a54aa54d84117ac3d99afdd527281f81e9e2c9 (diff) |
fix(isort): explicitly pass line endings (#395)
Diffstat (limited to 'lua/conform/formatters')
-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", |