Prettier: Using Different Args Based On Filetypes #92
Replies: 2 comments 1 reply
-
From MAIN.md#params it seems that the Will have to experiment and report back. |
Beta Was this translation helpful? Give feedback.
-
Great news! It got figured out. It turns out to be quite simple, but this works for me: null_ls.setup({
debug = false,
sources = {
formatting.prettier.with({
extra_args = function(params)
if params.filetype == "ruby" then
return { "--plugin=@prettier/plugin-ruby" }
end
return {
"--config",
"--arrow-parens",
"avoid",
}
end,
extra_filetypes = { "ruby" },
}),
},
diagnostics_format = "[#{c}] #{m} (#{s})",
}) For others interested, I think this will be a great starting point for you to continue building off of, but the key elements of getting |
Beta Was this translation helpful? Give feedback.
-
At my work we use Ruby and Typescript (monolith), and we're looking at integrating the prettier/plugin-ruby to format the Ruby code we use. We also use Prettier to format our Typescript code.
Reading the BUILTIN_CONFIG.md it seems we can add custom filetypes, so I should be able to tell Prettier to attach on Ruby files, that seems easy enough. Now, the Ruby plugin gets installed and ran via the following command
./node_modules/.bin/prettier --plugin=@prettier/plugin-ruby --write '**/*'
.But of course the command to run the formatter for Typescript is going to be different, so I need to figure out a way to dynamically tell
none-ls
to use a specific command on Ruby files, and a different command on Typescript files; That is the main problem I am trying to solve for.Reading the BUILTIN_CONFIG.md#arguments section, it appears that using a function to specify what the extra arguments should be might be hte way to go here. However, it's not clear to me how I can insert the filetype into that function so that when I have Ruby files a different command runs than the one used for Typescript files. A basic example is provided in the docs for dynamic args:
So for now, i'll open this up for discussion and I would love to hear what others think. I'll be using this thread to chip away at the problem as I work towards solving it, unless someone has a suggestion right out of the gate.
Beta Was this translation helpful? Give feedback.
All reactions