valeryan / vscode-phpsab

Php Sniffer and Beautifier for VS Code
https://marketplace.visualstudio.com/items?itemName=ValeryanM.vscode-phpsab
MIT License
58 stars 12 forks source link

SyntaxError: Unexpected token '#', " #122

Closed almeidaz closed 8 months ago

almeidaz commented 8 months ago

When i run PHPCBF : fix this file in vscode

it's fixing my file but add a '#' at start of my file.

Example :

<?php
if (! defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

will result :

# <?php
if (! defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

If i run the command line : C:\Users\jinx\AppData\Roaming\Composer\vendor\bin\phpcbf.bat -q --standard=WordPress "c:\wamp64\www\projects\php-test\test.php"

file is fixed without # but there is my log :

C:\Users\jinx\AppData\Roaming\Composer\vendor\bin\phpcbf.bat -q --standard=WordPress "c:\wamp64\www\projects\php-test\test.php"                                                                                           \php-test\test.php"

#
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE                                                  FIXED  REMAINING
----------------------------------------------------------------------
C:\wamp64\www\projects\php-test\test.php              1      3
----------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
----------------------------------------------------------------------

Time: 481ms; Memory: 12MB

We can see a # above PHPCBF RESULT SUMMARY

Do you have any idea where the problem comes from?

jonathanbossenger commented 8 months ago

Hi @almeidaz based on the code, it looks like this is a WordPress plugin file.

I just tested your sample code on my setup, and I cannot replicate the error, so it looks like there's either something on your local Windows environment that's causing this, or the version of phpcbf you have installed.

Can you tell me what your local development environment set up is, and how you installed phpcs and phpcbf.

almeidaz commented 8 months ago

Win10

install via composer global require squizlabs/php_codesniffer

 composer -V
Composer version 2.7.1 2024-02-09 15:26:28
phpcs --version

# PHP_CodeSniffer version 3.9.0 (stable) by Squiz and PHPCSStandards

my settings.json

"php.validate.executablePath": "C:\\wamp64\\bin\\php\\php7.4.33\\php.exe",
"php.executablePath": "C:\\wamp64\\bin\\php\\php7.4.33\\php.exe",
"phpsab.standard": "WordPress",
// "phpsab.standard": "PSR2",
"phpsab.executablePathCS": "C:\\Users\\jinx\\AppData\\Roaming\\Composer\\vendor\\bin\\phpcs.bat",
"phpsab.executablePathCBF": "C:\\Users\\jinx\\AppData\\Roaming\\Composer\\vendor\\bin\\phpcbf.bat",
"phpsab.debug": true,

  "[php]": {
    "editor.defaultFormatter": "valeryanm.vscode-phpsab"
    // "editor.formatOnSave": true
  },
where phpcs
C:\Users\jinx\AppData\Roaming\Composer\vendor\bin\phpcs
C:\Users\jinx\AppData\Roaming\Composer\vendor\bin\phpcs.bat
where phpcbf
C:\Users\jinx\AppData\Roaming\Composer\vendor\bin\phpcbf
C:\Users\jinx\AppData\Roaming\Composer\vendor\bin\phpcbf.bat

Do you have also the # when you type phpcs --version like : # PHP_CodeSniffer version 3.9.0 (stable)...

jonathanbossenger commented 8 months ago

Do you have also the # when you type phpcs --version like :

No, when I run phpcs --version I don't get the #

PHP_CodeSniffer version 3.9.0 (stable) by Squiz and PHPCSStandards

Do you get the # when you run any other terminal command in Windows, or only phpcs --version

almeidaz commented 8 months ago

Thanks for your response and your help.

Edit: Then i have finally found my mistake. I had too much play with Codesniffer.conf file. I had left an error with bad commented code starting with #.

jonathanbossenger commented 8 months ago

Haha that's funny, I was just about to ask if you'd been editing your phpcs config...glad you found it.