drupol / drupal-conventions

Check (and fix) your code against Drupal's code conventions and coding standard.
MIT License
24 stars 1 forks source link

Support: Fix specific style rule in a specific file. #1

Open donquixote opened 5 years ago

donquixote commented 5 years ago

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.

drupol commented 5 years ago

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