Closed xavortm closed 3 months ago
Thanks for reporting this issue and the detailed description, @xavortm ! I appreciate you letting me know about this.
I see it was brought to my attention previously by @mokorana #8 .
I'm happy to inform you that I've addressed this issue by adding a setup
method to configure the options. This should allow for more control over the default config.
require("praem90/nvim-phpcsf").setup({
phpcs = "phpcs",
phpcbf = "phpcbf",
standard = "10up-Default"
})
If you have any further questions or encounter any issues with the new setup method, please don't hesitate to let me know.
Thank you for the quick update! I still can't get it to work though :( I have updated the plugin, so from Lazy I can see it showing the latest commit, so it should be pulling your latest update, then in my config I have added it as you said:
return {
{
"praem90/nvim-phpcsf",
config = function()
require("praem90/nvim-phpcsf").setup({
phpcs = "phpcs",
phpcbf = "phpcbf",
standard = "10up-Default"
})
vim.api.nvim_create_augroup("PHPCSGroup", {clear = true})
-- vim.g.nvim_phpcs_config_phpcs_path = 'phpcs'
-- vim.g.nvim_phpcs_config_phpcbf_path = 'phpcbf'
-- vim.g.nvim_phpcs_config_phpcs_standard = 'WordPress' -- or path to your ruleset phpcs.xml
-- Setup auto formatting for php files using phpcs
...
(I also tried without the praem90/
prefix.
But when I try to open nvim now I get this error:
I am still quite new to vim in general, It could be an obvious mistake, but I did compare to other configs I have in Lazy and I think it's following the same structure
Viewing the plug in from Lazy I see this: The commit seems the same as https://github.com/praem90/nvim-phpcsf/commit/87d34cdbfff69dc1744313415aa0f96fbf92758f
Try this
require("phpcs").setup({
phpcs = "phpcs",
phpcbf = "phpcbf",
standard = "10up-Default"
})
No error now in opening neovim, but now when I open PHP files, even if there is no xml file in the root I get this:
For reference, this is the lua file that is errored in: https://gist.github.com/xavortm/135c58c3326be8221711e3513ea39b3f in case it's of help
It looks like the stdout
of the phpcs
is not a valid json.
Try to load the branch debug
and share with me the response printed.
Okay; but just to be sure - when I do not add the require() from above, it works, and I can format, have the inline error messages and all. The only downside is that it was not using the 10up-defaults standard. Does that mean that the phpcs json output changes when I use require or there is something else going on?
While on debug, the error when opening a PHP file is different now:
Its a typo. Could you please update it again?
Sure, there it is:
Does that error mean my standard is not globally available? Or rather, does it requrie it to be globally available or it uses what's in the xml I shared at the top?
When I run phpcs -i
I get this:
The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, Modernize, NormalizedArrays, Universal, PHPCSUtils, WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra
So I can see the standard is not available, but I thought it would read it from the local project. Or it doesn't work like that?
*Edit - in my composer.json I do have the package "10up/phpcs-composer": "^3.0",
(git repo - https://github.com/10up/phpcs-composer/tree/master) which should include the xml file I think. I did re-try to install composer packages (install or update) and the error is the same
I am testing a little more as I have some missing tokens and will write back
Yes, if you do not specify any standard it will detect the phpcs.xml
file in the root folder.
If you want to specify the standard name then it should be available in phpcs's list of standard.
So, in your case you dont need to call the setup
function. The plugin must detect the phpcs.xml
ruleset
Thanks :) I have made two changes:
Removed the setup and changed to
vim.g.nvim_phpcs_config_phpcs_standard = '10up-Default' -- or path to your ruleset phpcs.xml
where before it said 'WordPress'.
In a php file now I get this error:
{ "\27[31mE\27[0m 1 / 1 (100%)", "", "", '{"totals":{"...able":false,"type":"ERROR","line":1,"column":1}]}}}' }
Or should I not change the global standard value? In 100% of my projects I do use this standard, but I can't get it installed globally so I was hoping it would read it from the repositories I work in as they all have it from composer.
Yes, if you add this 10up/phpcs-composer
repo as a dependancy in your project's composer.json it might work.
Also, setting this vim.g.nvim_phpcs_config_phpcs_standard = '10up-Default'
will be overridden if a phpcs.xml
file is exists in your root directory.
Could you please share me the stdout of the below command from your project's root folder
./vendor/bin/phpcs --report=json .
Reverted to use 'WordPress' then 👍
Output from the command from root: https://gist.github.com/xavortm/2609bffdebaa803ef52d420c8221c381
My composer.json does include it as a dep, all projects I have tested on do:
...
"require-dev": {
"10up/phpcs-composer": "^3.0",
...
Could please confirm that you have provided the --report=json
option ?
If yes then it should print the json string
Apologies, I didn't knew of the command; here it is -> https://gist.github.com/xavortm/69cc30f81c818674c9488398bc817e10
I have stripped the first line with the ....ww...ww content and formatted the json for easy reading.
No worries. Actually those dots and progress should not be shown.
Let me fix this real quick.
Thanks again for your patience and for bringing this to my attention! I appreciate you helping me debug the issue.
Great! I've fixed the issues you reported. Please let me know if you have a chance to test it and encounter any further problems.
This is amazing, it works perfectly now! Of course, I still have to open my vim instance from the place where the xml file is, but that is totally fine I think. Thank you for the time and work on this, really really appreciated!
I'm happy to report that the fix is in place and should resolve the issue you reported. Please let me know if you encounter any further problems.
Hi! First, thanks for the plugin, it's really useful to me!
But unfortunately, sometimes I get an error for every PHP file I open, sometimes I don't and I am struggling to locate the problem. Here is what I get:
After I Q to close it, I can use the file and edit, but then when I save, it runs again.
This is my config file for the plugin:
The project has a phpcs.xml file that looks like this:
However one other problem I found is that when I save, my formatter isnot the defined in the file 10up-Default but WordPress instead which I have globally in phpcs and in the plugin config. I read that using the phpcs.xml file is a TODO, so I don't expect this to work., but the other error is really annoying.
However, when I open the project in a deeper folder, the error doesn't show up. It does only when a phpcs.xml is at the level I run nvim from.