-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running formatters with non-stdin option to respect "ignore patterns" #232
Comments
Specifically for yapf, one could try: require("conform").formatters["yapf"] = {
-- cwd = .require("conform.util").root_file({ -- detect project root here
-- "setup.py", "pyproject.toml", ".style.yapf", ".git",
-- })
stdin = false, -- See stevearc/conform.nvim#232 to support 'filename'
args = { "--quiet", "$FILENAME" },
range_args = function(ctx)
return { "--quiet", "--lines", string.format("%d-%d", ctx.range.start[1], ctx.range["end"][1]), "$FILENAME" }
end,
} but this will result in errors (Exit code 1) because when there are no input files to format,
(this is more due to yapf's lack of fine-grained behavior control). |
I think this is going to be handled on a case-by-case basis for formatters. They all have different config files and logic for allowlisting/blocklisting certain files from formatting rules. If you can come up with a configuration that respects the config file by default, I'll take a PR to add it. |
Question: is there any particular reason where "stdin" mode is preferred over the "$FILENAME" mode in general? |
Fewer moving parts, fewer things that can go wrong, slightly better performance. But it's a mild preference, so if there's a solid reason why we should prefer the file-based formatting we shouldn't be shy about using that instead. |
I see, thanks for the input. I also see another benefit: it can be also useful when dealing with range formatting. For YAPF, actually some upstream fix would be needed because of the "no input" situation. I will come back again with a PR if I have a reasonable solution to deal with this specific use case. |
Neovim version (nvim -v)
0.9.4
Operating system/version
macOS, Linux
Add the debug logs
log_level = vim.log.levels.DEBUG
and pasted the log contents below.Log file
Describe the bug
It looks like many of the formatters run the external formatter program through stdin/stdout PIPE. One drawback of this is that the filename is lost, so the formatting does not respect "ignore files".
For example, yapf 0.32+ supports
.yapfignore
or[tool.yapfignore]
inpyproject.toml
, but this setting is ignored because conform.nvim executesyapf
by feeding the buffer contents into stdin.I know the options
stdin = false
andargs = { ..., "$FILENAME "}
, but is this something that can be improved by default (also for many formatters not only for yapf) or are users supposed to take care of this manually?Steps To Reproduce
Put
.yapfignore
in the project root:Expected Behavior
Ignore files are respected.
Minimal example file
(Any files are affected)
Minimal init.lua
Additional context
No response
The text was updated successfully, but these errors were encountered: