Skip to content

Commit

Permalink
refactor: deprecate formatter alternation syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jul 19, 2024
1 parent 0b3d259 commit 9f111be
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ 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" } },
-- You can customize some of the format options for the filetype (:help conform.format)
rust = { "rustfmt", lsp_format = "fallback" },
-- Conform will run the first available formatter
javascript = { "prettierd", "prettier", stop_after_first = true },
},
})
```
Expand Down Expand Up @@ -457,8 +459,6 @@ require("conform").setup({
lua = { "stylua" },
-- Conform will run multiple formatters sequentially
go = { "goimports", "gofmt" },
-- Use a sub-list to run only the first available formatter
javascript = { { "prettierd", "prettier" } },
-- You can also customize some of the format options for the filetype
rust = { "rustfmt", lsp_format = "fallback" },
-- You can use a function here to determine the formatters dynamically
Expand Down
2 changes: 0 additions & 2 deletions doc/conform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ OPTIONS *conform-option
lua = { "stylua" },
-- Conform will run multiple formatters sequentially
go = { "goimports", "gofmt" },
-- Use a sub-list to run only the first available formatter
javascript = { { "prettierd", "prettier" } },
-- You can also customize some of the format options for the filetype
rust = { "rustfmt", lsp_format = "fallback" },
-- You can use a function here to determine the formatters dynamically
Expand Down
10 changes: 7 additions & 3 deletions doc/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ return {
-- Customize or remove this keymap to your liking
"<leader>f",
function()
require("conform").format({ async = true, lsp_format = "fallback" })
require("conform").format({ async = true })
end,
mode = "",
desc = "Format buffer",
Expand All @@ -163,10 +163,14 @@ return {
formatters_by_ft = {
lua = { "stylua" },
python = { "isort", "black" },
javascript = { { "prettierd", "prettier" } },
javascript = { "prettierd", "prettier", stop_after_first = true },
},
-- Set default options
default_format_opts = {
lsp_format = "fallback",
},
-- Set up format-on-save
format_on_save = { timeout_ms = 500, lsp_format = "fallback" },
format_on_save = { timeout_ms = 500 },
-- Customize formatters
formatters = {
shfmt = {
Expand Down
8 changes: 8 additions & 0 deletions lua/conform/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ M.list_formatters_for_buffer = function(bufnr)
local function dedupe_formatters(names, collect)
for _, name in ipairs(names) do
if type(name) == "table" then
vim.notify_once(
"deprecated[conform]: The nested {} syntax to run the first formatter has been replaced by the stop_after_first option. See :help conform.format. Support for the old syntax will be dropped on 2025-01-01.",
vim.log.levels.WARN
)
local alternation = {}
dedupe_formatters(name, alternation)
if not vim.tbl_isempty(alternation) then
Expand Down Expand Up @@ -322,6 +326,10 @@ M.resolve_formatters = function(names, bufnr, warn_on_missing, stop_after_first)
local info = M.get_formatter_info(name, bufnr)
add_info(info, warn_on_missing)
else
vim.notify_once(
"deprecated[conform]: The nested {} syntax to run the first formatter has been replaced by the stop_after_first option. See :help conform.format. Support for the old syntax will be dropped on 2025-01-01.",
vim.log.levels.WARN
)
-- If this is an alternation, take the first one that's available
for i, v in ipairs(name) do
local info = M.get_formatter_info(v, bufnr)
Expand Down
2 changes: 1 addition & 1 deletion lua/conform/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

---This list of formatters to run for a filetype, an any associated format options.
---@class conform.FiletypeFormatterInternal : conform.DefaultFormatOpts
---@field [integer] string|string[]
---@field [integer] string

---@alias conform.LspFormatOpts
---| '"never"' # never use the LSP for formatting (default)
Expand Down
2 changes: 0 additions & 2 deletions scripts/options_doc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ require("conform").setup({
lua = { "stylua" },
-- Conform will run multiple formatters sequentially
go = { "goimports", "gofmt" },
-- Use a sub-list to run only the first available formatter
javascript = { { "prettierd", "prettier" } },
-- You can also customize some of the format options for the filetype
rust = { "rustfmt", lsp_format = "fallback" },
-- You can use a function here to determine the formatters dynamically
Expand Down

0 comments on commit 9f111be

Please sign in to comment.