该代码仓库为特定的 djLint 配置文件(profile)提供了多个预先配置好的 hook(这些 hook 只是预先设置了 --profile 参数,并告知 pre-commit 需要查找哪些文件扩展名):
请注意,这些预定义的 hook 在它们接受的输入方面有时会过于保守(您的模板可能使用了不同的扩展名),因此 pre-commit 明确允许您覆盖这些预定义的选项。有关额外的配置信息,请参阅 pre-commit 的文档。
- 通过 Mason 安装 efm-langserver 和 djLint:
:MasonInstall efm djlint
- 将
htmldjango 添加到 filetypes。
- 创建格式化配置:
local djlint = {
formatCommand = "djlint --reformat --quiet --warn -",
formatStdin = true,
}
- 使用
htmldjango = { djlint } 将语言连接到格式化工具。
示例配置:
local djlint = {
formatCommand = "djlint --reformat --quiet --warn -",
formatStdin = true,
}
require("lspconfig").efm.setup({
filetypes = { "htmldjango" },
init_options = { documentFormatting = true },
settings = {
rootMarkers = { ".git/" },
languages = {
htmldjango = { djlint },
},
},
})