Break down complex code structures into simpler, more readable forms. Long indented blocks, verbose conditionals, and repetitive patterns should be simplified to improve code clarity and maintainability.
Key practices:
Examples:
Instead of a verbose loop:
for value in validation_state_metadata.values():
if value == "block":
return True
return False
Use a concise expression:
return "block" in validation_state_metadata.values()
Instead of confusing conditional order:
*(
(self.start.offset, self.end.offset)
if not (self.extra.get("sca_info") and not self.extra["sca_info"].reachable)
else (self.start.line, self.end.line)
),
Reorder for clarity:
*(
(self.start.line, self.end.line)
if (self.extra.get("sca_info") and not self.extra["sca_info"].reachable)
else (self.start.offset, self.end.offset)
),
This approach reduces cognitive load and makes code easier to understand and maintain.
Enter the URL of a public GitHub repository