Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix on save does not respect finder #179

Open
cartok opened this issue Jul 4, 2022 · 8 comments
Open

Fix on save does not respect finder #179

cartok opened this issue Jul 4, 2022 · 8 comments

Comments

@cartok
Copy link

cartok commented Jul 4, 2022

Looks like fix on save does not respect the finder object.
I've created a finder with in('/foo/bar'), created a file /baz.php and it gets auto fixed on save, but it should not. This can make the plugin unusable, can someone confirm this?

@cartok
Copy link
Author

cartok commented Jul 4, 2022

I guess it's because the plugin has an extra setting (exclude). I think it should rather be include but why have it at all?

@cartok
Copy link
Author

cartok commented Jul 4, 2022

I also tried to use a negated glob (ext glob is enabled by default in anymatch) and a negative lookahead regex but without success.

@cartok
Copy link
Author

cartok commented Jul 4, 2022

Tried it again with:

"php-cs-fixer.exclude": [
  "**/src/**",
  "!(**/src/foo/bar/**)",
]

Which seems to work files outside of src/foo/bar get ignored on save but inside still gets fixed, but it's not a nice solution I think.

@junstyle
Copy link
Owner

junstyle commented Jul 5, 2022

when use this extension to fix a file, it create a tmp file and then pass to php-cs-fixer, not the current edited file, maybe the config in is useless.

 "php-cs-fixer.pathMode": {
          "type": "string",
          "enum": [
            "override",
            "intersection"
          ],
          "default": "override",
          "description": "--path-mode can be override or intersection, intersection only works on explorer context menu action, not works for current focused file. detail see:https://github.com/FriendsOfPHP/PHP-CS-Fixer#usage"
        },

and see this extension's config: pathMode, this option always override when you fix the current edited file. so the config in
has been overridden, if you open the vscode's Developer Tools, you will see

Paths from configuration file have been overridden by paths provided as command arguments.

if you want the config in to work, you can use the command php-cs-fixer.fix, or context menu -> php-cs-fixer.fix

so i think the best way is using the option: php-cs-fixer.exclude, if you fix the current edited file.

@cartok
Copy link
Author

cartok commented Jul 6, 2022

Thanks, so ok I get it, you documented that it pathMode=intersection is not possible atm. Can't it get improved? I imagine that it would be good if by default mode would be intersection and the config would get used (including the rules). I tried it with intersection and get Cannot create intersection with not-fully defined Finder in configuration file., see:
image
The screenshot also shows that --config is not passed.

My finder configuration is:

$fullPath = getcwd() . '/app';
$finder = PhpCsFixer\Finder::create()
   ->in($fullPath)
   ->files()
   ->name(['*.php', '*.phtml'])
;

@cartok
Copy link
Author

cartok commented Jul 6, 2022

To the topic about the exclude option: What about adding an include option aswell?

@cartok
Copy link
Author

cartok commented Jul 6, 2022

Why the temp file?

@junstyle
Copy link
Owner

junstyle commented Jul 6, 2022

because use tmp file, so the config in can't match the tmp file path generally.

why i use tmp file?
this extension not only provide to format a whole file, but also format partial codes, such as selected range formatting...
and if you want to format an unsaved file, and not change the behavior to save first, need a temp file to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants