junstyle / vscode-php-cs-fixer

PHP CS Fixer extension for VS Code
https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer
MIT License
357 stars 45 forks source link

Invalid "indent" param, expected tab or two or four spaces #159

Closed ngdangtu-vn closed 3 years ago

ngdangtu-vn commented 3 years ago

I got this error while attempt to fix a php by right-clicked on the file in explorer panel and chose php-cs-fixer: fix

From OUTPUT:

Loaded config default from "c:\...\project/.vscode/.php-cs-fixer.php".

In WhitespacesFixerConfig.php line 35:

  Invalid "indent" param, expected tab or two or four spaces.  

fix [--path-mode PATH-MODE] [--allow-risky ALLOW-RISKY] [--config CONFIG] [--dry-run] [--rules RULES] [--using-cache USING-CACHE] [--cache-file CACHE-FILE] [--diff] [--format FORMAT] [--stop-on-violation] [--show-progress SHOW-PROGRESS] [--] [<path>...]

From Dev Console:

["fix", "--using-cache=no", "c:\\...\\project\\.vscode\\.php-cs-fixer.php", "--rules=@PSR2", "--path-mode=override"]

And if I chose php-cs-fixer: diff then nothing display in OUTPUT but I have a long list in Dev Console:

[Extension Host]                                           workbench.desktop.main.js:71
Loaded config default from "c:\...\project\.vscode\.php-cs-fixer.php"

[Extension Host]                                           workbench.desktop.main.js:71
v @ workbench.desktop.main.js:71
$logExtensionHostMessage @ workbench.desktop.main.js:1502
_doInvokeHandler @ workbench.desktop.main.js:1502
_invokeHandler @ workbench.desktop.main.js:1502
_receiveRequest @ workbench.desktop.main.js:1502
_receiveOneMessage @ workbench.desktop.main.js:1502
(anonymous) @ workbench.desktop.main.js:1502
fire @ workbench.desktop.main.js:69
fire @ workbench.desktop.main.js:85
_receiveMessage @ workbench.desktop.main.js:85
(anonymous) @ workbench.desktop.main.js:85
fire @ workbench.desktop.main.js:69
acceptChunk @ workbench.desktop.main.js:85
(anonymous) @ workbench.desktop.main.js:85
k @ workbench.desktop.main.js:2872
emit @ events.js:315
addChunk @ internal/streams/readable.js:309
readableAddChunk @ internal/streams/readable.js:284
Readable.push @ internal/streams/readable.js:223
onStreamRead @ internal/stream_base_commons.js:188

[Extension Host]                                           workbench.desktop.main.js:71
In WhitespacesFixerConfig.php line 35:

  Invalid "indent" param, expected tab or two or four spaces.  

[Extension Host]                                           workbench.desktop.main.js:71
fix [--path-mode PATH-MODE] [--allow-risky ALLOW-RISKY] [--config CONFIG] [--dry-run] [--rules RULES] [--using-cache USING-CACHE] [--cache-file CACHE-FILE] [--diff] [--format FORMAT] [--stop-on-violation] [--show-progress SHOW-PROGRESS] [--] [<path>...]

PHP CS Fixer: php general error.                 workbench.desktop.main.js:71

[Extension Host]                                           workbench.desktop.main.js:71
PHP CS Fixer: php general error.

At first it gave me a lot of error like:

Here is my config (this is the config producing "indent" param, Uncomment fixes to see other error:

<?php

# https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/master/doc/rules

define('INDENT_STYLE', '\t', true);
define('EOL', '\n', true);

$rules =[
    '@PSR1' => true,
    'array_indentation' => true,
    'no_trailing_comma_in_singleline_array'=> true,
    'whitespace_after_comma_in_array' => true,
    'no_whitespace_before_comma_in_array' => [
        'after_heredoc' => true
    ],
    'lowercase_keywords' => true,
    // 'no_space_around_double_colon'=>true,
    'standardize_not_equals'=>true,
    'ternary_operator_spaces'=>true,
    'object_operator_without_whitespace'=>true,
    'ternary_to_null_coalescing'=>true,
    'unary_operator_spaces'=>true,
    'elseif'=>true,
    'trailing_comma_in_multiline'=>[
        'after_heredoc' => true,
        'elements' => ['arrays', 'arguments'],
    ],
    'braces'=>[
        'allow_single_line_closure' => true,
        'position_after_functions_and_oop_constructs' => 'next',
        'position_after_control_structures' => 'next',
        'position_after_anonymous_constructs' => 'next',
    ],
    // 'binary_operator_spaces'=>[
    //  'operators' => ['=>', 'align_single_space_minimal'],
    // ],
    'function_declaration' => [
        'closure_function_spacing' => 'none',
    ],
    'list_syntax' => [
        'syntax' => 'short',
    ],
    'single_quote' => [
        'strings_containing_single_quote_chars' => false,
    ],
    'no_unneeded_curly_braces'=>true,
    'no_singleline_whitespace_before_semicolons'=>true,
    'no_useless_else'=>true,
    'no_alternative_syntax'=>false,
];

$config = new PhpCsFixer\Config();
return $config
    ->setRules($rules)
    ->setIndent(INDENT_STYLE)
    ->setLineEnding(EOL);

Tools details:

junstyle commented 3 years ago

it's clear from the error info.

single quote and double quote is differrence in php

define('INDENT_STYLE', "\t", true);

ngdangtu-vn commented 3 years ago

Thank god that wasn't a bug. And I'm sorry, it was my fault. But what happens to The rules contain unknown fixers "no_space_around_double_colon"? Set it to true is correct config right?

junstyle commented 3 years ago

i think you should read the doc of php-cs-fixer, i do not know yet.

maybe no_space_around_double_colon not exists now

ngdangtu-vn commented 3 years ago

Ok, I will try to google it few more times.