trailing_comma_in_multiline.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ====================================
  2. Rule ``trailing_comma_in_multiline``
  3. ====================================
  4. Multi-line arrays, arguments list, parameters list and ``match`` expressions
  5. must have a trailing comma.
  6. Configuration
  7. -------------
  8. ``after_heredoc``
  9. ~~~~~~~~~~~~~~~~~
  10. Whether a trailing comma should also be placed after heredoc end.
  11. Allowed types: ``bool``
  12. Default value: ``false``
  13. ``elements``
  14. ~~~~~~~~~~~~
  15. Where to fix multiline trailing comma (PHP >= 8.0 for ``parameters`` and
  16. ``match``).
  17. Allowed values: a subset of ``['arguments', 'arrays', 'match', 'parameters']``
  18. Default value: ``['arrays']``
  19. Examples
  20. --------
  21. Example #1
  22. ~~~~~~~~~~
  23. *Default* configuration.
  24. .. code-block:: diff
  25. --- Original
  26. +++ New
  27. <?php
  28. array(
  29. 1,
  30. - 2
  31. + 2,
  32. );
  33. Example #2
  34. ~~~~~~~~~~
  35. With configuration: ``['after_heredoc' => true]``.
  36. .. code-block:: diff
  37. --- Original
  38. +++ New
  39. <?php
  40. $x = [
  41. 'foo',
  42. <<<EOD
  43. bar
  44. - EOD
  45. + EOD,
  46. ];
  47. Example #3
  48. ~~~~~~~~~~
  49. With configuration: ``['elements' => ['arguments']]``.
  50. .. code-block:: diff
  51. --- Original
  52. +++ New
  53. <?php
  54. foo(
  55. 1,
  56. - 2
  57. + 2,
  58. );
  59. Example #4
  60. ~~~~~~~~~~
  61. With configuration: ``['elements' => ['parameters']]``.
  62. .. code-block:: diff
  63. --- Original
  64. +++ New
  65. <?php
  66. function foo(
  67. $x,
  68. - $y
  69. + $y,
  70. )
  71. {
  72. }
  73. Rule sets
  74. ---------
  75. The rule is part of the following rule sets:
  76. - `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ with config:
  77. ``['after_heredoc' => true]``
  78. - `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_ with config:
  79. ``['after_heredoc' => true]``
  80. - `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ with config:
  81. ``['after_heredoc' => true]``
  82. - `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ with config:
  83. ``['after_heredoc' => true]``
  84. - `@PHP82Migration <./../../ruleSets/PHP82Migration.rst>`_ with config:
  85. ``['after_heredoc' => true]``
  86. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  87. - `@Symfony <./../../ruleSets/Symfony.rst>`_