fterrag/vscode-php-cs-fixer

Blacklist/Whitelist for fix on save for certain paths

Opened this issue · 4 comments

Occasionally I edit files in vendor which then triggers the auto save fix which can be frustrating, as it's usually unintentional. You can temporarily disable the fix on save, but this is fiddly as you have to go into the config every time.

It would be great to be able to configure a whitelist/blacklist of paths to enable triggering fix on save:

{
  "vscode-php-cs-fixer.fixOnSavePaths": {
      "vendor/allow-fix-on-save": true,
      "vendor": false
   }
}

Matches are done in order, first match takes priority. Paths are matched from the workspace root path, so for example when a workspace is opened for C:\Sites\my-project and following the above examples, it would match for:

  • C:\Sites\my-project\vendor\allow-fix-on-save
  • C:\Sites\my-project\vendor
    ...etc

Is this an idea you would be open to adding?

It looks like the extension doesn't generally respect if you set this sort of thing in the config itself either.

For example, our config has:

$finder = \PhpCsFixer\Finder::create()
    ->exclude('vendor')
    ->in(__DIR__.'/[redacted]');

But cs fixer runs on every file regardless of this config.

@probablyup what do you have vscode-php-cs-fixer.config set to?

Maybe a setting to set --path-mode to intersection? See https://cs.symfony.com/doc/usage.html - as far as I understand it that should take into account the config finder rather than over-riding it.

PR for this here:
#18