Skip to content
Back to skills

Invert Broad Conditionals Into Guards

ASecurity

When a function body is wrapped in one broad conditional, invert it into a guard clause

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 17, 2026
ai-agents

Security analysis

A100/100

Scanned October 17, 2026

npx -y skills add samugit83/cortex --skill invert-broad-conditionals-into-guards --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Invert Broad Conditionals Into Guards?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Invert Broad Conditionals Into Guards
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/samugit83-invert-broad-conditionals-into-guards/badge)](https://www.skillsdirectory.com/skills/samugit83-invert-broad-conditionals-into-guards)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: invert-broad-conditionals-into-guards
description: When a function body is wrapped in one broad conditional, invert it into a guard clause
---

# Guard clauses

A function whose whole body sits inside `if ...:` hides its real work one
indent deeper than it needs to be.

Invert the condition, return early, and let the body sit at the top level:

    if item is None:
        return []
    ...the real work...

Two or three guards in a row read as a list of preconditions, which is usually
exactly what they are. Below about four, keep them; above it, the preconditions
themselves are probably worth a small helper of their own.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.