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

PHPCBF Writing code fixing result to file, replacing original content #20

Closed Jeffrey04 closed 4 years ago

Jeffrey04 commented 4 years ago

My settings

  "phpsab.executablePathCBF": "/home/jeffrey04/.phpenv/shims/phpcs",
  "phpsab.executablePathCS": "/home/jeffrey04/.phpenv/shims/phpcbf",
  "phpsab.standard": "PSR12",
  "phpsab.debug": true,
  "phpsab.allowedAutoRulesets": [
    ".phpcs.xml",
    ".phpcs.xml.dist",
    "phpcs.xml",
    "phpcs.xml.dist",
    "phpcs.ruleset.xml",
    "ruleset.xml"
  ]

When I was editing this file

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AppendCampaignId extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('vouchers', function (Blueprint $table) {
            $table->uuid('campaign_id')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}

saving it causing it to be replaced with this

----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 7 | ERROR | Each class must be in a namespace of at least one level
   |       | (a top-level vendor name)
----------------------------------------------------------------------

Time: 28ms; Memory: 6MB

disabling this extension will revert this behaviour. I am running vscode 1.46 and extension version is 0.0.5, while phpcbf is installed through composer with this command

composer global require "squizlabs/php_codesniffer=*"

and it is at version

[I]  jeffrey04@NOBITA-UBUNTU ~/P/happyx  $ phpcs --version                                                                                                                                                                         Δ3  master 
PHP_CodeSniffer version 3.5.5 (stable) by Squiz (http://www.squiz.net)
valeryan commented 4 years ago

I am not able to replicate this issue but it seems similar to #17. I have not replicated this problem either. Like in the other issues if you run phpcbf from the comand line do you get correctly formated files or does it replace the file as above?

Jeffrey04 commented 4 years ago

it would work if I do it from the command line though, not sure what went wrong

valeryan commented 4 years ago

In order for me to try and replicate this I would need to know what "/home/jeffrey04/.phpenv/shims/phpcs", has that is different from your global phpcs. It would be good to also have the .phpcs.xml file you are using.

Jeffrey04 commented 4 years ago

sorry I would have to close the ticket as I switched to another extension that works with the same setup

asakoya commented 2 years ago

I got the same problem and found that I had set the path to phpcs as "phpsab.executablePathCBF" 😂 After setting correct phpcbf path, it worked properly.