Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(black): formatting excluded files results in blank buffer (#249) #254

Merged

Conversation

bartels
Copy link
Contributor

@bartels bartels commented Dec 27, 2023

Fixes #249

This fix checks for blank formatter output in apply_format. Not sure if this is the best place to apply this fix, but seemed the most obvious place since it'll work the same for both sync and async formats

Copy link
Owner

@stevearc stevearc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach looks good, but the fuzz tester is failing. You may need to adjust the fuzz tester to not trigger this condition

Comment on lines 174 to 177
if new_text:match("^%s*$") and not original_text:match("^%s*$") then
log.trace("Aborting because a formatter returned empty output")
return
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a fine place for it, but I'd say add the buffer name to the log line and make it a warn instead of a trace

local original_lines = { "line one", "line two" }
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, original_lines)
vim.bo[bufnr].modified = false
test_util.set_formatter_output({ "" })
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently made a change the moved this out of test_util. You may need to rework the test a bit.

@stevearc stevearc merged commit c4b2efb into stevearc:master Jan 2, 2024
8 checks passed
@stevearc
Copy link
Owner

stevearc commented Jan 2, 2024

Thanks for the PR!

@Mange
Copy link

Mange commented Jan 3, 2024

Thanks! This helped me with the rubocop formatter that also started clearing all my files on format for no discernible reason after updating 2 days ago.

I'll try to figure out why that happens and report it later on, but now I can get back to work. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: black formatter results in blank buffer if using --force-exclude option
3 participants