junstyle / vscode-php-cs-fixer

PHP CS Fixer extension for VS Code

Home Page:https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

ngdangtu-vn opened this issue · comments

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:

  • The rules contain unknown fixers "no_space_around_double_colon"
  • [binary_operator_spaces] Invalid configuration: Unexpected "operators" key, expected any of "=", "", "/", "%", "<"
    , ">", "|", "^", "+", "-", "&", "&=", "&&", "||", ".=", "/=", "=>", "==", ">=", "===", "!=", "<>", "!==", "<=", "an
    d", "or", "xor", "-=", "%=", "
    =", "|=", "+=", "<<", "<<=", ">>", ">>=", "^=", "", "=", "<=>", "??", "??=", got
    "integer#0".
  • and some other error that I can't reproduce

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:

  • composer 2.1.3
  • php-cs-fixer 3.1.0 River
  • php cs fixer v0.2.8 (vscode ext install from vscodium marketplace) (enabled for workspace scope)

it's clear from the error info.

single quote and double quote is differrence in php

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

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?

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

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