Skip to content

collapsible-if

Pythonstyleno fixdefault: offpython/ruff

Reports an if whose only statement is another if, when neither has an elif or else.

The two tests are one condition, if a and b:. The nesting adds an indent level and makes the reader check that nothing else happens between the tests.

To fix, join the tests with and.

Reported
...
pass
if a:
...
pass
...
python:
lint:
rules:
collapsible-if: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line collapsible-if in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff SIM102 full