cjmling / findings

Notes on stuff i finds worth keeping for quick reference later on.
2 stars 0 forks source link

FR: PHP CS Fixer: Configuration error of the application #62

Open cjmling opened 6 years ago

cjmling commented 6 years ago

VS Code on windows had this setting to .bat file and it was working fine then one day it start having this error

"php-cs-fixer.executablePathWindows": "${workspaceRoot}/vendor/bin/php-cs-fixer.bat",

Not sure from where i got that .bat file from and why it was configured to .bat file. Reading up doc again , it is mentioned to link to .phar file. Downloaded the .phar based on php-cs-fixer installation guide, placed the .phar file in that location and changed the setting and it work fine again

"php-cs-fixer.executablePathWindows": "${workspaceRoot}/vendor/bin/php-cs-fixer.phar",

NOTE: may be you need the .phar file which come with the extension not from the main php-cs-fixer lib. https://github.com/junstyle/vscode-php-cs-fixer#install-php-cs-fixer

TO BETTER UNDERSTAND THE ISSUE

In vscode click Help > Toggle Developers Tools it will open something similar to chrome developer tools where we can see actual log what went wrong.

In my case there was this error

The rules contain risky fixers (self_accessor), but they are not allowed to run. Perhaps you forget to use --allow-  
  risky=yes option?  

and because of this not allow of risky , throw configuration error. So to get rid of this or to fix this i have to allow risky fixer which was done by adding ->setRiskyAllowed(true) in .php_cs.dist

for example :

return PhpCsFixer\Config::create()
    ->setRiskyAllowed(true)
    ->setFinder($finder)
    ->setIndent("    ")

OR

Other solution could be just remove that risky ( self_accessor ) rules from .php_cs.dist config file.

Credits: https://stackoverflow.com/a/42276875/507203

cjmling commented 5 years ago

NOTE : At home pc phpcsfixer is also installed globally in C:\Users\cjm_l\AppData\Roaming\Composer\vendor

we can use directly command php-cs-fixer to do stuff in command line without having prefix with php for example php php-cs-fixer

NOTE: php-cs-fixer.bat you get only when install globally but doesn't available when install locally in project. Not sure why.

May be it checked, we were running from inside virtual machine which is linux and therefore it didn't get .bat file ?

cjmling commented 5 years ago

NOTE: Don't forget to update/download the latest cs fixer if you use php 7.3