The Coding Standards are important
I'm WordPress Developer.
I am conscious of writing readable code, but since I am a human, I make mistakes.
Let's use formatter. And I want to run phpcbf from Neovim.
Great plugin is neoformat
Below are my settings.
let g:neoformat_php_phpcbf = {
\ 'exe': 'phpcbf',
\ 'args': [
\ '--standard=WordPress',
\ '--extensions=php',
\ '%',
\ '||',
\ 'true'
\ ],
\ 'stdin': 1,
\ 'no_append': 1
\ }
let g:neoformat_enabled_php = ['phpcbf']
nnoremap <leader>nf :Neoformat<cr>
Top comments (1)
Thanks for sharing this! I found this on Google searching for using phpcbf with
Neoformat and this got me in the right direction getting phpcbf working with
Neoformat with my setup. I ran into some odd issues when having Neoformat run
on save with:
It did work fine with the
<leader>nf
shortcut but I prefer Neoformat to runon save. I looked into it a bit more and it looks like there was
a feature to deal with non-standard error codes made due to how phpcbf handles error codes,
and I was able to adjust your code to take advantage of that and remove the
need for the
|| true
(which I think was causing my problem). In addition, Idon't think the
--extensions=php
is needed since it's already set as a PHPformatter, so it shouldn't run on anything else. Here's an update to your code
with the fixes:
My use case is that I use a
phpcs.xml
file for my rules, so I don't need toset a standard via a cli argument; and as mentioned before I like to have it
run on save, so my setup is like this:
Once again, thanks for sharing, and I hope this helps anyone else coming here via searching for how to use phpcbf with Neoformat like I did.