no_extra_blank_lines.rst 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 ``['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. @@ -2,5 +2,4 @@
  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. @@ -4,7 +4,6 @@
  31. case 41:
  32. echo "foo";
  33. break;
  34. -
  35. case 42:
  36. break;
  37. }
  38. Example #3
  39. ~~~~~~~~~~
  40. With configuration: ``['tokens' => ['continue']]``.
  41. .. code-block:: diff
  42. --- Original
  43. +++ New
  44. @@ -3,6 +3,5 @@
  45. for ($i = 0; $i < 9000; ++$i) {
  46. if (true) {
  47. continue;
  48. -
  49. }
  50. }
  51. Example #4
  52. ~~~~~~~~~~
  53. With configuration: ``['tokens' => ['curly_brace_block']]``.
  54. .. code-block:: diff
  55. --- Original
  56. +++ New
  57. @@ -1,7 +1,5 @@
  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. @@ -2,5 +2,4 @@
  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. @@ -1,7 +1,5 @@
  81. <?php
  82. $foo = array(
  83. -
  84. "foo"
  85. -
  86. );
  87. Example #7
  88. ~~~~~~~~~~
  89. With configuration: ``['tokens' => ['return']]``.
  90. .. code-block:: diff
  91. --- Original
  92. +++ New
  93. @@ -3,5 +3,4 @@
  94. function foo($bar)
  95. {
  96. return $bar;
  97. -
  98. }
  99. Example #8
  100. ~~~~~~~~~~
  101. With configuration: ``['tokens' => ['square_brace_block']]``.
  102. .. code-block:: diff
  103. --- Original
  104. +++ New
  105. @@ -1,7 +1,5 @@
  106. <?php
  107. $foo = [
  108. -
  109. "foo"
  110. -
  111. ];
  112. Example #9
  113. ~~~~~~~~~~
  114. With configuration: ``['tokens' => ['throw']]``.
  115. .. code-block:: diff
  116. --- Original
  117. +++ New
  118. @@ -3,5 +3,4 @@
  119. function foo($bar)
  120. {
  121. throw new \Exception("Hello!");
  122. -
  123. }
  124. Example #10
  125. ~~~~~~~~~~~
  126. With configuration: ``['tokens' => ['use']]``.
  127. .. code-block:: diff
  128. --- Original
  129. +++ New
  130. @@ -3,7 +3,6 @@
  131. namespace Foo;
  132. use Bar\Baz;
  133. -
  134. use Baz\Bar;
  135. class Bar
  136. Example #11
  137. ~~~~~~~~~~~
  138. With configuration: ``['tokens' => ['use_trait']]``.
  139. .. code-block:: diff
  140. --- Original
  141. +++ New
  142. @@ -3,6 +3,5 @@
  143. class Foo
  144. {
  145. use Bar;
  146. -
  147. use Baz;
  148. }
  149. Example #12
  150. ~~~~~~~~~~~
  151. With configuration: ``['tokens' => ['switch', 'case', 'default']]``.
  152. .. code-block:: diff
  153. --- Original
  154. +++ New
  155. @@ -1,9 +1,6 @@
  156. <?php
  157. switch($a) {
  158. -
  159. case 1:
  160. -
  161. default:
  162. -
  163. echo 3;
  164. }
  165. Rule sets
  166. ---------
  167. The rule is part of the following rule sets:
  168. @PhpCsFixer
  169. Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``no_extra_blank_lines`` rule with the config below:
  170. ``['tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait']]``
  171. @Symfony
  172. Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``no_extra_blank_lines`` rule with the config below:
  173. ``['tokens' => ['case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait']]``