no_extra_blank_lines.rst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. =============================
  2. Rule ``no_extra_blank_lines``
  3. =============================
  4. Removes extra blank lines and/or blank lines following configuration.
  5. Configuration
  6. -------------
  7. ``tokens``
  8. ~~~~~~~~~~
  9. List of tokens to fix.
  10. Allowed values: a subset of ``['attribute', 'break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait']``
  11. Default value: ``['extra']``
  12. Examples
  13. --------
  14. Example #1
  15. ~~~~~~~~~~
  16. *Default* configuration.
  17. .. code-block:: diff
  18. --- Original
  19. +++ New
  20. <?php
  21. $foo = array("foo");
  22. -
  23. $bar = "bar";
  24. Example #2
  25. ~~~~~~~~~~
  26. With configuration: ``['tokens' => ['break']]``.
  27. .. code-block:: diff
  28. --- Original
  29. +++ New
  30. <?php
  31. switch ($foo) {
  32. case 41:
  33. echo "foo";
  34. break;
  35. -
  36. case 42:
  37. break;
  38. }
  39. Example #3
  40. ~~~~~~~~~~
  41. With configuration: ``['tokens' => ['continue']]``.
  42. .. code-block:: diff
  43. --- Original
  44. +++ New
  45. <?php
  46. for ($i = 0; $i < 9000; ++$i) {
  47. if (true) {
  48. continue;
  49. -
  50. }
  51. }
  52. Example #4
  53. ~~~~~~~~~~
  54. With configuration: ``['tokens' => ['curly_brace_block']]``.
  55. .. code-block:: diff
  56. --- Original
  57. +++ New
  58. <?php
  59. for ($i = 0; $i < 9000; ++$i) {
  60. -
  61. echo $i;
  62. -
  63. }
  64. Example #5
  65. ~~~~~~~~~~
  66. With configuration: ``['tokens' => ['extra']]``.
  67. .. code-block:: diff
  68. --- Original
  69. +++ New
  70. <?php
  71. $foo = array("foo");
  72. -
  73. $bar = "bar";
  74. Example #6
  75. ~~~~~~~~~~
  76. With configuration: ``['tokens' => ['parenthesis_brace_block']]``.
  77. .. code-block:: diff
  78. --- Original
  79. +++ New
  80. <?php
  81. $foo = array(
  82. -
  83. "foo"
  84. -
  85. );
  86. Example #7
  87. ~~~~~~~~~~
  88. With configuration: ``['tokens' => ['return']]``.
  89. .. code-block:: diff
  90. --- Original
  91. +++ New
  92. <?php
  93. function foo($bar)
  94. {
  95. return $bar;
  96. -
  97. }
  98. Example #8
  99. ~~~~~~~~~~
  100. With configuration: ``['tokens' => ['square_brace_block']]``.
  101. .. code-block:: diff
  102. --- Original
  103. +++ New
  104. <?php
  105. $foo = [
  106. -
  107. "foo"
  108. -
  109. ];
  110. Example #9
  111. ~~~~~~~~~~
  112. With configuration: ``['tokens' => ['throw']]``.
  113. .. code-block:: diff
  114. --- Original
  115. +++ New
  116. <?php
  117. function foo($bar)
  118. {
  119. throw new \Exception("Hello!");
  120. -
  121. }
  122. Example #10
  123. ~~~~~~~~~~~
  124. With configuration: ``['tokens' => ['use']]``.
  125. .. code-block:: diff
  126. --- Original
  127. +++ New
  128. <?php
  129. namespace Foo;
  130. use Bar\Baz;
  131. -
  132. use Baz\Bar;
  133. class Bar
  134. {
  135. }
  136. Example #11
  137. ~~~~~~~~~~~
  138. With configuration: ``['tokens' => ['switch', 'case', 'default']]``.
  139. .. code-block:: diff
  140. --- Original
  141. +++ New
  142. <?php
  143. switch($a) {
  144. -
  145. case 1:
  146. -
  147. default:
  148. -
  149. echo 3;
  150. }
  151. Rule sets
  152. ---------
  153. The rule is part of the following rule sets:
  154. - `@PER <./../../ruleSets/PER.rst>`_ with config:
  155. ``['tokens' => ['use']]``
  156. - `@PER-CS <./../../ruleSets/PER-CS.rst>`_ with config:
  157. ``['tokens' => ['use']]``
  158. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_ with config:
  159. ``['tokens' => ['use']]``
  160. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:
  161. ``['tokens' => ['use']]``
  162. - `@PSR12 <./../../ruleSets/PSR12.rst>`_ with config:
  163. ``['tokens' => ['use']]``
  164. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
  165. ``['tokens' => ['attribute', 'break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use']]``
  166. - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
  167. ``['tokens' => ['attribute', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'switch', 'throw', 'use']]``
  168. References
  169. ----------
  170. - Fixer class: `PhpCsFixer\\Fixer\\Whitespace\\NoExtraBlankLinesFixer <./../../../src/Fixer/Whitespace/NoExtraBlankLinesFixer.php>`_
  171. - Test class: `PhpCsFixer\\Tests\\Fixer\\Whitespace\\NoExtraBlankLinesFixerTest <./../../../tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php>`_
  172. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.