single_line_comment_style.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ==================================
  2. Rule ``single_line_comment_style``
  3. ==================================
  4. Single-line comments and multi-line comments with only one line of actual
  5. content should use the ``//`` syntax.
  6. Configuration
  7. -------------
  8. ``comment_types``
  9. ~~~~~~~~~~~~~~~~~
  10. List of comment types to fix.
  11. Allowed values: a subset of ``['asterisk', 'hash']``
  12. Default value: ``['asterisk', 'hash']``
  13. Examples
  14. --------
  15. Example #1
  16. ~~~~~~~~~~
  17. *Default* configuration.
  18. .. code-block:: diff
  19. --- Original
  20. +++ New
  21. <?php
  22. -/* asterisk comment */
  23. +// asterisk comment
  24. $a = 1;
  25. -# hash comment
  26. +// hash comment
  27. $b = 2;
  28. /*
  29. * multi-line
  30. * comment
  31. */
  32. $c = 3;
  33. Example #2
  34. ~~~~~~~~~~
  35. With configuration: ``['comment_types' => ['asterisk']]``.
  36. .. code-block:: diff
  37. --- Original
  38. +++ New
  39. <?php
  40. -/* first comment */
  41. +// first comment
  42. $a = 1;
  43. -/*
  44. - * second comment
  45. - */
  46. +// second comment
  47. $b = 2;
  48. /*
  49. * third
  50. * comment
  51. */
  52. $c = 3;
  53. Example #3
  54. ~~~~~~~~~~
  55. With configuration: ``['comment_types' => ['hash']]``.
  56. .. code-block:: diff
  57. --- Original
  58. +++ New
  59. -<?php # comment
  60. +<?php // comment
  61. Rule sets
  62. ---------
  63. The rule is part of the following rule sets:
  64. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  65. - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
  66. ``['comment_types' => ['hash']]``
  67. References
  68. ----------
  69. - Fixer class: `PhpCsFixer\\Fixer\\Comment\\SingleLineCommentStyleFixer <./../../../src/Fixer/Comment/SingleLineCommentStyleFixer.php>`_
  70. - Test class: `PhpCsFixer\\Tests\\Fixer\\Comment\\SingleLineCommentStyleFixerTest <./../../../tests/Fixer/Comment/SingleLineCommentStyleFixerTest.php>`_
  71. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.