-
Notifications
You must be signed in to change notification settings - Fork 787
file is mangled when the formatter (erblint) found no errors #1559
Comments
Looks like the exit code doesn't account for errors: Shopify/erb_lint#118 Ideally the executable itself would be better behaved, but a potential fix from our end is something like this: diff --git a/lua/null-ls/builtins/formatting/erb_lint.lua b/lua/null-ls/builtins/formatting/erb_lint.lua
index 78e9144..3445943 100644
--- a/lua/null-ls/builtins/formatting/erb_lint.lua
+++ b/lua/null-ls/builtins/formatting/erb_lint.lua
@@ -20,6 +20,10 @@ return h.make_builtin({
output = "raw",
on_output = function(params, done)
local output = params.output
+ if output:find("No errors were found in ERB files") then
+ return done()
+ end
+
local metadata_end = output:match(".*==()") + 1
return done({ { text = output:sub(metadata_end) } })
end, I'm not a user, so I can't say for sure if this is a good fix / how this would handle non-English messages. |
wow. thanks for narrowing that down. is it possible to overload this from the source setup in anyway? or is modifying the built-in the only approach that will work? for now, i'll explore the possibility of adding an exit code to |
It's dirty, but you should be able to do this in the meantime: -- add to table of sources and register
local erb_lint = null_ls.builtins.formatting.erb_lint.with({
on_output = function(params, done)
local output = params.output
if output:find("No errors were found in ERB files") then
return done()
end
local metadata_end = output:match(".*==()") + 1
return done({ { text = output:sub(metadata_end) } })
end,
}) If the solution works for you it might be worth putting in a PR, though, since as far as I can tell this might be affecting other users (and I'm surprised this is the first report). |
Since the erb_lint has already implemented different exit codes, can we close this? |
FAQ
Issues
Neovim Version
v0.8.1
Dev Version?
Operating System
linux
Minimal Config
Steps to Reproduce
Reproducibility Check
minimal_init.lua
template and that my issue is reproducible by runningnvim --clean -u minimal_init.lua
and following the steps above.Expected Behavior
since erblint reports no errors, the file doesn't need to be formatted and there should be no change to the file after saving
Actual Behavior
when the condition includes
x == x
the file is formatted tobut if the conditional doesn't have a comparison, this behavior isn't seen and the file is preserved as expected
Debug Log
Help
Yes, but I don't know how to start. I would need guidance
Implementation Help
No response
Requirements
The text was updated successfully, but these errors were encountered: