Php-cs-fixer: Accept any number of space superior at 2 for indentation

Created on 17 May 2018  Â·  7Comments  Â·  Source: FriendsOfPHP/PHP-CS-Fixer

Hello,

I work on project that have 2 or 4 spaces for indentation and I wonder if it's possible to set up php-cs-fixer to accept any number of space superior at 2 for indentation ?
If yes how ? If no is it possible to add it please ?

Thanks !

kinquestion

Most helpful comment

Some rules will detect the indentation and try to preserve it or apply it to the code these modify.
The ones that don't detect the indent use the configured indentation.
While this is indeed a limitation that might not be very practical in your use case it is done for a reason.
The tool is designed to change code into _one_ style that can be defined through configuration, it is not meant to fix to multiple/dynamic styles.
I would advice:

  • reconsider using one style in the project
  • if not possible; make two configuration files; one for each style for each set of files
  • if not practical either I would remove the indentation fixer for the configuration

All 7 comments

Hi @Paviluf ,

You can configure the indentation through the configuration you use for the fixer. Therefore you need a configuration file. Details about this file can be found in the README, for the indentation search for ->setIndent to find the relevant details.
Mixing two types of indentation is not something the fixer supports, currently you can use 4-spaces or tabs, I'm not sure if 2-spaces is (still) supported.

Thank you but it's not really practical. It will be great if we can have a setting to detect the indentation and format the code accordingly.

Some rules will detect the indentation and try to preserve it or apply it to the code these modify.
The ones that don't detect the indent use the configured indentation.
While this is indeed a limitation that might not be very practical in your use case it is done for a reason.
The tool is designed to change code into _one_ style that can be defined through configuration, it is not meant to fix to multiple/dynamic styles.
I would advice:

  • reconsider using one style in the project
  • if not possible; make two configuration files; one for each style for each set of files
  • if not practical either I would remove the indentation fixer for the configuration

To remove the indentation fixer I just need to remove setIndent() from the config ?

the rule is called indentation_type, either remove it from you config or if it is imported through a set you can disable it later on using indentation_type => false in the ->setRules([ part of your configuration file

OK thank you !

Closing as question had been resolved

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kcloze picture kcloze  Â·  3Comments

fisharebest picture fisharebest  Â·  3Comments

datenmeister picture datenmeister  Â·  3Comments

aidantwoods picture aidantwoods  Â·  3Comments

OskarStark picture OskarStark  Â·  3Comments