Skip to content

Instantly share code, notes, and snippets.

@crierr
Created April 13, 2024 16:10
Show Gist options
  • Save crierr/322ea6711df7614a000cb3f3be87bf93 to your computer and use it in GitHub Desktop.
Save crierr/322ea6711df7614a000cb3f3be87bf93 to your computer and use it in GitHub Desktop.
Configuration for conform.nvim to use local installed version of prettier, when it is installed by Yarn PnP
-- If prettier is installed with Yarn PnP, run below command to generate bin-prettier.js.
-- `yarn dlx @yarnpkg/sdks base`
-- @see https://yarnpkg.com/getting-started/editor-sdks
local util = require("conform.util")
local fs = require("conform.fs")
return {
"stevearc/conform.nvim",
opts = {
formatters = {
prettier = {
command = function(self, bufnr)
local cmd = util.find_executable({ ".yarn/sdks/prettier/bin-prettier.js" }, "")(self, bufnr)
if cmd ~= "" then
return cmd
end
-- return type of util.from_node_modules is fun(self: conform.FormatterConfig, ctx: conform.Context): string
---@diagnostic disable-next-line
return util.from_node_modules(fs.is_windows and "prettier.cmd" or "prettier")(self, bufnr)
end,
},
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment