Skip to content

Rule E221 and Rule E222 does not catch error in if condition  #13886

@samratashok87

Description

@samratashok87

Rule E221 ([multiple-spaces-before-operator] and Rule E222 ([multiple-spaces-after-operator) work for normal assignment operators.
But If multiples spaces are present in if condition either before or after '==' operator Ruff does not catch.

#!/usr/bin/env python3
a  =  1
if a  ==  1:
    print(a)

In the above code Ruff flags the line a = 1 as error as it contains more space before and after operator where as it does not catch the error on the if condition.

/home/ashok/.local/bin/ruff check hello_world.py                                                                                    

hello_world.py:6:2: E221 [*] Multiple spaces before operator
  |
5 | print('Hello World')
6 | a  =  1
  |  ^^ E221
7 | if a  ==  1:
8 |     print(a)
  |
  = help: Replace with single space

hello_world.py:6:5: E222 [*] Multiple spaces after operator
  |
5 | print('Hello World')
6 | a  =  1
  |     ^^ E222
7 | if a  ==  1:
8 |     print(a)
  |
  = help: Replace with single space

This issue is caught by flake8.

Ruff.toml

target-version = "py310"
[lint]
preview = true
extend-select = [
  "E",
  "PL",  # pylint
  "UP",  # pyupgrade
  "D",   # pydocstyle
  "C4",
  "SIM",
]

ruff version : 0.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions