Php-cs-fixer: how to exclude a file

Created on 10 Feb 2016  路  12Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

README.md should include some example how to exclude file.

the examples show how to exclude directory, and that does not work for files, and it's not very obvious to know that 'exclude' means just directories.

Most helpful comment

@GrahamCampbell the ticket is about asking to improve php-cs-fixer doc not about actual problem.
and even if your only response is "go see symfony docs" it should include direct link to the doc.

ps: the cache issue is solved, re-run with php-cs-fixer.phar 1.11.1 is okay

All 12 comments

i.e i wish to exclude some file that prevents the process to run, and no cache file is written due that, causing subsequent runs to be slow

Files that were not fixed due to internal error:
   1) src/color_smartytmpl.php

See symfony's finder docs.

Files that were not fixed due to internal error:

It would be useful for us to know why that was happening though so we can fix it.

@GrahamCampbell the ticket is about asking to improve php-cs-fixer doc not about actual problem.
and even if your only response is "go see symfony docs" it should include direct link to the doc.

ps: the cache issue is solved, re-run with php-cs-fixer.phar 1.11.1 is okay

regarding internal error, i ran with -vvv but that did not produce anything useful to understand what's wrong with the file, and looking at the file i do not see what could be wrong with it.

Unfortunately there is no way to get more info about the internal error at the moment, unless you work with the code of the fixer itself of cause.
Could you provide a minimal set of code on which the error occurs? It would help us debugging the issue. As @GrahamCampbell stated it would also help to know which fixers you are running.
About the blacklisting of files and adding more details to the doc; sounds like a good idea! Did you figure it out? Then maybe you could describe how to do it, maybe even in a PR for the docs? Otherwise I'm happy to pick up your notes and PR it :)

Yeah, it would be very handy to have a way (or document one, if it exists) to ignore certain .php files. Mostly when the contents are partials with only a few lines of inline PHP.

You can easily end up with this:
<li <?php if ($cur == 'news') { echo 'class="active"'; } ?>><a href="news">News</a></li>

Becoming this:

                       <li <?php if ($cur == 'news') {
   echo 'class="active"';
} ?>><a href="news">News</a></li>

You can configure your finder in your .php_cs file, eg:
https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/1.11/.php_cs#L25
https://github.com/symfony/symfony/blob/master/.php_cs#L19

As the example is already inside this repository I don't see big need to add it to readme file as well, but if you think that would be worth please feel free to create PR with that ;)

also, i'm looking for sample how to process *.php only in specific dir, for example project root:

    ->in(__DIR__)
    ->name('*.php')

this went to subdirs!

->depth(0) works, thansk

Closed due to merge of #1870

Was this page helpful?
0 / 5 - 0 ratings