adael / SublimePhpCsFixer

Run php-cs-fixer code formatter to format php code from your favorite text editor
MIT License
71 stars 14 forks source link

Doesn't work without project folder open #20

Closed Luc45 closed 7 years ago

Luc45 commented 7 years ago

When I use PHPCSFixer: format this file, nothing happens. Here's what my config looks like:

{
    "config": "C:\\Users\\lucas.figueiredo\\.phpcsfixer",
    "on_save": true
}

Here's what .phpcsfixer looks like:

<?php
return PhpCsFixer\Config::create()
->setRules([
    '@PSR2' => true,
    'array_syntax' => ['syntax' => 'short'],
    'no_unused_imports' => true,
]);

PhpCsFixer is installed globally via composer. If I run php-cs-fixer fix file.php on cmd, it works.

The executable path is also correct, here's what php-cs-fixer.bat looks like:

@ECHO OFF
setlocal DISABLEDELAYEDEXPANSION
SET BIN_TARGET=%~dp0/../friendsofphp/php-cs-fixer/php-cs-fixer
php "%BIN_TARGET%" %*

/../friendsofphp/php-cs-fixer/php-cs-fixer -> exists

How can I further debug why nothing happens on Sublime?

-- Edit --

On Sublime Console I got this:

PHP CS Fixer: Formatting view...
PHP CS Fixer: autodetected: C:\Users\lucas.figueiredo\AppData\Roaming\composer\vendor\bin\php-cs-fixer.bat
Traceback (most recent call last):
  File "C:\Sublime Text 3\sublime_plugin.py", line 818, in run_
    return self.run(edit)
  File "SublimePhpCsFixer in C:\Users\lucas.figueiredo\AppData\Roaming\Sublime Text 3\Installed Packages\PHP CS Fixer.sublime-package", line 206, in run
  File "SublimePhpCsFixer in C:\Users\lucas.figueiredo\AppData\Roaming\Sublime Text 3\Installed Packages\PHP CS Fixer.sublime-package", line 112, in format_contents
  File "SublimePhpCsFixer in C:\Users\lucas.figueiredo\AppData\Roaming\Sublime Text 3\Installed Packages\PHP CS Fixer.sublime-package", line 149, in format_file
  File "SublimePhpCsFixer in C:\Users\lucas.figueiredo\AppData\Roaming\Sublime Text 3\Installed Packages\PHP CS Fixer.sublime-package", line 189, in get_project_folder
AttributeError: 'NoneType' object has no attribute 'get'

Which led me to use "Open folder with Sublime", which solved the problem:

PHP CS Fixer: Formatting view...
PHP CS Fixer: autodetected: C:\Users\lucas.figueiredo\AppData\Roaming\composer\vendor\bin\php-cs-fixer.bat
PHP CS Fixer: Using config: C:\Users\lucas.figueiredo\.phpcsfixer
PHP CS Fixer: Done. View formatted

Long story short, it only seems to work if there is a project folder on the sidebar?