Skip to content

Commit

Permalink
Extend the description with the option of adding an explicit else
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-reiss committed Feb 27, 2024
1 parent 1639ce7 commit a96a567
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use crate::checkers::ast::Checker;
///
/// ## Why is this bad?
/// It may not be ovious if the elif statement was willingly or mistakenly unindented.
/// Extracting the indented if statement into a separate function might avoid confusion and prevent errors.
/// Adding an explicit else, or extracting the indented if statement into a separate
/// function might avoid confusion and prevent errors.
///
/// ## Example
/// ```python
Expand All @@ -26,6 +27,19 @@ use crate::checkers::ast::Checker;
///
/// Use instead:
/// ```python
/// # Option 1: add explicit else
/// if old_conf:
/// if not new_conf:
/// machine.disable()
/// elif old_conf.value != new_conf.value:
/// machine.disable()
/// machine.enable(new_conf.value)
/// else:
/// pass
/// elif new_conf: # [confusing-consecutive-elif]
/// machine.enable(new_conf.value)
///
/// # Option 2: extract function
/// def extracted(old_conf, new_conf, machine):
/// if not new_conf:
/// machine.disable()
Expand Down

0 comments on commit a96a567

Please sign in to comment.