.. _UsePlusForStringConcatRule:

==========================
UsePlusForStringConcatRule
==========================

Enforces use of explicit string concatenations using a ``+`` sign where an implicit concatenation is detected.
An implicit concatenation is a tuple or a call with multiple strings and a missing comma, e.g: ``("a" "b")``, and may have unexpected results.

-------
Message
-------
Implicit string concatenation detected, please add '+' to be explicit. E.g. a tuple or a call ("a" "b") with a missing comma results in multiple strings being concatenated as one string and causes unexpected behaviour.

----------------
Has Autofix: Yes
----------------

-------------------
VALID Code Examples
-------------------

# 1:







.. code-block:: python

            'abc'




# 2:







.. code-block:: python

            'abc' + 'def'




# 3:







.. code-block:: python

            f'abc'




---------------------
INVALID Code Examples
---------------------

# 1:







.. code-block:: python

            'ab' 'cd'




Autofix:

.. code-block:: python

    --- 
    +++ 
    @@ -1 +1 @@
    -'ab' 'cd'
    +('ab' + 'cd')

# 2:







.. code-block:: python

            'ab' 'cd' 'ef' 'gh'




Autofix:

.. code-block:: python

    --- 
    +++ 
    @@ -1 +1 @@
    -'ab' 'cd' 'ef' 'gh'
    +('ab' + 'cd' + 'ef' + 'gh')

# 3:







.. code-block:: python

            f'ab' f'cd'




Autofix:

.. code-block:: python

    --- 
    +++ 
    @@ -1 +1 @@
    -f'ab' f'cd'
    +(f'ab' + f'cd')

.. container:: toggle


    # 4:







    .. code-block:: python


        (
            # comment
            'ab'  # middle comment
            'cd'  # trailing comment
        )





    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -2,5 +2,5 @@
         (
             # comment
             'ab'  # middle comment
        -    'cd'  # trailing comment
        +    + 'cd'  # trailing comment
         )

