-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
bug: phpcbf overwrites php-cs-fixer config with stats #289
Comments
My guess is that phpcbf is not a well-behaved formatter when it comes to stdin/stdout. The correct behavior is, if formatting to stdout, to put all these diagnostic messages in stderr so tools like conform don't parse it as part of the formatted file. My guess is we'll have to either change it to operate on a file instead of stdin, or modify it to not accept exit code |
I have to dig into how |
I found the following which seems to confirm that we should treat at least 0 and 1 exit codes as success, I have not dug into the code to see if there’s anything else we should do: squizlabs/PHP_CodeSniffer#1818 (comment) Note that the exit codes are likely to change with the future release 4.x of phpcbf which has a new maintainer and repo: PHPCSStandards/PHP_CodeSniffer#184 Edit: looks like we are probably already handling the exit codes correctly: https://github.com/stevearc/conform.nvim/blob/5a15cc46e75cad804fd51ec5af9227aeb1d1bdaa/lua/conform/formatters/phpcbf.lua |
I did some digging and I think the problem might be that when
I haven't however found out why it doesn't work on files when it exits with a code |
I also tried to change the formatter config to not use stdin but it didn't help. I propably don't know how to configure it properly. local util = require("conform.util")
---@type conform.FileFormatterConfig
return {
meta = {
url = "https://phpqa.io/projects/phpcbf.html",
description = "PHP Code Beautifier and Fixer fixes violations of a defined coding standard.",
},
command = util.find_executable({
"vendor/bin/phpcbf",
}, "phpcbf"),
args = { "$FILENAME" },
stdin = false,
-- 0: no errors found
-- 1: errors found
-- 2: fixable errors found
-- 3: processing error
exit_codes = { 0, 1, 2 },
} logs:
Running the command |
It is possible that phpcbf cares about the filename. If you |
I got around to testing this and seems like phpcbf doesn't for some reason format the file, it reports there were no errors. The files are identical but the first command has an exit code
|
Opened up an issue about the ignored hidden files, hopefully it will fix the no stdin solution and I can make a PR out of it. |
Can you try out #333 and see if that fixes your issue? |
That seems to fix the problem, thank you. I'll open up a PR if phpcbf decides to accept hidden files at some point. |
Neovim version (nvim -v)
0.9.5
Operating system/version
Archlinux 6.7.3-arch1-1
Add the debug logs
log_level = vim.log.levels.DEBUG
and pasted the log contents below.Log file
Describe the bug
phpcbf formatter seems to overwrite the file whenever it runs successfully and for some reason the only file it seems to run successfully is .php-cs-fixer.dist.php.
It overwrites the file with
What is the severity of this bug?
breaking (some functionality is broken)
Steps To Reproduce
:w
Expected Behavior
I expect it to format the file according to the rulesets I have defined or if no rulesets are defined by the defaults.
Minimal example file
.php-cs-fixer.dist.php
(phpcbf exits with code 0 and overwrites)app/Models/Locale.php
(phpcbf exits with code 1 and does nothing)Minimal init.lua
Additional context
No response
The text was updated successfully, but these errors were encountered: