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

Seeing error: "Paths from configuration file have been overridden by paths provided as command arguments."

charlesroper opened this issue · comments

I'm just getting started with PHP CS Fixer and this extension - thanks for all your efforts on it @junstyle!

I'm having a strange problem. I'm on Windows 10 with PHP 8.1.11 installed. VS Code 1.72.2.

> php-cs-fixer --version
PHP CS Fixer 3.12.0 Oliva by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.11

PHP CS Fixer is installed globally via Composer:

> which php-cs-fixer
C:/Users/Charles/AppData/Roaming/Composer/vendor/bin/php-cs-fixer.bat

The plugin seems to work fine if there are changes to make. The fix, format and diff commands all work as expected.

Here is an example output (I'll copy my .php-cs-fixer.dist.php file in at the bottom here):

[
  "fix",
  "--using-cache=no",
  "--format=json",
  "--config=c:\\tools\\laragon\\www\\Kirby\\.php-cs-fixer.dist.php",
  "--path-mode=override",
  "C:\\Users\\Charles\\AppData\\Local\\Temp\\pcf-tmp0.1661757189684132\\Model.php"
]
{"files":[{"name":"C:\\Users\\Charles\\AppData\\Local\\Temp\\pcf-tmp0.1661757189684132\\Model.php"}],"time":{"total":0.114},"memory":18}

However, if there are no changes to make when I run one of the php-cs-fixer commands, there seems to be an error. See the last two lines here:

[
  "fix",
  "--using-cache=no",
  "--format=json",
  "--config=c:\\tools\\laragon\\www\\Kirby\\.php-cs-fixer.dist.php",
  "--path-mode=override",
  "C:\\Users\\Charles\\AppData\\Local\\Temp\\pcf-tmp0.018226688881113562\\Model.php"
]
{"files":[],"time":{"total":0.147},"memory":18}
Loaded config default from "c:\tools\laragon\www\Kirby\.php-cs-fixer.dist.php".
Paths from configuration file have been overridden by paths provided as command arguments.

This doesn't cause problems for the fix command - it even works fine when I have the fixer run on save. The diff command doesn't seem to show the error at all. So the problem goes largely unnoticed.

Where this issue is more of an actual problem is when using the formatter. VS Code shows me the following error dialog:

2022-10-23_01

Here is the output log:

[
  "fix",
  "--using-cache=no",
  "--format=json",
  "--config=c:\\tools\\laragon\\www\\Kirby\\.php-cs-fixer.dist.php",
  "--path-mode=override",
  "C:\\Users\\Charles\\AppData\\Local\\Temp\\pcf-tmp0.15992573792876685\\Model.php"
]
{"files":[],"time":{"total":0.108},"memory":18}
Loaded config default from "c:\tools\laragon\www\Kirby\.php-cs-fixer.dist.php".
Paths from configuration file have been overridden by paths provided as command arguments.

And here is a screenshot of my devtools log:

2022-10-23_02

Finally, here's the content of my .php-cs-fixer.dist.php (it's just copied in from the Kirby repo - see here):

<?php

$finder = PhpCsFixer\Finder::create()
	->exclude('dependencies')
	->exclude('panel/node_modules')
	->in(__DIR__);

$config = new PhpCsFixer\Config();
return $config
	->setRules([
		'@PSR12' => true,
		'align_multiline_comment' => ['comment_type' => 'phpdocs_like'],
		'array_indentation' => true,
		'array_syntax' => ['syntax' => 'short'],
		'cast_spaces' => ['space' => 'none'],
		// 'class_keyword_remove' => true, // replaces static::class with 'static' (won't work)
		'combine_consecutive_issets' => true,
		'combine_consecutive_unsets' => true,
		'combine_nested_dirname' => true,
		'concat_space' => ['spacing' => 'one'],
		'declare_equal_normalize' => ['space' => 'single'],
		'dir_constant' => true,
		'function_typehint_space' => true,
		'include' => true,
		'logical_operators' => true,
		'lowercase_cast' => true,
		'lowercase_static_reference' => true,
		'magic_constant_casing' => true,
		'magic_method_casing' => true,
		'method_chaining_indentation' => true,
		'modernize_types_casting' => true,
		'multiline_comment_opening_closing' => true,
		'native_function_casing' => true,
		'native_function_type_declaration_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_leading_namespace_whitespace' => true,
		'no_mixed_echo_print' => ['use' => 'echo'],
		'no_unneeded_control_parentheses' => true,
		'no_unused_imports' => true,
		'no_useless_return' => true,
		'ordered_imports' => ['sort_algorithm' => 'alpha'],
		// 'phpdoc_add_missing_param_annotation' => ['only_untyped' => false], // adds params in the wrong order
		'phpdoc_align' => ['align' => 'left'],
		'phpdoc_indent' => true,
		'phpdoc_scalar' => true,
		'phpdoc_trim' => true,
		'short_scalar_cast' => true,
		'single_line_comment_style' => true,
		'single_quote' => true,
		'ternary_to_null_coalescing' => true,
		'whitespace_after_comma_in_array' => true
	])
	->setRiskyAllowed(true)
	->setIndent("\t")
	->setFinder($finder);

Note, I found this which seems like it might be related: https://stackoverflow.com/a/50908446/1944

After some great support on the project gitter page: https://gitter.im/PHP-CS-Fixer/Lobby, it turns out the issue was that the way I was calling things on the command line was overwriting the path information in my config file.

A clue was the CLI message that read Paths from configuration file have been overridden by paths provided as command arguments.

My original command was...

php php-cs-fixer fix /path/to/project/folder --config /path/to/config/file/.php_cs.dist

Two options that should have been used:

  1. Skip the /path/to/project/folder Correct command = php php-cs-fixer fix --config /path/to/config/file/.php_cs.dist. According to the devs, this could have a drawback in that one may not be able to run the tool with sub paths of the root project.

  2. Add a -path-mode=intersection flag to the CLI statement to make things play nice with each other. Correct command = php php-cs-fixer fix /path/to/project/folder --config /path/to/config/file/.php_cs.dist --path-mode=intersection

Another thing to note:

If I enable the HTML formatting setting, then fix and format operations fail on on files that contain HTML. However, the diff operation works fine and reports the changes I would expect. Here are two screenshots to illustrate:

Fix this file:
2022-10-23_04

Diff (there are no complaints here about configuration file paths being overridden):
2022-10-23_05

it's a bug, when your file content ends with <?php Sniopet('footer')?>, i remove the last closed tag ?>.
fixed fc7803c

and the fix command output directly from php-cs-fixer, no matter formatHtml option true or false,

Thank you for this - it seems to work better now.

There are still a couple of problems I have found:

  1. Formatting still doesn't work. I still see the following error:

2022-10-23_01

  1. If I set VS Code's "editor.formatOnSave": true then this extension doesn't fire - nothing happens. If I set to false it works again.

I think I found part of the problem with the formatter. I have Intelephense set as the default formatter. If I change the default to be junstyle.php-cs-fixer then your formatter works for most files, and format on save also works.

These are my workspace settings:

{
	"editor.formatOnSave": true,
	"php-cs-fixer.allowRisky": true,
	"php-cs-fixer.formatHtml": true,
	"php-cs-fixer.onsave": true,
	"[php]": {
		"editor.defaultFormatter": "junstyle.php-cs-fixer"
	},
}

However, formatting HTML does not seem to work at all. Here's a video to show what I mean:

https://youtu.be/1KEGr6eDdZE