Giter VIP home page Giter VIP logo

vscode-php-cs-fixer's People

Contributors

alecgeatches avatar bluedasher13 avatar cvergne avatar eclipxe13 avatar emtudo avatar goodjack avatar ifeltsweet avatar imacrayon avatar inkvizytor avatar jkulak avatar junstyle avatar markjaquith avatar mayani avatar oldstarchy avatar rainrider avatar sdvallejo avatar smhnaji avatar stollr avatar suigingin avatar thaldos avatar tiagosilvapereira avatar ylivay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-php-cs-fixer's Issues

PHP Parse error: syntax error, unexpected '?'

vscode: v1.19.3
php-cs-fixer: homebrew/php/php-cs-fixer: stable 2.10.0 (bottled)

Issue

Throws these error in the developer tools when I tried to fix the file.

[Extension Host] PHP Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /usr/local/Cellar/php-cs-fixer/2.10.0/vendor/symfony/options-resolver/OptionsResolver.php on line 980
[Extension Host] Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /usr/local/Cellar/php-cs-fixer/2.10.0/vendor/symfony/options-resolver/OptionsResolver.php on line 980

pathMode

The pathMode intersection doesnt work for me. When i use override it works. I also dont get any errors in the console.

Here is my .php_cs:

<?php

return PhpCsFixer\Config::create()
    ->setUsingCache(false)
    ->setRules([
        '@PSR2' => true,
        '@Symfony' => true,
        'array_syntax' => [
            'syntax' => 'short',
        ],
        'increment_style' => [
            'style' => 'post',
        ],
        'not_operator_with_successor_space' => true,
        'ordered_imports' => true,
        'yoda_style' => false,
    ])
    ->setFinder(
        PhpCsFixer\Finder::create()
            ->exclude([
                'test',
                'vendor',
                'node_modules',
            ])
            ->in(__DIR__)
            ->name('*.php')
            ->ignoreDotFiles(true)
            ->ignoreVCS(true)
    )
;

And this is my vscode config:

"php-cs-fixer.config": "/Users/nico/Sites/.php_cs",
"php-cs-fixer.executablePath": "/usr/local/bin/php-cs-fixer",
"php-cs-fixer.lastDownload": 0,
"php-cs-fixer.onsave": true,
"php-cs-fixer.pathMode": "intersection",

Enable php-cs-fixer.rules as json

I know it's is possible to use a .php_cs file fot this but nonetheless:
I noticed it's possible to pass more complex rules but the extension expects the rule as a string

this works but it's ugly

"php-cs-fixer.rules": "{\"@Symfony\":true,\"array_syntax\":{\"syntax\":\"short\"}}"

this doen't work

"php-cs-fixer.rules": {
	"@Symfony": true,
	"array_syntax": { "syntax": "short" }
}

is it possible to support both simple string (better for "@symphony") and json for complex example above

Get executablePath wrong

The executablePath for php.exe it is not obtained correctly.

this.executablePath = workspace.getConfiguration('php').get('php.validate.executablePath', 'php');
this.executablePath = workspace.getConfiguration('php').get('validate.executablePath', 'php');

This is the Object returned by workspace.getConfiguration('php')

{
   "suggest":{
      "basic":true
   },
   "validate":{
      "enable":true,
      "executablePath":".../php.exe",
      "run":"onType"
   }
}

Error on Save

I'm using latest version on VS Code and I have set format on save option to true.
However, I get following errors when I save :

[Atishay-Jain.All-Autocomplete] Cannot read property 'split' of undefined: TypeError: Cannot read property 'split' of undefined
	at Function.replace (C:\Users\Aditya\.vscode\extensions\Atishay-Jain.all-autocomplete-0.0.10\out\src\extension.js:112:25)
	at e.contentChanges.forEach (C:\Users\Aditya\.vscode\extensions\Atishay-Jain.all-autocomplete-0.0.10\out\src\extension.js:139:41)
	at Array.forEach (native)
	at Function.handleContextChange (C:\Users\Aditya\.vscode\extensions\Atishay-Jain.all-autocomplete-0.0.10\out\src\extension.js:138:26)
	at context.subscriptions.push.vscode_1.workspace.onDidChangeTextDocument (C:\Users\Aditya\.vscode\extensions\Atishay-Jain.all-autocomplete-0.0.10\out\src\extension.js:224:30)
	at e.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:4:84411)
	at e.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:4:86133)
	at e.$acceptModelChanged (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:4:427937)
	at t.e.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:4:509443)
	at e._invokeHandler (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:4:354786)

Not working in ubuntu

  • VSCode Version: 1.18.0
  • OS Version: Ubuntu 16.04 LTS

Tried removing all extensions and config etc. Still cant fix it

console.ts:123 [Extension Host]% Array(4) console.ts:123 [Extension Host] Error: spawn php-cs-fixer ENOENT at exports._errnoException (util.js:1050:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32) at onErrorNT (internal/child_process.js:367:16) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9) console.ts:123 [Extension Host]% (4) ["fix", "--using-cache=no", "/tmp/temp-lveplztq.php", "--rules=@PSR2"] console.ts:123 [Extension Host] Error: spawn php-cs-fixer ENOENT at exports._errnoException (util.js:1050:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32) at onErrorNT (internal/child_process.js:367:16) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9)

Reproduces without extensions: No

Is there a way to change the PHP path?

I am trying to disable xdebug when running php-cs-fixer. I found this old issue for Atom: pfefferle/atom-php-cs-fixer#27 and have adjusted to work for the current php-cs-fixer by changing it to:

/usr/bin/env php -n -dextension=phar.so -dextension=tokenizer.so -dextension=ctype.so -dextension=json.so "$@"

And saved that to /usr/local/bin/phpx. Now I want to launch php-cs-fixer using it. Is there currently a way to configure this in the extension?

Format selection fails if there are linting errors

If you attempt to format a method inside class it will fail. That is because php-cs-fixer will abort because of linting errors. This is understandable because we only provided part of our code to php-cs-fixer and it doesn't see the rest of context.

Is there a way to provide the whole context to php-cs-fixer but only apply fixes to specific lines?

php general error (windows)

Trying to run this extension on windows in vs code i get the following error:

  The "app" directory does not exist.  
                                       

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>...]


notificationsAlerts.ts:42 PHP CS Fixer: php general error.
e.onDidNotificationChange @ notificationsAlerts.ts:42
log.ts:171   ERR An unknown error occurred. Please consult the log for more details.

image

In log:
image

running php-cs-fixer:

$ php-cs-fixer -v
PHP CS Fixer 2.12.2 Long Journey by Fabien Potencier and Dariusz Ruminski

vs code settings:


    "php-cs-fixer.executablePathWindows": "php-cs-fixer.bat",
    "php.validate.executablePath": "C:\\tools\\php72\\php.exe"

the file is in the app\Http\Controllers Folder (Laravel). But even files in the root of the project seem to get the same error.

Ive been trying to get it to work googling for what to configure for windows, but nothing seems to work.

Fix on save no longer working

Seems since a recent VS Code update the "fix on save" config option no longer works. However running php cs fixer manually thru the command palette works

image

PHP CS Fixer Plugin not working

Hey!

I tried your plugin, installed php cs fixer correctly (Can use it via commandline)

But it won't format my files with your extension. Log from devtools:

["fix", "--using-cache=no", "C:\Users\Philipp\AppData\Local\Temp/temp-ystcafynnq.php", "--rules=@PSR2"]

After that, nothing happens.

I have the latest php cs fixer version installed and the latest normal VSCode build.

Tanks!

Not initializing on vscode start

Hello,

Each time I start VSCode I need to deactivate this extension and activate it again.
If I don't to that the extension is not working (nothing happens).

No errors appear in the console.

My config :

  • OSX High Sierra
  • VSCode 1.17.1
"php-cs-fixer.executablePath": "/Users/myname/.composer/vendor/bin/php-cs-fixer",
"php-cs-fixer.onsave": true,
"php-cs-fixer.config": "/Users/myname/.phpcsfixer",
"php-cs-fixer.allowRisky": true,

Other extensions installed :

  • PHP DocBlocker
  • PHP IntelliSense
  • PHP Namespace Resolver
  • Other extensions not revelant to PHP

Any idea ?
Thanks,

PHP 7.3 Support

Add support for PHP 7.3. Currently, a general error is shown when trying to format a PHP document.

image

"Sorry, but there is no formatter for 'plaintext'-files installed." when saving a new PHP-file

Whenever I save a new PHP-file, I see the message "Sorry, but there is no formatter for 'plaintext'-files installed.". If I disable vscode-php-cs-fixer and reloads vscode, the issue disappears, so I'm pretty confident the issue is with this plugin.

  • Extension Name: php-cs-fixer
  • Extension Version: 0.1.56
  • OS Version: Darwin x64 17.3.0
  • VSCode version: 1.19.2

We have written the needed data into your clipboard. Please paste:

{
	"activationTimes": {
		"startup": false,
		"codeLoadingTime": 15,
		"activateCallTime": 1,
		"activateResolvedTime": 0,
		"activationEvent": "onLanguage:php"
	}
}

Formatting HTML Inserts Tabs Instead of Spaces

Is it possible to format the HTML so it uses spaces instead of tabs? Right now it enters a tab that is equivalent to 2 spaces regardless of other settings and configuration like .editorconfig. In the config I have ->setIndent(' ') to be 2 spaces as well.

PHP CS Fixer: executablePath not found

screenshot_2

The extension is throwing me errors.

  1. Installed using Composer. Successful. Found .bat file in bin.
  2. PATH var: C:\Users\{My Username}\AppData\Roaming\Composer\vendor\bin
  3. Set "php-cs-fixer.executablePathWindows"="php-cs-fixer.bat" in settings

When I try to Fix the document it throws me
PHP CS Fixer: executablePath not found, please check your settings. It will set to built-in php-cs-fixer.phar. Try again!
I am on Windows 10.

Other extensions taking precedence in right-click menu

I have this extension working well on its own. Unfortunately, some other extensions also have a formatting option included and the right-click menu is executing. the other extension. I have to format by going into the command palette.

The question I want to ask here is "do you know a way I can get the right-click menu to execute the extension I want"?

macOS: Running the contributed command:'php-cs-fixer.diff' failed.

I'm trying to run this extension on macOS (also completely new to Visual Studio).

php-cs-fixer is available globally. If I run in a terminal, here's what I get

$ php-cs-fixer --version
PHP CS Fixer 2.12.1 Long Journey by Fabien Potencier and Dariusz Ruminski (beef6cb)
$ which php-cs-fixer
/usr/local/bin/php-cs-fixer

Following the discussion in #2, I tried changing the executablePath, but still getting the same errors

"php-cs-fixer.executablePath": "/usr/local/bin/php-cs-fixer",

Error:

notificationsAlerts.ts:40 Error: Running the contributed command:'php-cs-fixer.diff' failed.
	at e._executeContributedCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:674:709)
	at e.$executeContributedCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:675:6)
	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)
e.onDidNotificationChange @ notificationsAlerts.ts:40
(anonymous) @ notificationsAlerts.ts:28
e.fire @ event.ts:140
e.notify @ notifications.ts:127
e.error @ notificationService.ts:61
t.onError @ commandsHandler.ts:326
(anonymous) @ commandsHandler.ts:311
done @ winjs.base.js:1393
v @ winjs.base.js:1239
enter @ winjs.base.js:916
_run @ winjs.base.js:1083
_error @ winjs.base.js:1056
e.resolveErr @ lazyPromise.ts:78
e._receiveReplyErr @ rpcProtocol.ts:245
e._receiveOneMessage @ rpcProtocol.ts:187
(anonymous) @ rpcProtocol.ts:111
(anonymous) @ rpcProtocol.ts:307
e.fire @ event.ts:140
(anonymous) @ ipc.net.ts:81
emitOne @ events.js:96
emit @ events.js:191
readableAddChunk @ _stream_readable.js:178
Readable.push @ _stream_readable.js:136
onread @ net.js:560

Any idea what I'm doing wrong?

PHP CS Fixer: php general error

When i try to save a file i get the error 'PHP CS Fixer: php general error'

When i try to run php-cs-fixer fix . from the terminal it formats all my files correctly ...

Some help please?
screen shot 2017-03-01 at 13 15 12
screen shot 2017-03-01 at 13 16 16

php include_once space inserted in associative array key value

When fixing the following example, an extra space is inserted in the key $_SERVER['DOCUMENT_ROOT'] so that it becomes $_SERVER['DOCUMENT_ROOT ']

Example:

<a href='javascript:void(0);' id='<?php echo $DeptID; ?>' onclick='changeDepartment("<?php echo $DeptID; ?>","<?php echo str_replace("'
  ", "\\ ", $DeptName); ?>  ", "<?php echo $DeptShortName; ?>",
  1, "<?php echo $DeptState ?>"); '>
                            <span class="icon-office"></span><?php echo $Pro_DeptName . ' TO '; ?>
                        </a>
                
<!-- ### BEGIN: Help Modal ### -->
<?php include_once $_SERVER['DOCUMENT_ROOT'] . "/shared/helpModal.php";  ?>
<!-- ### END: Help Modal ### -->

Output:

<a href='javascript:void(0);' id='<?php echo $DeptID; ?>' onclick='changeDepartment("<?php echo $DeptID; ?>","<?php echo str_replace("'
  ", "\\ ", $DeptName); ?>  ", "<?php echo $DeptShortName; ?>",
  1, "<?php echo $DeptState ?>"); '>
                            <span class="icon-office"></span><?php echo $Pro_DeptName . ' TO '; ?>
                        </a>
                
<!-- ### BEGIN: Help Modal ### -->
<?php include_once $_SERVER['DOCUMENT_ROOT '] . "/shared/helpModal.php";  ?>
<!-- ### END: Help Modal ### -->

Can I use vendor/bin/php-cs-fixer for the executable?

I've installed php-cs-fixer on a per-project basis via composer require --dev friendsofphp/php-cs-fixer

How can I have this extension use the vendor/bin/php-cs-fixer executable and also use my .php_cs file in the project root folder?

Relative Path config file.

Hey i have a situation here. I want to share the Visual Studio Code settings between work, home, multiple places but with different Users. The problem i got is that i cannot use relative path for the config file in the settings.

For example i have:

"php-cs-fixer.config": "/Users/name1/Coding/php-cs-fix/.php_cs"
but for work i have this:
"php-cs-fixer.config": "/Users/name2/Coding/php-cs-fix/.php_cs"

so if i will use a sync process between those computers i will every time have to update the correct user.

a solution can be to be allowed to use a relative path:
"php-cs-fixer.config": "~/Coding/php-cs-fix/.php_cs"

Thanks!
And good job with the extension!

Cant get it work again :(

Hi ,
I tried everything but i can't get it work again. When i first installed it and set it, it worked like a charm and i was really happy. Now i'm getting this error over and over again :

ERR Bad argument: TypeError: Bad argument
at ChildProcess.spawn (internal/child_process.js:294:26)
at Object.exports.spawn (child_process.js:390:9)
at PHPCSFixer.format (C:\Users\random.vscode\extensions\junstyle.php-cs-fixer-0.1.55\extension.js:94:23)
at exports.activate.context.subscriptions.push.languages.registerDocumentFormattingEditProvider.provideDocumentFormattingEdits.Promise (C:\Users\random.vscode\extensions\junstyle.php-cs-fixer-0.1.55\extension.js:340:25)
at Promise ()
at Object.provideDocumentFormattingEdits (C:\Users\random.vscode\extensions\junstyle.php-cs-fixer-0.1.55\extension.js:334:24)
at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:443:456
at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:93:1004
at new n.Class.derive._oncancel (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:74:234)
at Object.t.asWinJsPromise (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:93:967)

I have .php_cs file in my project and i got this in my settings
"php-cs-fixer.executablePath": "d://php-cs-fixer.phar"

I really need help over here because i need this took working back again cause it's awesome !

Applying fixer on temp file with different name cause not working with risky rules

Hello, I'm using the extension and it is working very well, except when using 'psr4'.
This rule is supposed to rename the class to match the file name.

The problem is that your extension is giving temporary file name, to apply the fixer on the code:

fileName = TmpDir + '/temp-' + Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10) + '.php';

and so the rule 'psr4' can not be working. 😞

What about giving the temp file the same name like opened file:

fileName = TmpDir +'/' + vscode.window.activeTextEditor.document.uri.fsPath.replace(/^.*[\\\/]/, '');

This way it is all working. ?M

Thanks

@Symfony and concat_space not correct.

When im using the following rules "php-cs-fixer.rules": "@PSR2,@Symfony", they are not being followed.
return ' ' . $test . ' ';
should be formatted to
return ' '.$test.' ';

When running php-cs-fixer fix /path/to/file --rules=@PSR2,@Symfony this works.

onSave and onSemicolon, doesn't work

Visual studio code: version 1.18.1
F1-> php-cs-fixer: fix this file works
on brackets works.
but when enableing this:
"php-cs-fixer.onsave": true,
"php-cs-fixer.autoFixBySemicolon": true,
it does absolutely nothing.
note: latest version of php-cs-fixer also installed also via composer

align_double_arrow = true seems not working

Hi, I am running Ubuntu 16.04 with Visual Studio Code 1.18.1
When I have a PHP table that is not well formatted, I run ALT+MAJ+F and it doesn't format well. Example:

echo $twig->render('file.twig', [
'value1'           => $value1,
    'value2'  => $value2,
               'value3'    => $value3,
]);

When I do 'Format Document' it doesn't change the PHP table. I'd like it to be displayed as this,

echo $twig->render('file.twig', [
    'value1' => $value1,
    'value2' => $value2,
    'value3' => $value3,
]);

Do you have any idea?

Here is my settings.json file

{
    "workbench.iconTheme": "vscode-icons", // Affiche des icônes dans l'explorateur de fichiers
    "editor.renderWhitespace": "none", // Affiche les espaces dans l'éditeur
    "editor.renderIndentGuides": true, // Affiche les guides d'indentation
    "minify.minifyExistingOnSave": true, // Minifie les fichiers à l'enregistrement (Minify)
    "editor.minimap.enabled": true,
    "editor.renderLineHighlight": "none",
    "extensions.ignoreRecommendations": false,
    "window.openFilesInNewWindow": "on",
    "window.title": "${dirty}${activeEditorMedium}${separator}${rootName}${separator}${appName}", // Config. titre fenêtre (Chermin du fichier - projet - Visual Studio Code)
    // Configure glob patterns for excluding files and folders.
    "files.exclude": {
        "**/vendor": true
    },
    "php.suggest.basic": false,
    "php.executablePath": "/usr/bin/php",
    "workbench.colorTheme": "Default Light+",
    "window.zoomLevel": 0,
    "php-cs-fixer.executablePath": "php-cs-fixer",
    "php-cs-fixer.config": ".php_cs",
    "php-cs-fixer.onsave": true,
    "editor.detectIndentation": false,
    "editor.fontSize": 12
}

Here is my .php_cs


<?php

return PhpCsFixer\Config::create()
    ->setRules([
        '@PSR2'                                         => true,
        'array_syntax'                                  => array('syntax' => 'short'),
        'combine_consecutive_unsets'                    => true,
        'method_separation'                             => true,
        'no_multiline_whitespace_before_semicolons'     => true,
        'single_quote'                                  => true,
        'binary_operator_spaces'                        => array('align_double_arrow' => true, 'align_equals' => false),
        'blank_line_after_opening_tag' => true,
        'blank_line_before_return'     => true,
        'braces'                       => array('allow_single_line_closure' => true),
        // 'cast_spaces' => true,
        // 'class_definition' => array('singleLine' => true),
        'concat_space'            => array('spacing' => 'one'),
        'declare_equal_normalize' => true,
        'function_typehint_space' => true,
        'hash_to_slash_comment'   => true,
        'include'                 => true,
        'lowercase_cast'          => true,
        // 'native_function_casing' => true,
        // 'new_with_braces' => true,
        // 'no_blank_lines_after_class_opening' => true,
        // 'no_blank_lines_after_phpdoc' => true,
        // 'no_empty_comment' => true,
        // 'no_empty_phpdoc' => true,
        // 'no_empty_statement' => true,
        'no_extra_consecutive_blank_lines' => array('curly_brace_block',
            'extra',
            'parenthesis_brace_block',
            'square_brace_block',
            'throw',
            'use',
        ),
        // 'no_leading_import_slash' => true,
        // 'no_leading_namespace_whitespace' => true,
        // 'no_mixed_echo_print' => array('use' => 'echo'),
        'no_multiline_whitespace_around_double_arrow' => true,
        // 'no_short_bool_cast' => true,
        // 'no_singleline_whitespace_before_semicolons' => true,
        'no_spaces_around_offset' => true,
        // 'no_trailing_comma_in_list_call' => true,
        // 'no_trailing_comma_in_singleline_array' => true,
        // 'no_unneeded_control_parentheses' => true,
        // 'no_unused_imports' => true,
        'no_whitespace_before_comma_in_array' => true,
        'no_whitespace_in_blank_line'         => true,
        // 'normalize_index_brace' => true,
        'object_operator_without_whitespace' => true,
        // 'php_unit_fqcn_annotation' => true,
        // 'phpdoc_align' => true,
        // 'phpdoc_annotation_without_dot' => true,
        // 'phpdoc_indent' => true,
        // 'phpdoc_inline_tag' => true,
        // 'phpdoc_no_access' => true,
        // 'phpdoc_no_alias_tag' => true,
        // 'phpdoc_no_empty_return' => true,
        // 'phpdoc_no_package' => true,
        // 'phpdoc_no_useless_inheritdoc' => true,
        // 'phpdoc_return_self_reference' => true,
        // 'phpdoc_scalar' => true,
        // 'phpdoc_separation' => true,
        // 'phpdoc_single_line_var_spacing' => true,
        // 'phpdoc_summary' => true,
        // 'phpdoc_to_comment' => true,
        // 'phpdoc_trim' => true,
        // 'phpdoc_types' => true,
        // 'phpdoc_var_without_name' => true,
        // 'pre_increment' => true,
        // 'return_type_declaration' => true,
        // 'self_accessor' => true,
        // 'short_scalar_cast' => true,
        'single_blank_line_before_namespace' => true,
        // 'single_class_element_per_statement' => true,
        // 'space_after_semicolon' => true,
        // 'standardize_not_equals' => true,
        'ternary_operator_spaces' => true,
        // 'trailing_comma_in_multiline_array' => true,
        'trim_array_spaces'               => true,
        'unary_operator_spaces'           => true,
        'whitespace_after_comma_in_array' => true,
    ])
    //->setIndent("\t")
    ->setLineEnding("\r\n")
    ->setUsingCache(false);

Exception raised within the application (over sshfs)

Hi, thanks for your extension !

php-cs-fixer 2.9.0

I'm trying to make it work in VSCode while editing a remote project over sshfs but I'm getting this error when trying to fix via vscode :

["fix", "--using-cache=no", "/tmp/temp-numfvly.php", "--config=/home/user/workspace/company/server/project/.php_cs"]

Loaded config Company (PHP 7.0) from "/home/user/workspace/company/server/project/.php_cs".
Paths from configuration file have been overridden by paths provided as command arguments.
Fixed all files in 1.174 seconds, 12.000 MB memory used
Files that were not fixed due to errors reported during fixing:
   1) /tmp/temp-numfvly.php

messageService.ts:126 PHP CS Fixer: Exception raised within the application.
e.doShow @ messageService.ts:126
e.show @ messageService.ts:105
e._showMessage @ mainThreadMessageService.ts:71
n.Class.derive._oncancel @ winjs.base.raw.js:1641
e._showMessage @ mainThreadMessageService.ts:41
e.$showMessage @ mainThreadMessageService.ts:35
e.invoke @ abstractThreadService.ts:42
e._invokeHandler @ rpcProtocol.ts:109
e._receiveOneMessage @ rpcProtocol.ts:96
(anonymous) @ rpcProtocol.ts:32
(anonymous) @ rpcProtocol.ts:157
e.fire @ event.ts:142
(anonymous) @ ipc.net.ts:81
emitOne @ events.js:96
emit @ events.js:191
readableAddChunk @ _stream_readable.js:178
Readable.push @ _stream_readable.js:136
onread @ net.js:560

This is the last message of the developper console, I have no more insight than this.
When I run the command in terminal on the file itself it works
Maybe the tmp file is not created in the first place ? (I can't find it in my /tmp)

Unknown fixers importsOrder

When I try to use importsOrder' => [ 'sortAlgorithm' => 'length'] in the .php_cs file it throws an error

    [PhpCsFixer\ConfigurationException\InvalidConfigurationException]  
  The rules contain unknown fixers: "importsOrder".                  
                                                                     


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>]...

This seems to be true for any rule not in the sample .php-cs config file. I tried to add another rule/fixer
'position_after_control_structures' => 'next' which give a similar error as

[PhpCsFixer\ConfigurationException\InvalidConfigurationException]       
  The rules contain unknown fixers: "position_after_control_structures".  
                                                                          

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>]...

Update .
Sorry my bad. I was using it the wrong way. The correct way to specify the config (I guess) is


        'ordered_imports' => array(
            'importsOrder' => null,
            'sortAlgorithm' => 'length'
        ),
        'braces' => array(
            'position_after_control_structures' => 'next',
            'position_after_functions_and_oop_constructs' => 'next',
        )

Now no more unknown fixers errors.

Error: spawn php-cs-fixer ENOENT

Trying to setup php-cs-fixer for VSCode I get this error for php-cs-fixer v2.8.3 on Windows 10

["fix", "--using-cache=no", "C:\Users\mtpul\AppData\Local\Temp/temp-xwyqjr.php", "--rules=@PSR2"]

Error: spawn php-cs-fixer ENOENT
	at exports._errnoException (util.js:1050:11)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
	at onErrorNT (internal/child_process.js:367:16)
	at _combinedTickCallback (internal/process/next_tick.js:80:11)
	at process._tickCallback (internal/process/next_tick.js:104:9)

My configuration is:

// PHP
// "php-cs-fixer.executablePathWindows": "D:\\installs\\php-cs-fixer\\php-cs-fixer-v2.phar",
"php-cs-fixer.onsave": true,
"php-cs-fixer.autoFixByBracket": true,
"php-cs-fixer.autoFixBySemicolon": true,
"php-cs-fixer.formatHtml": true,

I originally tried to use php-cs-fixer-v2.phar, but for some reason, it can't access the file.

php_unit_method_casing rule not working

I have the php_unit_method_casing set to ['case' => 'snake_case'] but I still get errors after the linter finishes processing the file. What could be the problem?

My .php_cs.dist config is below

<?php

return PhpCsFixer\Config::create()
    ->setRiskyAllowed(true)
    ->setRules([
        '@PSR2' => true,
        '@Symfony' => true,
        'align_multiline_comment' => ['comment_type' => 'phpdocs_like'],
        'array_indentation' => true,
        'array_syntax' => ['syntax' => 'short'],
        'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => true],
        'blank_line_before_statement' => ['statements' => ['continue', 'declare', 'return', 'throw', 'try']],
        'braces' => ['allow_single_line_closure' => true],
        'combine_consecutive_unsets' => true,
        'concat_space' => ['spacing' => 'one'],
        'escape_implicit_backslashes' => ['double_quoted' => true],
        'explicit_indirect_variable' => true,
        'explicit_string_variable' => true,
        'hash_to_slash_comment' => true,
        'linebreak_after_opening_tag' => true,
        'method_chaining_indentation' => true,
        'multiline_comment_opening_closing' => true,
        'multiline_whitespace_before_semicolons' => true,
        'ordered_class_elements' => ['sortAlgorithm' => 'alpha'],
        'ordered_imports' => ['imports_order' => null, 'sort_algorithm' => 'length'],
        'php_unit_method_casing' => ['case' => 'snake_case'],
        'phpdoc_align' => ['align' => 'left'],
        'phpdoc_order' => true,
        'phpdoc_types_order' => ['sort_algorithm' => 'alpha'],
        'psr4' => true,
    ])
    ->setFinder(PhpCsFixer\Finder::create()
        ->exclude('vendor')
        ->in(__DIR__)
    )
;

Screenshot of the error

image

Consider supporting project relative paths for executable

In our project we prefer to install dev tools, including php-cs-fixer, via composer require --dev. This will place our executable under "./vendor/bin/php-cs-fixed" of our project root.

Could you consider supporting relative paths in php-cs-fixer.executablePath. It could use VS Code variables. Example:

"php-cs-fixer.executablePath": "${workspaceRoot}/vendor/bin/php-cs-fixer"

VS Code - Not Running and No Feedback At All

I'm on Windows 10. Installed php-cs-fixer globally via Composer.

The Composer vendor bin folder is in my path and running php-cs-fixer.bat from anywhere works.

In VS Code I've installed the php-cs-fixer extension and set the config option "php-cs-fixer.executablePathWindows" to "php-cs-fixer.bat".

The trouble is the file is not reformatted and there is no feedback in the terminal and no error alert at the top.

Previously when I didn't have the executablePathWindows option set correctly a red alert would pop up telling me php-cs-fixer could not be found.

I'm sure this is something I've neglected to setup in the config file or options PHP file but for the life of me I cannot figure it out. Is there a log file somewhere?

FYI, if I run php-cs-fixer.bat fix FileToFix.php manuall the file is fixed as expected.

String with xml tags is being wrongly formated for some reason

I opened the Issue 3630 in the php-cs-fixer tracker bug, in the end, the bug is related to this extension, so I am opening this one here.

If you enable "php-cs-fixer.formatHtml", strings with XML gs will be broken and the whole code will become invalid.

For example

        $this->assertEquals(
            '<?xml version="1.0"?><fullNames><item key="0"><gender>M</gender><fullName>Jos&#xE9; de Oliveira Pinto</fullName></item><item key="1"><gender>F</gender><fullName>Maria Santos Zafira</fullName></item></fullNames>',
            $serializer->serialize('xml')
        );

will become

        $serializer = new FullNameSerializer($this->getFullNames());
        $this->assertEquals(
            '<?xml version="1.0"?>
    <fullNames>
        <item key="0">
            <gender>M</gender>
            <fullName>Jos&#xE9; de Oliveira Pinto</fullName>
        </item>
        <item key="1">
            <gender>F</gender>
            <fullName>Maria Santos Zafira</fullName>
        </item>
    </fullNames>',
            $serializer->serialize(FullNameSerializer::ENCODER_JSON)
        );

And a multiline string will become broken, since it will try to indent the closing label, what won't allow the multine string to close, what will "eat" all the code until the end of the class.

    public function testXml()
    {
        $xml = <<<XML
<?xml version="1.0"?>
    <fullNames>
        <item key="0">
            <gender>M</gender>
            <fullName>Jos&#xE9; de Oliveira Pinto</fullName>
        </item>
        <item key="1">
            <gender>F</gender>
            <fullName>Maria Santos Zafira</fullName>
        </item>
    </fullNames>
    XML; } }

Pasting a use statement immediately runs php-cs-fixer even with autoFixBySemicolon set to false

Behavior:
On the clip board I have use Test\Name\Space; and I try to paste it in. My rule set (in .php_cs.dist) removes unused use statements but the issue is it should not have called php-cs-fixer yet. I should be allowed to paste the use statement then go implement where I use it below.

Here are my settings

  "php-cs-fixer.executablePath": "php-cs-fixer",
  "php-cs-fixer.executablePathWindows": "", //eg: php-cs-fixer.bat
  "php-cs-fixer.onsave": false,
  "php-cs-fixer.rules": "@PSR2",
  "php-cs-fixer.config": ".php_cs.dist",
  "php-cs-fixer.autoFixByBracket": false,
  "php-cs-fixer.autoFixBySemicolon": false,
  "php-cs-fixer.formatHtml": false,
  "php-cs-fixer.documentFormattingProvider": true,
  "php-cs-fixer.allowRisky": false

What's happening:
gif

Edit: Also note, that if I were to just copy and paste use Test\Name\Space (with no semicolon) and then type the semicolon it works fine.

Add Support for more than one php-fig coding standard.

vscode version: v 1.18.1
php-cs-fixer version: PHP CS Fixer 2.10.0

Issue:

Am currently using "PSR2" for code fixing, which works fine:
Current Configuration:

{
...

"php-cs-fixer.rules": "@PSR2"

...
}

Question:

I would like to also enforce "PSR1".
Qn: Is it possible to enforce BOTH "PSR1" and "PSR2" at ago ?
For example:
"php-cs-fixer.rules": "@PSR2, @PSR1"

Thanks in advance.

?

?

Typo in readme

tip: try "php-cs.fixer.bat" on windows. => php-cs-fixer.bat

Fixing php inside javascript causes erroneous > ! % pcs - comment - end!# -->

Example:

        <script>
            // ### Begin: Update User Status Function
            $("input#user_active").change(function() {
                $.get("/profile/logic/SetUserProfile.php", {
                    <?php
                    if ($_COOKIE["isTO"]) {
                        ?>
                        Action: "UpdateUserDepartment",
                        UserID: "<?php echo $UserID; ?>",
                        DepartmentID: "<?php echo $userDepartmentID; ?>",
                        <?php
                    } else {
                        ?>
                        Action: "UpdateProfile",
                        UserHexID: "<?php echo $UserHexID; ?>",
                        <?php
                    }
                    ?>
                        Status: $(this).is(":checked") ? 1 : 0
                    },
                    function(data) {
                        // console.log(data);
                        // * Reload Table
                        getUsers();
                    });
            });
            // ### End: Update User Status Function
        </script>

Output:

<script>
    // ### Begin: Update User Status Function
    $("input#user_active").change(function() {
        $.get("/profile/logic/SetUserProfile.php", {
                <?php
                if ($_COOKIE["isTO"]) { ?
                    > ! % pcs - comment - end!# -->
                        Action: "UpdateUserDepartment",
                        UserID: "<?php echo $UserID; ?>",
                        DepartmentID:
                        "<?php echo $userDepartmentID; ?>",
                        <?php
                } else { ?
                    > ! % pcs - comment - end!# -->
                        Action: "UpdateProfile",
                        UserHexID:
                        "<?php echo $UserHexID; ?>",
                        <?php
                } ?
                > ! % pcs - comment - end!# -->
                Status : $(this).is(":checked") ? 1 : 0
            },
            function(data) {
                // console.log(data);
                // * Reload Table
                getUsers();
            });
    });
    // ### End: Update User Status Function
</script>

Support workspace Composer folder

To actively support local Composer installation to find PHP CS Fixer, I believe it would be useful to change line 30 of extension.js in this way:

this.executablePath = config.get('executablePath', '${workspaceRoot}\vendor\bin\' + process.platform === "win32" ? 'php-cs-fixer.bat' : 'php-cs-fixer');

In this way, the plugin should support the workspace Composer folder...

Can not run risky fixers..

Hello,
thanks for the nice extension.

I have a bit of a problem here, I can not make it run risky fixers. If I do it manually:
php-cs-fixer fix file.php --allow-risky=yes --rules="psr4"
It runs fine (renaming the class according to the file name). But if I run it with VSCode, by setting "php-cs-fixer.allowRisky": true and "'psr4' => true," in .php_cs it does not rename the class.

Am I missing something..?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.