---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
  --> collapsible_else_if.py:37:5
   |
35 |       if 1:
36 |           pass
37 | /     else:
38 | |         if 2:
   | |________^
39 |               pass
   |
help: Convert to `elif`
   |
36 |         pass
   -     else:
   -         if 2:
   -             pass
37 +     elif 2:
38 +         pass
39 |
   |

PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
  --> collapsible_else_if.py:45:5
   |
43 |       if 1:
44 |           pass
45 | /     else:
46 | |         if 2:
   | |________^
47 |               pass
48 |           else:
   |
help: Convert to `elif`
   |
44 |         pass
45 +     elif 2:
46 +         pass
47 |     else:
   -         if 2:
   -             pass
   -         else:
   -             pass
48 +         pass
49 |
   |

PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
  --> collapsible_else_if.py:55:5
   |
53 |       if 1:
54 |           pass
55 | /     else:
56 | |         # inner comment
57 | |         if 2:
   | |________^
58 |               pass
59 |           else:
   |
help: Convert to `elif`
   |
54 |         pass
55 +     # inner comment
56 +     elif 2:
57 +         pass
58 |     else:
   -         # inner comment
   -         if 2:
   -             pass
   -         else:
   -             pass  # final pass comment
59 +         pass  # final pass comment
60 |
   |

PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
  --> collapsible_else_if.py:69:5
   |
67 |       elif True:
68 |           print(2)
69 | /     else:
70 | |         if True:
   | |________^
71 |               print(3)
72 |           else:
   |
help: Convert to `elif`
   |
68 |         print(2)
69 +     elif True:
70 +         print(3)
71 |     else:
   -         if True:
   -             print(3)
   -         else:
   -             print(4)
72 +         print(4)
73 |
   |

PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
  --> collapsible_else_if.py:79:5
   |
77 |       if 1:
78 |           pass
79 | /     else:
80 | |         if 2: pass
   | |________^
81 |           else: pass
   |
help: Convert to `elif`
   |
78 |         pass
   -     else:
   -         if 2: pass
   -         else: pass
79 +     elif 2: pass
80 +     else: pass
81 |
   |

PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
  --> collapsible_else_if.py:87:5
   |
85 |       if 1:
86 |           pass
87 | /     else:
88 | |         if 2: pass
   | |________^
89 |           else:
90 |               pass
   |
help: Convert to `elif`
   |
86 |         pass
87 +     elif 2: pass
88 |     else:
   -         if 2: pass
   -         else:
   -             pass
89 +         pass
90 |
   |

PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
  --> collapsible_else_if.py:96:5
   |
94 |       if 1:
95 |           pass
96 | /     else:
97 | |         if 2:
   | |________^
98 |               pass
99 |           else: pass
   |
help: Convert to `elif`
   |
95 |         pass
   -     else:
   -         if 2:
   -             pass
   -         else: pass
96 +     elif 2:
97 +         pass
98 +     else: pass
99 |
   |

PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
   --> collapsible_else_if.py:105:5
    |
103 |       if 1:
104 |           pass
105 | /     else:
106 | |         # inner comment which happens
107 | |         # to be longer than one line
108 | |         if 2:
    | |________^
109 |               pass
110 |           else:
    |
help: Convert to `elif`
    |
104 |         pass
105 +     # inner comment which happens
106 +     # to be longer than one line
107 +     elif 2:
108 +         pass
109 |     else:
    -         # inner comment which happens
    -         # to be longer than one line
    -         if 2:
    -             pass
    -         else:
    -             pass  # final pass comment
110 +         pass  # final pass comment
111 |
    |

PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
   --> collapsible_else_if.py:117:5
    |
115 |       if 1:
116 |           pass
117 | /     else:
118 | |             # inner comment which happens to be overly indented
119 | |         if 2:
    | |________^
120 |               pass
121 |           else:
    |
help: Convert to `elif`
    |
116 |         pass
117 +     # inner comment which happens to be overly indented
118 +     elif 2:
119 +         pass
120 |     else:
    -             # inner comment which happens to be overly indented
    -         if 2:
    -             pass
    -         else:
    -             pass  # final pass comment
121 +         pass  # final pass comment
122 |
    |

PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
   --> collapsible_else_if.py:128:5
    |
126 |       if 1:
127 |           pass
128 | /     else:
129 | |     # inner comment which happens to be under indented
130 | |         if 2:
    | |________^
131 |               pass
132 |           else:
    |
help: Convert to `elif`
    |
127 |         pass
    -     else:
128 |     # inner comment which happens to be under indented
    -         if 2:
    -             pass
    -         else:
    -             pass  # final pass comment
129 +     elif 2:
130 +         pass
131 +     else:
132 +         pass  # final pass comment
133 |
    |

PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation
   --> collapsible_else_if.py:139:5
    |
137 |       if 1:
138 |           pass
139 | /     else:
140 | |             # inner comment which has mixed
141 | |         # indentation levels
142 | |                 # which is pretty weird
143 | |         if 2:
    | |________^
144 |               pass
145 |           else:
    |
help: Convert to `elif`
    |
138 |         pass
139 +         # inner comment which has mixed
140 +     # indentation levels
141 +             # which is pretty weird
142 +     elif 2:
143 +         pass
144 |     else:
    -             # inner comment which has mixed
    -         # indentation levels
    -                 # which is pretty weird
    -         if 2:
    -             pass
    -         else:
    -             pass  # final pass comment
145 +         pass  # final pass comment
    |
