Skip to content

Rule F011

Avoid using backslash \ for line continuation; prefer proper chaining for clarity

Severity

🟢 LOW — Minor performance impact.

PySpark version

Compatible with PySpark 1.0 and later.

Information

Using backslashes to continue lines can make code harder to read and maintain:

  • Reduces readability of complex transformations
  • Harder to add or remove steps without breaking the backslash chain
  • Less visually clear which operations are applied to the DataFrame

Best practices

  • Use parentheses and proper chaining to write transformations clearly
  • Each transformation should be on its own line inside parentheses

Example

Bad:

df = df.filter(F.col('event') == 'executing')\
    .filter(F.col('has_tests') == True)\
    .drop('has_tests')

Good:

df = (
    df
    .filter(F.col('event') == 'executing')
    .filter(F.col('has_tests') == True)
    .drop('has_tests')
)

Rule of thumb: Avoid \ line continuations; use parentheses and proper chaining for clearer, maintainable DataFrame transformations.