diff options
author | Steven Arcangeli <506791+stevearc@users.noreply.github.com> | 2023-10-15 16:18:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-15 16:18:08 -0700 |
commit | 7027ebbd772e2d3593f7dd566dea06d2d20622ee (patch) | |
tree | b78bbe24dda9cd7e1272bce6c699b5e576d76a66 /scripts/options_doc.lua | |
parent | 9b5fbddfca5080c6961dabafb3f0a6ef7e2fc18a (diff) |
feat!: merge configs in conform.formatters with defaults (#140)
This breaking change should make it significantly easier to modify formatters. While I expect 99% of configs to be backwards-compatible, this can still potentially cause problems. If you:
* define a formatter in the `formatters` option
* that has the same name as a built-in formatter
* and omits a property from the original formatter (e.g. leaves out `range_args` or `cwd`)
Then you may encounter breaking behavior from this commit, because now your config definition will be merged with the built-in definition, and so will inherit those omitted properties. This config merging behavior can be opted-out of by adding `inherit = false` to your formatter config.
Diffstat (limited to 'scripts/options_doc.lua')
-rw-r--r-- | scripts/options_doc.lua | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/scripts/options_doc.lua b/scripts/options_doc.lua index b68614e..6f850ef 100644 --- a/scripts/options_doc.lua +++ b/scripts/options_doc.lua @@ -30,14 +30,14 @@ require("conform").setup({ log_level = vim.log.levels.ERROR, -- Conform will notify you when a formatter errors notify_on_error = true, - -- Define custom formatters here + -- Custom formatters and changes to built-in formatters formatters = { my_formatter = { - -- This can be a string or a function that returns a string + -- This can be a string or a function that returns a string. + -- When defining a new formatter, this is the only field that is *required* command = "my_cmd", - -- OPTIONAL - all fields below this are optional -- A list of strings, or a function that returns a list of strings - -- Return a single string instead to run the command in a shell + -- Return a single string instead of a list to run the command in a shell args = { "--stdin-from-filename", "$FILENAME" }, -- If the formatter supports range formatting, create the range arguments here range_args = function(ctx) @@ -55,15 +55,20 @@ require("conform").setup({ condition = function(ctx) return vim.fs.basename(ctx.filename) ~= "README.md" end, - -- Exit codes that indicate success (default {0}) + -- Exit codes that indicate success (default { 0 }) exit_codes = { 0, 1 }, -- Environment variables. This can also be a function that returns a table. env = { VAR = "value", }, + -- Set to false to disable merging the config with the base definition + inherit = true, + -- When inherit = true, add these additional arguments to the command. + -- This can also be a function, like args + prepend_args = { "--use-tabs" }, }, -- These can also be a function that returns the formatter - other_formatter = function() + other_formatter = function(bufnr) return { command = "my_cmd", } |