trailing_comma_in_multiline.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. ====================================
  2. Rule ``trailing_comma_in_multiline``
  3. ====================================
  4. Arguments lists, array destructuring lists, arrays that are multi-line,
  5. ``match``-lines and parameters lists 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', 'array_destructuring', '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. - `@PER <./../../ruleSets/PER.rst>`_ with config:
  77. ``['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]``
  78. - `@PER-CS <./../../ruleSets/PER-CS.rst>`_ with config:
  79. ``['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]``
  80. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:
  81. ``['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]``
  82. - `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ with config:
  83. ``['after_heredoc' => true]``
  84. - `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_ with config:
  85. ``['after_heredoc' => true]``
  86. - `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ with config:
  87. ``['after_heredoc' => true]``
  88. - `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ with config:
  89. ``['after_heredoc' => true]``
  90. - `@PHP82Migration <./../../ruleSets/PHP82Migration.rst>`_ with config:
  91. ``['after_heredoc' => true]``
  92. - `@PHP83Migration <./../../ruleSets/PHP83Migration.rst>`_ with config:
  93. ``['after_heredoc' => true]``
  94. - `@PHP84Migration <./../../ruleSets/PHP84Migration.rst>`_ with config:
  95. ``['after_heredoc' => true]``
  96. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
  97. ``['after_heredoc' => true, 'elements' => ['array_destructuring', 'arrays']]``
  98. - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
  99. ``['after_heredoc' => true, 'elements' => ['array_destructuring', 'arrays', 'match', 'parameters']]``
  100. References
  101. ----------
  102. - Fixer class: `PhpCsFixer\\Fixer\\ControlStructure\\TrailingCommaInMultilineFixer <./../../../src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php>`_
  103. - Test class: `PhpCsFixer\\Tests\\Fixer\\ControlStructure\\TrailingCommaInMultilineFixerTest <./../../../tests/Fixer/ControlStructure/TrailingCommaInMultilineFixerTest.php>`_
  104. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.