mhartington/formatter.nvim

Uncrustify requires a config file

alecandido opened this issue · 2 comments

return function(lang)
return {
exe = "uncrustify",
args = { "-q", "-l " .. lang },
stdin = true,
}
end

You'd need a -c /some/path argument, but it's impossible to provide to this formatter.

The alternative is to export an environment variable $UNCRUSTIFY_CONFIG, with the path of the configuration.

If the only way to use it is supposed to be the environment variable, it would be fair to document it (if nothing better, at least a comment in the formatter definition).

Allowing for more arguments to be passed in the formatter definition would be the favorite option (then you could decide to use the environment variable anyhow, but it's up to individual choice).

Looks like you can do this:

return function(lang) 
   return { 
     exe = "UNCRUSTIFY_CONFIG=/path/to/file uncrustify", 
     args = { "-q", "-l " .. lang }, 
     stdin = true, 
   } 
 end 

Oh, yes, that's very similar to what I'm doing:

local function uncrustify(lang)
  return {
    exe = "uncrustify",
    args = { "-q", "-l " .. lang, "-c $XDG_CONFIG_HOME/uncrustify.cfg" },
    stdin = true,
  }
end

But the issue was that requires to rewrite the formatter myself (in both cases), fully ignoring the one provided by the plugin.
Thus, having it in the plugin is useless, because it is unusable, and everyone would have to maintain possible updates on their own (against the concept of a reusable plugin).

The idea was to replace the formatter with something like:

local function uncrustify(lang, args)
  return {
    exe = "uncrustify",
    args = { "-q", "-l " .. lang, table.unpack(args) },
    stdin = true,
  }
end

to allow extension with further arguments. Or to add an explicit config argument.