mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-22 00:49:03 +02:00
feat(prettier): the prettier extra now needs a prettier config file by default. See docs to change this.
This commit is contained in:
parent
9a1162314f
commit
8ceccd71e2
2 changed files with 29 additions and 10 deletions
|
@ -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 {
|
return {
|
||||||
{
|
{
|
||||||
"williamboman/mason.nvim",
|
"williamboman/mason.nvim",
|
||||||
|
@ -35,6 +48,22 @@ return {
|
||||||
["markdown.mdx"] = { "prettier" },
|
["markdown.mdx"] = { "prettier" },
|
||||||
["graphql"] = { "prettier" },
|
["graphql"] = { "prettier" },
|
||||||
["handlebars"] = { "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,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -58,14 +58,4 @@ return {
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
-- {
|
|
||||||
-- "stevearc/conform.nvim",
|
|
||||||
-- optional = true,
|
|
||||||
-- opts = {
|
|
||||||
-- formatters_by_ft = {
|
|
||||||
-- ["svelte"] = { "prettier" },
|
|
||||||
-- },
|
|
||||||
-- },
|
|
||||||
-- },
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue