aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform/runner.lua
diff options
context:
space:
mode:
authorEric Bartels <ebartels@gmail.com>2024-01-02 08:26:14 -0800
committerGitHub <noreply@github.com>2024-01-02 08:26:14 -0800
commitc4b2efb8aee4af0ef179a9b49ba401de3c4ef5d2 (patch)
tree27e8cea8fdf74db1466a0d5b6fb7c938b2b4dff2 /lua/conform/runner.lua
parent053b8b8617dc2a64100c16f66750367170132de9 (diff)
Fix(black): formatting excluded files results in blank buffer (#254)
* Fix(black): formatting excluded files results in blank buffer (#249) * Fixed stylua formatting * Fixed more stylua formatting * Log buffer name and change from trace to warning * Test fix: set_formatter_output funtion was moved out of test_util * Avoid blank output triggering errors in fuzzer tests
Diffstat (limited to 'lua/conform/runner.lua')
-rw-r--r--lua/conform/runner.lua7
1 files changed, 7 insertions, 0 deletions
diff --git a/lua/conform/runner.lua b/lua/conform/runner.lua
index 62d158e..0f4604d 100644
--- a/lua/conform/runner.lua
+++ b/lua/conform/runner.lua
@@ -169,6 +169,13 @@ M.apply_format = function(bufnr, original_lines, new_lines, range, only_apply_ra
table.remove(original_lines)
table.remove(new_lines)
+ -- Abort if output is empty but input is not (i.e. has some non-whitespace characters).
+ -- This is to hack around oddly behaving formatters (e.g black outputs nothing for excluded files).
+ if new_text:match("^%s*$") and not original_text:match("^%s*$") then
+ log.warn("Aborting because a formatter returned empty output for buffer %s", bufname)
+ return
+ end
+
log.trace("Comparing lines %s and %s", original_lines, new_lines)
local indices = vim.diff(original_text, new_text, {
result_type = "indices",