clean-code

Applies Clean Code principles and refactoring patterns to improve code readability and maintainability.

Updated Aug 19, 2026
One-click install
npx skills add https://github.com/nperepichka/Antigravity --skill clean-code-nperepichka
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: clean-code
Source: https://github.com/nperepichka/Antigravity/tree/main/config/skills/clean-code
Command: npx skills add https://github.com/nperepichka/Antigravity --skill clean-code-nperepichka

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Codebases accumulate technical debt through long functions, deep nesting, poor naming, and SOLID violations, making them hard to read, test, and extend. This Skill provides a systematic framework for identifying code smells and refactoring them into clean, maintainable code. ## Core Features & Use Cases - Complexity Control: Enforces cyclomatic (≤10) and cognitive (≤15) complexity thresholds with concrete refactoring tactics like guard clauses, lookup tables, and named predicates. - SOLID & Modern Error Handling: Applies all five SOLID principles with multi-language examples (Python, TypeScript, Java, Go) and distinguishes expected domain errors (Result/Option types) from unrecoverable exceptions. - Refactoring Playbook: Ships a detailed implementation playbook covering code smell catalogs, monolith decomposition, ROI-based prioritization, and static analysis toolchain configuration (Ruff, ESLint, SonarQube). - Use Case: When reviewing a pull request with a 150-line function containing nested conditionals, use this Skill to decompose it into focused methods with guard clauses, extract parameter objects, and verify complexity metrics drop below thresholds. ## Quick Start Review the attached legacy module using the clean-code skill and refactor it to reduce cognitive complexity below 15 per function.

Frequently Asked Questions about clean-code

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce cognitive complexity in nested code?▼

Reduce cognitive complexity by inverting conditions into guard clauses with early returns, extracting multi-clause conditionals into named predicate functions, and replacing if/else ladders with lookup tables. Target a cognitive complexity score of 15 or below per function.

What is the difference between cyclomatic and cognitive complexity?▼

Cyclomatic complexity counts mathematical branch paths through code, while cognitive complexity measures the mental effort to understand control flow, penalizing deep nesting and recursion. Flat switch statements raise cyclomatic but not cognitive complexity.

When should I use Result types instead of exceptions?▼

Use Result<T, E>, Option<T>, or discriminated unions for expected domain failures like validation errors or declined payments, keeping failure modes explicit in type signatures. Reserve exceptions for unexpected, unrecoverable system failures such as network drops or corrupted state.

Does this refactoring approach work with Python and TypeScript?▼

Yes, the playbook includes refactoring examples in Python, TypeScript, Java, C#, and Go, covering SOLID principles, code smell resolution, and monolith decomposition. It also configures language-specific static analysis tools like Ruff, mypy, and ESLint.

How do I prioritize which technical debt to refactor first?▼

Prioritize using the formula: (Business Value × Technical Debt) / (Effort × Risk). Fix code causing production bugs immediately, schedule debt blocking new features within the sprint, and defer style-only issues in rarely modified code to the backlog.

When should I avoid splitting code into smaller functions?▼

Avoid over-fragmentation when it breaks Locality of Behavior, scattering a cohesive linear procedure into single-use micro-helpers across files. Keep related logic together when it is better understood by reading the unit itself rather than jumping between abstractions.