astral-sh/ruff

Auto-fix for SIM103 could be improved or add a new SIM rule?

Open

#6,184 opened on Jul 31, 2023

View on GitHub
 (10 comments) (0 reactions) (0 assignees)Rust (47,527 stars) (2,088 forks)batch import
acceptedhelp wantedrule

Description

I came across this code on a project:

if not condition_a and condition_b:
    return True
elif condition_a and condition_b:
    return True
else:
    return False

condition_a is redundant and this entire snippet should be simplified to:

return bool(condition_b)

However, this is what ruff produced using ruff --select="SIM103" example.py --fix --isolated:

if not condition_a and condition_b:
  return True
return bool(condition_a and condition_b)

I think this is correct reading the rule docs but I thought there could be some improvement here either within this rule or a new rule.

Ruff version is 0.0.280 and config:

[tool.ruff]
line-length = 120
select = [
  "D3",  # pydocstyle
  "D40", # pydocstyle
  "DTZ", # flake8-datetimez
  "FLY", # flynt
  "I",   # isort
  "INT", # flake8-gettext
  "PIE", # flake8-pie
  "PLC", # pylint
  "PLE", # pylint
  "RSE", # flake8-raise
  "SIM2", # flake8-simplify
  "SIM3", # flake8-simplify
  "TCH", # flake8-type-checking
  "W",   # pycodestyle
  "YTT", # flake8-2020
]
target-version = "py37"

Contributor guide