soderlind / vscode-phpcbf

PHP Code Beautifier and Fixer for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=persoderlind.vscode-phpcbf
GNU General Public License v3.0
28 stars 10 forks source link

Does Nothing! #21

Open ahmadawais opened 6 years ago

ahmadawais commented 6 years ago

I really want this ext to work. I tried everything.

System:
    OS: macOS Sierra 10.12.6
    CPU: x64 Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
    Memory: 989.34 MB / 16.00 GB
    Shell: 5.2 - /bin/zsh

 Binaries:
    Node: 10.1.0 - ~/.nvm/versions/node/v10.1.0/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 6.0.1 - ~/.nvm/versions/node/v10.1.0/bin/npm
 IDE:
    VSCode: 1.23.1 - /usr/local/bin/code

I have phpcs ext installed. This is what my settings look like…

/ Setting for phpcs.
    "phpcs.executablePath": "/usr/local/bin/phpcs",
    "phpcs.standard": "WPAA",
    // Setting for phpcbf.
    "phpcbf.debug": true,
    "phpcbf.onsave": true,
    "phpcbf.standard": "WPAA",
    "phpcbf.executablePath": "/usr/local/bin/phpcbf",
    "[php]": {
        "editor.formatOnSave": false,
        "editor.formatOnPaste": false,
    },

My coding standard is WPAA, it's my custom WordPress Coding standards setup. I set it up like this and it works in the command line.

This extension does nothing. Shows nothing in the debug console. What to do?

Here's a gif demo.

Help! 🙌

roopemerikukka commented 6 years ago

I'm having kind of same problem. The phpcbf works fine from the command line but the extension does nothing for my code. Neither the "phpcbf.onsave": true or Format Document -command works.

kumelen commented 6 years ago

Same here. I don't remeber what version of vscode i had when the extension still working, but since the last update it doesn't work any more. Now i have 1.23.1 vscode version, on linux. Default config for the extension. If i execute the command directly from the terminal, the corrections applies to the file. But if i press the Ctrl+Alt+I keys nothing happends. I tried setting another shortcut but it's the same. I activated the debug for phpcbf and nothing its showed.

ahmadawais commented 6 years ago

@soderlind any help?

saltnpixels commented 6 years ago

I got it working.... im only trying out vs code because of you @ahmadawais ! in my user settings I had to set the executable path because for some reason it cannot use the global phpcbf.

"phpcbf.executablePath": "/Users/yourUserFolder/.composer/vendor/bin/phpcbf"

ahmadawais commented 6 years ago

@saltnpixels Glad to know that you're trying coz of me. I am 80% ready with the VSCode Power User course. Things like this issue are stuck.

Also I tried "phpcbf.executablePath": "/usr/local/bin/phpcbf", see the issue comment # 1. No can do. I think it's related to your phpcbf version and such.

saltnpixels commented 6 years ago

I found that it worked when I went through the hidden composer folder. And then I finally got it to use the WordPress ruleset

On June 7, 2018 at 11:32:46 PM, Ahmad Awais ⚡️ (notifications@github.com) wrote:

@saltnpixels https://github.com/saltnpixels Glad to know that you're trying coz of me. I am 80% ready with the VSCode Power User https://VSCode.pro/ course. Things like this issue are stuck.

Also I tried "phpcbf.executablePath": "/usr/local/bin/phpcbf", see the issue comment # 1. No can do. I think it's related to your phpcbf version and such.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/soderlind/vscode-phpcbf/issues/21#issuecomment-395635735, or mute the thread https://github.com/notifications/unsubscribe-auth/ALE88rLcc5b9jP8Hmeoh-ZavSW6iF9tvks5t6fBegaJpZM4UUP8C .

kumelen commented 6 years ago

Hi. I also I tried "phpcbf.executablePath": "/usr/local/bin/phpcbf", no success. Any idea?

garrettw commented 6 years ago

Setting the absolute path to phpcbf did not fix the problem for me. (macOS High Sierra 10.13.5) Console error is "An unknown error occurred. Please consult the log for more details." -- but I'm not sure where said log file would be.

createandcode commented 6 years ago

Not working for me either - no matter what path I set for phpcbf.executablePath

blakewilson commented 6 years ago

I'm also getting the same error as @garrettw in the console.

blakewilson commented 6 years ago

With phpcbf.debug set to true I get the following in the console upon "format document"

MacOS High Sierra Version 10.13.5 VSCode Version: 1.24.1 PHPCS Version: 1.0.5 PHPCBF Version: 0.0.8

ERR console.group is not a function: TypeError: console.group is not a function
    at PHPCBF.getArgs (/Users/blakewilson/.vscode/extensions/persoderlind.vscode-phpcbf-0.0.8/extension.js:73:21)
    at PHPCBF.format (/Users/blakewilson/.vscode/extensions/persoderlind.vscode-phpcbf-0.0.8/extension.js:96:55)
    at Promise (/Users/blakewilson/.vscode/extensions/persoderlind.vscode-phpcbf-0.0.8/extension.js:252:30)
    at Promise (<anonymous>)
    at Object.provideDocumentFormattingEdits (/Users/blakewilson/.vscode/extensions/persoderlind.vscode-phpcbf-0.0.8/extension.js:244:28)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:692:344
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:103:887
    at new n.Class.derive._oncancel (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:83:776)
    at Object.t.asWinJsPromise (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:103:850)
    at e.provideDocumentFormattingEdits (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:692:298)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:705:793
    at e._withAdapter (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:701:385)
    at e.$provideDocumentFormattingEdits (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:705:755)
    at e._doInvokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:636:832)
    at e._invokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:636:550)
    at e._receiveRequest (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:635:631)
    at e._receiveOneMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:635:400)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:634:315
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:637:395
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:95:432
    at e.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:96:764)
    at Socket.<anonymous> (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:154:338)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at readableAddChunk (_stream_readable.js:178:18)
    at Socket.Readable.push (_stream_readable.js:136:10)
    at Pipe.onread (net.js:560:20)
garrettw commented 6 years ago

That's a known issue. See #14

kumelen commented 6 years ago

Good news for me. If I remove the phpcs.xml.dist file from my project root the fixer start working again. Also it works if i don't remove it but set my global vscode config declaring:

"phpcbf.executablePath": "/usr/bin/phpcbf",
"phpcbf.standard": "WordPress"

This is my phpcs.xml.dist that before the vscode update work verywell. I'm happy with the default WordPress standard so is fixed for me, but i don't have idea why it gets broken with the custom config file (i dont create it, i found it from internet, cant remember where)

<?xml version="1.0"?>
<ruleset name="WordPress Theme Coding Standards">
    <!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
    <!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
    <!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki -->
    <!-- See https://github.com/wimg/PHPCompatibility -->

    <!-- Set a description for this ruleset. -->
    <description>A custom set of code standard rules to check for WordPress themes.</description>

    <!--
    #############################################################################
    COMMAND LINE ARGUMENTS
    https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
    #############################################################################
    -->

    <!-- Pass some flags to PHPCS:
         p flag: Show progress of the run.
         s flag: Show sniff codes in all reports.
    -->
    <arg value="ps"/>

    <!-- Strip the filepaths down to the relevant bit. -->
    <arg name="basepath" value="./"/>

    <!-- Check up to 8 files simultanously. -->
    <arg name="parallel" value="8"/>

    <!-- Only check the PHP, CSS and SCSS files. JS files are checked separately with JSCS and JSHint. -->
    <arg name="extensions" value="php,css,scss/css"/>

    <!-- Check all files in this directory and the directories below it. -->
    <file>.</file>

    <!--
    #############################################################################
    USE THE WordPress RULESET
    #############################################################################
    -->

    <rule ref="WordPress"/>

    <!--
    #############################################################################
    SNIFF SPECIFIC CONFIGURATION
    #############################################################################
    -->

    <!-- Verify that the text_domain is set to the desired text-domain.
         Multiple valid text domains can be provided as a comma-delimited list. -->
    <rule ref="WordPress.WP.I18n">
        <properties>
            <property name="text_domain" type="array" value="_s"/>
        </properties>
    </rule>

    <!-- Allow for theme specific exceptions to the file name rules based
         on the theme hierarchy. -->
    <rule ref="WordPress.Files.FileName">
        <properties>
            <property name="is_theme" value="true"/>
        </properties>
    </rule>

    <!-- Set the minimum supported WP version. This is used by several sniffs.
         The minimum version set here should be in line with the minimum WP version
         as set in the "Requires at least" tag in the readme.txt file. -->
    <config name="minimum_supported_wp_version" value="4.5"/>

    <rule ref="WordPress.Arrays.MultipleStatementAlignment">
        <properties>
            <!-- No need to adjust alignment of large arrays when the item with the largest key is removed. -->
            <property name="exact" value="false"/>
            <!-- Don't align multi-line items if ALL items in the array are multi-line. -->
            <property name="alignMultilineItems" value="!=100"/>
            <!-- Array assignment operator should always be on the same line as the array key. -->
            <property name="ignoreNewlines" value="false"/>
        </properties>
    </rule>

    <!-- Verify that everything in the global namespace is prefixed with a theme specific prefix.
         Multiple valid prefixes can be provided as a comma-delimited list. -->
    <rule ref="WordPress.NamingConventions.PrefixAllGlobals">
        <properties>
            <property name="prefixes" type="array" value="_s" />
        </properties>
    </rule>

    <!--
    #############################################################################
    USE THE PHPCompatibility RULESET
    #############################################################################
    -->

    <config name="testVersion" value="5.2-99.0"/>
    <rule ref="PHPCompatibility">
        <!-- Whitelist PHP native classes, interfaces, functions and constants which
             are back-filled by WP.

             Based on:
             * /wp-includes/compat.php
             * /wp-includes/random_compat/random.php
        -->
        <exclude name="PHPCompatibility.PHP.NewClasses.errorFound"/>
        <exclude name="PHPCompatibility.PHP.NewClasses.typeerrorFound"/>

        <exclude name="PHPCompatibility.PHP.NewConstants.json_pretty_printFound"/>
        <exclude name="PHPCompatibility.PHP.NewConstants.php_version_idFound"/>

        <exclude name="PHPCompatibility.PHP.NewFunctions.hash_equalsFound"/>
        <exclude name="PHPCompatibility.PHP.NewFunctions.json_last_error_msgFound"/>
        <exclude name="PHPCompatibility.PHP.NewFunctions.random_intFound"/>
        <exclude name="PHPCompatibility.PHP.NewFunctions.random_bytesFound"/>
        <exclude name="PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound"/>

        <exclude name="PHPCompatibility.PHP.NewInterfaces.jsonserializableFound"/>
    </rule>

    <!-- Whitelist the WP Core mysql_to_rfc3339() function. -->
    <rule ref="PHPCompatibility.PHP.RemovedExtensions">
        <properties>
            <property name="functionWhitelist" type="array" value="mysql_to_rfc3339"/>
        </properties>
    </rule>

</ruleset>
matthewfarlymn commented 6 years ago

I thought mine was doing nothing also, but then I realized that it would run... There is no loading indicator in the bottom activity bar and if the file is large it can take time for it to format. Hope this helps... It would probably be a good idea to add a loading/processing indicator similar to the phpcs plugin if possible.

bondansebastian commented 6 years ago

Not working for me too.

I'm on Windows Version 10.0.17134 Build 17134 Using VS Code Version 1.25.1

matthewfarlymn commented 6 years ago

Steps to ensure this plugin correctly formats.

  1. Save the file before performing "Format Document"
  2. Allow for phpcs to complete if you have the plugin auto-running when working on a file
  3. Highlight all content in the document and select "Format Document" from your select menu
  4. Wait about a min if the document is large ( i.e. > 5000 lines ) for PHPCBF to complete

macOS High Sierra v10.13.6 Code v1.25.1 phpcbf v0.0.8

seangwright commented 6 years ago

I had the same issue as the OP, but somehow this extension started working again for me.

I did toggle/change several settings but I don't know which could have fixed it.

That said, anyone can debug the extension (not via breakpoints but via logging) by editing the extension.js installed on your filesystem.

I'm on Windows 10 and my file is found at C:\Users\{user directory}\.vscode\extensions\persoderlind.vscode-phpcbf-0.0.8\extension.js

You can edit this file, adding console.error()/log() statements wherever you want. You can then reload VSCode after making changes to the file (ctrl+shift+p -> Reload Window on Windows) and then open up developer tools (ctrl+shift+p -> Developer: Toggle Developer Tools) to see what the extension is logging out. Maybe you can capture additional errors or paths that aren't correct?

Here is my settings.json for VSCode in case it helps anyone.

{
  "php.validate.executablePath": "D:\\dev\\php721\\php.exe",
  "php.executablePath": "D:\\dev\\php721\\php.exe",
  "php.suggest.basic": false,
  "editor.tabSize": 2,
  "prettier.bracketSpacing": true,
  "prettier.singleQuote": true,
  "prettier.tabWidth": 2,
  "[javascript]": {
    "editor.formatOnSave": true
  },
  "phpcs.ignorePatterns": [
    "wp-admin",
    "wp-content/plugins",
    "wp-content/themes/genesis",
    "wp-includes"
  ],
  "phpcs.executablePath": ".\\vendor\\bin\\phpcs.bat",
  "phpcs.composerJsonPath": ".\\composer.json",
  "phpcs.standard": "WordPress-Extra",
  "phpcs.enable": true,
  "phpcs.showSources": true,
  "phpcs.showWarnings": true,
  "phpcs.trace.server": "off",
  "phpcs.autoConfigSearch": false,
  "phpcbf.executablePath": ".\\vendor\\bin\\phpcbf.bat",
  "phpcbf.documentFormattingProvider": true,
  "phpcbf.debug": false,
  "phpcbf.onsave": true,
  "phpcbf.enable": true,
  "phpcbf.standard": "WordPress-Extra",
  "[php]": {
    "editor.formatOnSave": true
  }
}

And here are the extensions I have installed (extensions.json)

{
  "recommendations": [
    "felixfbecker.php-debug",
    "felixfbecker.php-intellisense",
    "persoderlind.vscode-phpcbf",
    "ikappas.phpcs",
    "esbenp.prettier-vscode"
  ]
}
JohannesMattsson91 commented 5 years ago

I had the same problem as well, but if I first select the code that needs to be formatted, and then right click and select "Highlight selection", it works!

format_highlighted

garrettw commented 5 years ago

That shouldn't be necessary though.

JohannesMattsson91 commented 5 years ago

I agree, but it should help the contributors finding the problem.

jonnyijapan commented 5 years ago

Nothing works so far... I'm having to use phpcs 2.9 though but that shuoldn't be the issue, at least it works if I run from Terminal, outside of VSCode. And I get no output to Debug console even with the debug flag set to true.

JohannesMattsson91 commented 5 years ago

Have you specified the absolute path to phpcbf? In my settings I have this in the option "Executable Path" (yours may differ dep on how you installed it): /home/name/.config/composer/vendor/bin/phpcbf And restart vscode.

jonnyijapan commented 5 years ago

I could finally found the debug logs (that was in Help>Developer console) Seems that the reporting.php of phpcbf tries to write somewhere where it doesn't have write access, looks like the write URL is like "//xxxxx.diff" which looks weird.

jonnyijapan commented 5 years ago

And yes I put the absolute path of the phpcbf executable in settings.

JohannesMattsson91 commented 5 years ago

What operating system are you using? I have had similar problems when installing software in Linux with flatpak.

Also I think you should upgrade phpcs to 3.4 to get all the current fixes.

jonnyijapan commented 5 years ago

macOS Mojave. Can't update phpcs as the fuelphp standard only supports up until 2.9. Well wish I could. Unless I'll have to figure out how to migrate a 2.x standard into 3.x myself.

coccoinomane commented 5 years ago

Hello @ahmadawais, I know this is old, but the following VS Code extension seem to work fine:

It has both the linter (phpcs) and the fixer (phpcbf), the latter being invoked by the usual "Format document" and "Format selection" commands.

Hope it helps.

Best wishes, Guido

benallfree commented 5 years ago

This issue is solved in #30.

etomProductions commented 3 years ago

@benallfree Not true,

Not solved. and there is no clear solution for this. and glad to replace the extension with other stable one. Good luck

artvorobyev commented 3 years ago

Adding this to my settings.json solved the problem: "[php]": { "editor.defaultFormatter": "persoderlind.vscode-phpcbf" }

dgwyer commented 3 years ago

I was having similar issues and after (too long!) trying to get this working I just switched to the other extension and it worked immedately!

https://github.com/wongjn/vscode-php-sniffer


My issues were related to phpcbf not being able to find the WordPress rules even though when running phpcbf -i it showed WordPress in the list of available rules. The developer console was displaying errors saying that WordPress rules cannot be found!

diogoca commented 1 year ago

Same issue here, fixed after removing the PHP DEVSENSE extension.