junstyle / vscode-php-cs-fixer

PHP CS Fixer extension for VS Code
https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer
MIT License
356 stars 45 forks source link

Settings are not being used #174

Closed geoff-maddock closed 2 years ago

geoff-maddock commented 2 years ago

I'm running VS Code using WSL1 Ubuntu (on Windows).

I've installed this extension into VS Code and specified the configurations in the settings:

Config File: ./.php-cs-fixer.php (it's in the root of my project) Executable: php-cs-fixer (this is installed locally) OnSave: checked Path Mode: override

When I open a file and hit save, I get a generic error: PHP-CS-FIXER: An error occurred

I opened up the Developer Tools, hit save again, and see the details of the command failing:

PHP-CS-Fixer: An error occurred.
onDidChangeNotification @ notificationsAlerts.ts:42
(anonymous) @ notificationsAlerts.ts:28
invoke @ event.ts:575
deliver @ event.ts:779
fire @ event.ts:740
addNotification @ notifications.ts:206
notify @ notificationService.ts:137
(anonymous) @ mainThreadMessageService.ts:86
_showMessage @ mainThreadMessageService.ts:44
$showMessage @ mainThreadMessageService.ts:38
_doInvokeHandler @ rpcProtocol.ts:473
_invokeHandler @ rpcProtocol.ts:458
_receiveRequest @ rpcProtocol.ts:374
_receiveOneMessage @ rpcProtocol.ts:296
(anonymous) @ rpcProtocol.ts:161
invoke @ event.ts:575
deliver @ event.ts:779
fire @ event.ts:740
fire @ ipc.net.ts:638
_receiveMessage @ ipc.net.ts:958
(anonymous) @ ipc.net.ts:831
invoke @ event.ts:575
deliver @ event.ts:779
fire @ event.ts:740
acceptChunk @ ipc.net.ts:382
(anonymous) @ ipc.net.ts:338
(anonymous) @ browserSocketFactory.ts:230
invoke @ event.ts:575
deliver @ event.ts:779
fire @ event.ts:740
_fileReader.onload @ browserSocketFactory.ts:91
log.ts:313   ERR Command failed: /c/Users/geoff.maddock/AppData/Roaming/Composer/vendor/bin/php-cs-fixer fix /c/Users/geoff.maddock/PhpstormProjects/cadence/src/Controller/Internal/AccountController.php --using-cache=no --config=.php-cs-fixer --path-mode=override
You are running PHP CS Fixer v2, which is not maintained anymore. Please update to v3.
You may find an UPGRADE guide at https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.3.0/UPGRADE-v3.md .
If you need help while solving warnings, ask at https://gitter.im/PHP-CS-Fixer, we will help you!

In ConfigurationResolver.php line 632:

  Cannot read config file ".php-cs-fixer".  

fix [--path-mode PATH-MODE] [--allow-risky ALLOW-RISKY] [--config CONFIG] [--dry-run] [--rules RULES] [--using-cache USING-CACHE] [--cache-file CACHE-FILE] [--diff] [--diff-format DIFF-FORMAT] [--format FORMAT] [--stop-on-violation] [--show-progress SHOW-PROGRESS] [--] [<path>...]

: Error: Command failed: /c/Users/geoff.maddock/AppData/Roaming/Composer/vendor/bin/php-cs-fixer fix /c/Users/geoff.maddock/PhpstormProjects/cadence/src/Controller/Internal/AccountController.php --using-cache=no --config=.php-cs-fixer --path-mode=override
You are running PHP CS Fixer v2, which is not maintained anymore. Please update to v3.
You may find an UPGRADE guide at https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.3.0/UPGRADE-v3.md .
If you need help while solving warnings, ask at https://gitter.im/PHP-CS-Fixer, we will help you!

In ConfigurationResolver.php line 632:

  Cannot read config file ".php-cs-fixer".  

fix [--path-mode PATH-MODE] [--allow-risky ALLOW-RISKY] [--config CONFIG] [--dry-run] [--rules RULES] [--using-cache USING-CACHE] [--cache-file CACHE-FILE] [--diff] [--diff-format DIFF-FORMAT] [--format FORMAT] [--stop-on-violation] [--show-progress SHOW-PROGRESS] [--] [<path>...]

    at ChildProcess.exithandler (node:child_process:397:12)
    at ChildProcess.emit (node:events:390:28)
    at maybeClose (node:internal/child_process:1064:16)
    at Socket.<anonymous> (node:internal/child_process:450:11)
    at Socket.emit (node:events:390:28)
    at Pipe.<anonymous> (node:net:687:12)

No, interestingly, you'll notice that it's not using the config file I specified. So in case it didn't like the non-full path, I specified the full path: /c/Users/geoff.maddock/PhpstormProjects/cadence/.php-cs-fixer.php

I re-saved, and got the same error in the console, and the path was NOT updated to the value in the settings.

To dig a bit deeper, I opened up the User settings.json and found these keys were set for php-cs-fixer:

   "vscode-php-cs-fixer.fixOnSave": false,
    "vscode-php-cs-fixer.toolPath": "/home/gmaddock/.config/composer/vendor/bin/php-cs-fixer",
    "php-cs-fixer.executable": "php-cs-fixer",
    "php-cs-fixer.configFile": "/c/Users/geoff.maddock/PhpstormProjects/cadence/.php-cs-fixer.php"
    "php-cs-fixer.onsave": true,
    "php-cs-fixer.rules": "@PSR2",
    "php-cs-fixer.formatHtml": true,
    "php-cs-fixer.executablePath": "php-cs-fixer",
    "php-cs-fixer.config": "./.php-cs-fixer",

A bit stumped as to what is going on here - no matter what I set the config setting to, the error still says it cannot read ".php-cs-fixer"

junstyle commented 2 years ago
    "php-cs-fixer.config": "/c/Users/geoff.maddock/PhpstormProjects/cadence/.php-cs-fixer.php"

.config not .configFile

geoff-maddock commented 2 years ago

Not sure what the deal exactly was there, but once I wiped out those extra settings, used the full path for both the executable and the config, and restarted ALL instances of vscode that I had open (I had three), it worked.

Thanks for a super useful extension!