drupal-conventions icon indicating copy to clipboard operation
drupal-conventions copied to clipboard

Support: Fix specific style rule in a specific file.

Open donquixote opened this issue 6 years ago • 1 comments

Hello Pol! My task is simple (I think): Fix specific style rules in specific files. E.g. I have one file that has a lot of code style problems, but all I want to fix atm is the indentation level. How would I do this? Where would I even start?

In the past I used PhpStorm for this, but I want a cli tool. So I thought php-cs-fixer would do the job, but somehow I need to tell it about Drupal coding standards, and that I only want to fix indentation at this point, based on the 2 spaces and whichever special rules apply in Drupal, e.g. correct indentation for switch() or for multi-line conditional statements.

In the end I want to fix everything, but I want a separate git commit with indentation only, this should be easier to review with sth like --word-diff-regex.

I suppose this library can give me that, but I need the baby steps :) This would be useful to add to the README also.

donquixote avatar Feb 02 '19 00:02 donquixote

Hi @donquixote ,

Fix one issue at a time is possible with php-cs-fixer or phpcs.

Ex:

php-cs-fixer fix --rules="[TheDirectiveToFixTheSpecificThing]" src/CustomCode.php

The issue with that is that you would have to know which directive is doing what... and there are many in php-cs-fixer/phpcs.

Could you explain a bit what would be the usecase of fixing only one issue at a time ?

Thx

drupol avatar Feb 18 '19 15:02 drupol