feat(prettier): the prettier extra now needs a prettier config file by default. See docs to change this.

This commit is contained in:
Folke Lemaitre
2024-06-05 22:55:36 +02:00
parent 9a1162314f
commit 8ceccd71e2
2 changed files with 29 additions and 10 deletions

View File

@ -1,3 +1,16 @@
if lazyvim_docs then
-- By default, prettier will only be used for formatting
-- if a prettier configuration file is found in the project.
-- Set to `false` to always use prettier for supported filetypes.
vim.g.lazyvim_prettier_needs_config = true
end
local needs_config = vim.g.lazyvim_prettier_needs_config ~= false
-- local check = vim.g.lazyvim_prettier
local enabled = {} ---@type table<string, boolean>
return {
{
"williamboman/mason.nvim",
@ -35,6 +48,22 @@ return {
["markdown.mdx"] = { "prettier" },
["graphql"] = { "prettier" },
["handlebars"] = { "prettier" },
["svelte"] = { "prettier" },
},
formatters = {
prettier = {
condition = function(_, ctx)
if not needs_config then
return true
end
if enabled[ctx.filename] == nil then
enabled[ctx.filename] = vim.fs.find(function(name, path)
return name:match("^%.prettierrc%.") or name:match("^prettier%.config%.")
end, { path = ctx.filename, upward = true })[1] ~= nil
end
return enabled[ctx.filename]
end,
},
},
},
},

View File

@ -58,14 +58,4 @@ return {
})
end,
},
-- {
-- "stevearc/conform.nvim",
-- optional = true,
-- opts = {
-- formatters_by_ft = {
-- ["svelte"] = { "prettier" },
-- },
-- },
-- },
}