From 2568d746abbadf66a03c62b568ee73d874cd8617 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Fri, 8 Sep 2023 08:48:33 -0700 Subject: feat: syntax for using first available formatter Alternations are now supported. You can specify a sub-list in place of a formatter name and conform will use the first formatter in that list that is available. For example, this will use either prettierd or prettier (whichever is available), and then always trim whitespace afterwards: conform.format(formatters = { { "prettierd", "prettier" }, "trim_whitespace" }) This syntax is available both in the formatters_by_ft config option and in the `formatters` argument of the `format` method. --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 8d6cd45..66b50dc 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,10 @@ At a minimum, you will need to set up some formatters by filetype require("conform").setup({ formatters_by_ft = { lua = { "stylua" }, - -- Conform will run multiple formatters sequentially + -- Conform will run multiple formatters sequentially python = { "isort", "black" }, + -- Use a sub-list to run only the first available formatter + javascript = { { "prettierd", "prettier" } }, }, }) ``` @@ -210,6 +212,8 @@ require("conform").setup({ lua = { "stylua" }, -- Conform will run multiple formatters sequentially python = { "isort", "black" }, + -- Use a sub-list to run only the first available formatter + javascript = { { "prettierd", "prettier" } }, }, -- If this is set, Conform will run the formatter on save. -- It will pass the table to conform.format(). @@ -384,10 +388,10 @@ List information about all filetype-configured formatters `get_formatter_info(formatter, bufnr): conform.FormatterInfo` \ Get information about a formatter (including availability) -| Param | Type | Desc | -| --------- | -------------- | ---- | -| formatter | `string` | | -| bufnr | `nil\|integer` | | +| Param | Type | Desc | +| --------- | -------------- | ------------------------- | +| formatter | `string` | The name of the formatter | +| bufnr | `nil\|integer` | | ## Acknowledgements -- cgit v1.2.3-70-g09d2