stevearc / conform.nvim

Lightweight yet powerful formatter plugin for Neovim
MIT License
2.89k stars 150 forks source link

bug: php-cs-fixer setup #329

Closed scippio closed 5 months ago

scippio commented 6 months ago

Neovim version (nvim -v)

v0.9.5

Operating system/version

Archlinux

Add the debug logs

Log file

12:03:45[ERROR] error formatting log line: '"Formatter 'php-cs-fixer' error: PHP CS Fixer 3.51.0 (008b824) Insomnia by Fabien Potencier, Dariusz Ruminski and contributors.\nPHP runtime: 8.3.3\nLoaded config default.\nUsing cache file \".php-cs-fixer.cache\".\n 0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0%\n 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%\n\n"' args {
n = 0
}

Describe the bug

I have problem with my php-cs-fixer setup. I added php-cs-fixer config, but when formatter starts I get this php-cs-fixer error. Maybe I have bad configuration setup? Please help. Thank you.

Manual runs are ok like: php-cs-fixer fix /path-to-file

PHP CS Fixer 3.51.0 (008b824) Insomnia by Fabien Potencier, Dariusz Ruminski and contributors.                                                                                                                                                  
PHP runtime: 8.3.3                                                                                                                                                                                                                              
Loaded config default.                                                                                                                                                                                                                          
Using cache file ".php-cs-fixer.cache".                                                                                                                                                                                                         
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%                                                                                                                                                                                                        

   1) app/Models/RequestApprove.php                                                                                                                                                                                                             

Fixed 1 of 1 files in 0.016 seconds, 16.711 MB memory used 

or ("The command can also read from standard input, in which case it won't
automatically fix anything" in docs): cat /path-to-file | php-cs-fixer fix -

PHP CS Fixer 3.51.0 (008b824) Insomnia by Fabien Potencier, Dariusz Ruminski and contributors.                                                                                                                                                  
PHP runtime: 8.3.3                                                                                                                                                                                                                              
Loaded config default.                                                                                                                                                                                                                          
Using cache file ".php-cs-fixer.cache".                                                                                                                                                                                                         
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%                                                                                                                                                                                                        

   1) php://stdin                                                                                                                                                                                                                               

Found 1 of 1 files that can be fixed in 0.016 seconds, 16.711 MB memory used 

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

1) start nvim with conform 2) open php file 3) try save/format by conform

Expected Behavior

format without error

Minimal example file

No response

Minimal init.lua

formatters_by_ft = {
                javascript = { "prettier" },
                typescript = { "prettier" },
                javascriptreact = { "prettier" },
                typescriptreact = { "prettier" },
                svelte = { "prettier" },
                css = { "prettier" },
                html = { "prettier" },
                json = { "prettier" },
                yaml = { "prettier" },
                markdown = { "prettier" },
                graphql = { "prettier" },
                lua = { "stylua" },
                python = { "isort", "black" },
                php = { "php-cs-fixer" },
            },
            format_on_save = {
                lsp_fallback = true,
                async = false,
                timeout_ms = 1000,
            },
            formatters = {
                prettier = {
                    command = "prettier",
                    args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0) },
                },
                stylua = {
                    command = "stylua",
                    args = { "-" },
                },
                isort = {
                    command = "isort",
                    args = { "-" },
                },
                black = {
                    command = "black",
                    args = { "-" },
                },
                ["php-cs-fixer"] = {
                    command = "php-cs-fixer",
                    args = { "fix", "-" },
                },
            },

Additional context

No response

scippio commented 6 months ago

I found thats php-cs-fixer doesn't not support stdout :thinking: :disappointed: ... So thats maybe the problem....

Is there fully supported php formatter for conform? I habe Mason and trying pretty-php too, but without success...

stevearc commented 6 months ago

Why are you defining formatters? These are all formatters that are built-in, and you're overriding their args to be invalid.

scippio commented 6 months ago

But it's not working without definitions. When I open my php file I get:

image

stevearc commented 5 months ago

I think you have something wrong with your config. If you define a formatter in your formatters_by_ft it should always show up in :ConformInfo. If you're missing a definition for that formatter, it will give you the error:

Formatters for this buffer:
php-cs-fixer unavailable: No config found

Which, indeed, we do expect because the name of that formatter is actually php_cs_fixer with underscores. You don't need to define any of the formatters you have in the formatters block, and in the case of prettier it is actively buggy. If you still can't get it working, I recommend starting with a minimal neovim config (like the one in the bug report template) and see if that can reproduce the issue.

scippio commented 5 months ago

php_cs_fixer` with underscores.

omg :facepalm: Sorry, it works now... I'm new in nvim & plugins and I overlooked :see_no_evil: all these build-in formatters :man_facepalming:

Thank you for help. I'm closing this "issue".