astral-sh/ruff

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

Open

#6 184 ouverte le 31 juil. 2023

Voir sur GitHub
 (10 commentaires) (0 réactions) (0 assignés)Rust (2 088 forks)batch import
acceptedhelp wantedrule

Métriques du dépôt

Stars
 (47 527 stars)
Métriques de merge PR
 (Merge moyen 3j 8h) (573 PRs mergées en 30 j)

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"

Guide contributeur