no_trailing_comma_in_singleline.rst 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ========================================
  2. Rule ``no_trailing_comma_in_singleline``
  3. ========================================
  4. If a list of values separated by a comma is contained on a single line, then the
  5. last item MUST NOT have a trailing comma.
  6. Configuration
  7. -------------
  8. ``elements``
  9. ~~~~~~~~~~~~
  10. Which elements to fix.
  11. Allowed values: a subset of ``['arguments', 'array', 'array_destructuring', 'group_import']``
  12. Default value: ``['arguments', 'array_destructuring', 'array', 'group_import']``
  13. Examples
  14. --------
  15. Example #1
  16. ~~~~~~~~~~
  17. *Default* configuration.
  18. .. code-block:: diff
  19. --- Original
  20. +++ New
  21. <?php
  22. -foo($a,);
  23. -$foo = array(1,);
  24. -[$foo, $bar,] = $array;
  25. -use a\{ClassA, ClassB,};
  26. +foo($a);
  27. +$foo = array(1);
  28. +[$foo, $bar] = $array;
  29. +use a\{ClassA, ClassB};
  30. Example #2
  31. ~~~~~~~~~~
  32. With configuration: ``['elements' => ['array_destructuring']]``.
  33. .. code-block:: diff
  34. --- Original
  35. +++ New
  36. <?php
  37. foo($a,);
  38. -[$foo, $bar,] = $array;
  39. +[$foo, $bar] = $array;
  40. Rule sets
  41. ---------
  42. The rule is part of the following rule sets:
  43. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  44. - `@Symfony <./../../ruleSets/Symfony.rst>`_
  45. References
  46. ----------
  47. - Fixer class: `PhpCsFixer\\Fixer\\Basic\\NoTrailingCommaInSinglelineFixer <./../../../src/Fixer/Basic/NoTrailingCommaInSinglelineFixer.php>`_
  48. - Test class: `PhpCsFixer\\Tests\\Fixer\\Basic\\NoTrailingCommaInSinglelineFixerTest <./../../../tests/Fixer/Basic/NoTrailingCommaInSinglelineFixerTest.php>`_
  49. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.