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

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

Closed
samratashok87 opened this issue Oct 23, 2024 · 1 comment · Fixed by #13890
Closed

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

samratashok87 opened this issue Oct 23, 2024 · 1 comment · Fixed by #13890
Labels
bug Something isn't working help wanted Contributions especially welcome

Comments

@samratashok87
Copy link

samratashok87 commented Oct 23, 2024

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

@MichaReiser MichaReiser added bug Something isn't working help wanted Contributions especially welcome labels Oct 23, 2024
@MichaReiser
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Contributions especially welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants