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:

'abc'

# 2:

'abc' + 'def'

# 3:

f'abc'

INVALID Code Examples

# 1:

'ab' 'cd'

Autofix:

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

# 2:

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

Autofix:

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

# 3:

f'ab' f'cd'

Autofix:

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

# 4:

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

Autofix:

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