Closed csntr closed 4 months ago
You can use the require_cwd
option to disable prettier when no config is found.
You might have to overwrite cwd
too since the default for prettier includes package.json
.
local conform = require("conform")
conform.setup({
formatters = {
prettier = {
-- cwd means "config working directory"
require_cwd = true,
cwd = require("conform.util").root_file({
".prettierrc",
".prettierrc.json",
".prettierrc.yml",
".prettierrc.yaml",
".prettierrc.json5",
".prettierrc.js",
".prettierrc.cjs",
".prettierrc.mjs",
".prettierrc.toml",
"prettier.config.js",
"prettier.config.cjs",
"prettier.config.mjs",
}),
},
},
-- rest of your config
})
You can find the default prettier filenames here
Is it possible to point to a default .prettierrc in a place different than home directory?
@rodhash do prettier
/prettier_d
themselves support it?
Hmm I'm not really sure .. on my personal computer it works just fine but at work I have a special set up that's why I was trying to move it away from home dir.
Another question pls: Conform reads the standard Prettier configuration from somewhere? Perhaps some config file?
I'm asking this because even when no ".prettierrc.json" exists Conform still manages to format the file with lua require("conform").format()
I even removed the .prettierrc.json
just to test it and it works.
Checking ConformInfo
things look just fine:
Formatters for this buffer:
LSP: ts_ls, null-ls
prettierd ready (javascriptreact, typescript, typescriptreact, graphql, css, json, yaml, jsonc, less, scss, mar
By default conform assumes a project with a package.json should be prettier enabled.
Please check the comment above for more details https://github.com/stevearc/conform.nvim/issues/407#issuecomment-2120988992
I see. Yeah I noticed that comment 407.
What I find interesting is: apparently Conform uses a standard configuration even when no .prettierrc (or any of the other files) is provided ..
That's what I'm trying to understand, where this standard configuration is coming from because I can run Conform on any JS / TS files apparently.
I have a nuxt project where I want to use antfo eslint config which says its supposed to work without prettier. In other projects the most common practice is to use prettier. I have configured conform to use prettier for most js/ts/vue files but in this case the best would be if it somehow could see that there is no prettier in the project so it could fallback to LSP formatting which is what I want optimally with the ESLint LSP. I didn't find anything on this, is this possible somehow?