Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce FullyMultilineFixer for ControlStructure, Array & Functions. #7813

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions doc/ruleSets/PER-CS2.0.rst
Expand Up @@ -19,4 +19,8 @@ Rules
``['closure_fn_spacing' => 'none']``

- `method_argument_space <./../rules/function_notation/method_argument_space.rst>`_
- `single_expression_per_line <./../rules/control_structure/single_expression_per_line.rst>`_ with config:

``['elements' => ['arguments', 'arrays', 'case', 'control_structures', 'match', 'parameters']]``

- `single_line_empty_body <./../rules/basic/single_line_empty_body.rst>`_
4 changes: 4 additions & 0 deletions doc/ruleSets/PSR12.rst
Expand Up @@ -41,6 +41,10 @@ Rules

- `return_type_declaration <./../rules/function_notation/return_type_declaration.rst>`_
- `short_scalar_cast <./../rules/cast_notation/short_scalar_cast.rst>`_
- `single_expression_per_line <./../rules/control_structure/single_expression_per_line.rst>`_ with config:

``['elements' => ['arguments', 'case', 'control_structures', 'match', 'parameters']]``

- `single_import_per_statement <./../rules/import/single_import_per_statement.rst>`_ with config:

``['group_to_single_imports' => false]``
Expand Down
1 change: 1 addition & 0 deletions doc/ruleSets/Symfony.rst
Expand Up @@ -183,4 +183,5 @@ Rules
Disabled rules
--------------

- `single_expression_per_line <./../rules/control_structure/single_expression_per_line.rst>`_
VincentLanglet marked this conversation as resolved.
Show resolved Hide resolved
- `single_line_empty_body <./../rules/basic/single_line_empty_body.rst>`_
158 changes: 158 additions & 0 deletions doc/rules/control_structure/single_expression_per_line.rst
@@ -0,0 +1,158 @@
===================================
Rule ``single_expression_per_line``
===================================

Multi-line arrays, arguments list, parameters list, control structures,
``switch`` cases and ``match`` expressions should have one element by line.
VincentLanglet marked this conversation as resolved.
Show resolved Hide resolved

Configuration
-------------

``elements``
~~~~~~~~~~~~

Which expression must have one element by line.

Allowed values: a subset of ``['arguments', 'arrays', 'case', 'control_structures', 'match', 'parameters']``

Default value: ``['arrays', 'arguments', 'parameters', 'control_structures', 'case', 'match']``

Examples
--------

Example #1
~~~~~~~~~~

*Default* configuration.

.. code-block:: diff

--- Original
+++ New
<?php
-array(1,
- 2);
+array(
+1,
+ 2
+);

Example #2
~~~~~~~~~~

With configuration: ``['elements' => ['arguments']]``.

.. code-block:: diff

--- Original
+++ New
<?php
-foo(1,
- 2);
+foo(
+1,
+ 2
+);

Example #3
~~~~~~~~~~

With configuration: ``['elements' => ['control_structures']]``.

.. code-block:: diff

--- Original
+++ New
<?php
-if ($a
- && $b) {};
+if (
+$a
+ && $b
+) {};

Example #4
~~~~~~~~~~

With configuration: ``['elements' => ['case']]``.

.. code-block:: diff

--- Original
+++ New
<?php
switch ($foo) {
- case 0: case 1:
+ case 0:
+case 1:
return null;
};

Example #5
~~~~~~~~~~

With configuration: ``['elements' => ['parameters']]``.

.. code-block:: diff

--- Original
+++ New
<?php
-function foo($x,
- $y)
+function foo(
+$x,
+ $y
+)
{
}

Example #6
~~~~~~~~~~

With configuration: ``['elements' => ['match']]``.

.. code-block:: diff

--- Original
+++ New
<?php
match($x) {
- 1 => 1, 2 => 2
+ 1 => 1,
+2 => 2
};

Rule sets
---------

The rule is part of the following rule sets:

- `@PER <./../../ruleSets/PER.rst>`_ with config:

``['elements' => ['arguments', 'arrays', 'case', 'control_structures', 'match', 'parameters']]``

- `@PER-CS <./../../ruleSets/PER-CS.rst>`_ with config:

``['elements' => ['arguments', 'arrays', 'case', 'control_structures', 'match', 'parameters']]``

- `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_ with config:

``['elements' => ['arguments', 'case', 'control_structures', 'match', 'parameters']]``

- `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:

``['elements' => ['arguments', 'arrays', 'case', 'control_structures', 'match', 'parameters']]``

- `@PSR12 <./../../ruleSets/PSR12.rst>`_ with config:

``['elements' => ['arguments', 'case', 'control_structures', 'match', 'parameters']]``


References
----------

- Fixer class: `PhpCsFixer\\Fixer\\ControlStructure\\SingleExpressionPerLineFixer <./../../../src/Fixer/ControlStructure/SingleExpressionPerLineFixer.php>`_
- Test class: `PhpCsFixer\\Tests\\Fixer\\ControlStructure\\SingleExpressionPerLineFixerTest <./../../../tests/Fixer/ControlStructure/SingleExpressionPerLineFixerTest.php>`_

The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.
3 changes: 3 additions & 0 deletions doc/rules/index.rst
Expand Up @@ -321,6 +321,9 @@ Control Structure
- `simplified_if_return <./control_structure/simplified_if_return.rst>`_

Simplify ``if`` control structures that return the boolean result of their condition.
- `single_expression_per_line <./control_structure/single_expression_per_line.rst>`_

Multi-line arrays, arguments list, parameters list, control structures, ``switch`` cases and ``match`` expressions should have one element by line.
- `switch_case_semicolon_to_colon <./control_structure/switch_case_semicolon_to_colon.rst>`_

A case should be followed by a colon and not a semicolon.
Expand Down