Get the FREE Ultimate OpenClaw Setup Guide →

code-simplifier

npx machina-cli add skill 7dieuuoc/ChernyCode/code-simplifier --openclaw
Files (1)
SKILL.md
2.4 KB

Code Simplifier

Clean up and simplify code after making changes.

When to Use

Run this skill after completing a feature or fix to ensure the code is clean, readable, and maintainable.

Simplification Goals

Reduce Complexity

  • Break long functions into smaller, focused ones
  • Reduce nesting depth (max 3 levels)
  • Simplify complex conditionals
  • Extract magic numbers to named constants

Improve Readability

  • Use descriptive variable and function names
  • Add clarifying comments for non-obvious logic
  • Ensure consistent formatting
  • Remove unnecessary comments

Apply Pythonic Patterns

  • Use list/dict/set comprehensions where appropriate
  • Use with statements for resource management
  • Use enumerate() instead of manual indexing
  • Use zip() for parallel iteration
  • Use f-strings for formatting
  • Use pathlib for file paths

Clean Up

  • Remove unused imports
  • Remove unused variables
  • Remove commented-out code
  • Remove redundant code paths
  • Consolidate duplicate logic

Workflow

  1. Identify Changed Files

    • Focus on files modified in the current session
    • Or specify files/directories as arguments
  2. Analyze Each File

    • Check for simplification opportunities
    • Prioritize high-impact improvements
  3. Apply Simplifications

    • Make incremental changes
    • Preserve original behavior
    • Run tests after each change
  4. Format and Lint

    • Run ruff format .
    • Run ruff check --fix .
  5. Verify

    • Run tests: pytest
    • Ensure behavior unchanged

Arguments

Optionally specify files or directories to simplify.

Usage:

  • /code-simplifier - Simplify recently changed files
  • /code-simplifier src/module.py - Simplify specific file
  • /code-simplifier src/ - Simplify entire directory

Example Transformations

Before:

result = []
for i in range(len(items)):
    if items[i].is_valid == True:
        result.append(items[i].value)

After:

result = [item.value for item in items if item.is_valid]

Before:

if x != None:
    if y != None:
        if z != None:
            process(x, y, z)

After:

if all(v is not None for v in (x, y, z)):
    process(x, y, z)

Source

git clone https://github.com/7dieuuoc/ChernyCode/blob/main/cursor_personal_skills/code-simplifier/SKILL.mdView on GitHub

Overview

Code Simplifier cleans up code after feature work or bug fixes to improve readability and maintainability. It targets reducing complexity, clarifying intent, and applying Pythonic patterns while removing unused or redundant code.

How This Skill Works

The tool analyzes files changed in the current session, identifies simplification opportunities, and applies incremental changes while preserving behavior. It then formats and lint-checks with ruff and runs tests to verify no regressions.

When to Use It

  • After completing a feature or fix to ensure code is clean and maintainable
  • When a function is long or heavily nested and could be split
  • When conditionals are overly complex or contain magic numbers
  • When adding code that can leverage Pythonic patterns (comprehensions, with, enumerate, zip, f-strings, pathlib)
  • Before committing to ensure consistency, readability, and removal of unused code

Quick Start

  1. Step 1: Identify changed files in the current session
  2. Step 2: Analyze each file for simplification opportunities and apply incremental changes
  3. Step 3: Run formatting and linting, then execute tests to verify behavior

Best Practices

  • Break long functions into smaller, focused ones and cap nesting depth at 3
  • Use descriptive names and clarifying comments for non-obvious logic
  • Adopt Pythonic patterns: comprehensions, with, enumerate, zip, f-strings, pathlib
  • Remove unused imports/variables and eliminate commented-out or redundant code paths
  • Format and lint with ruff format, ruff check, and run tests (pytest) to verify behavior

Example Use Cases

  • Convert a for-loop that builds a list into a single list comprehension
  • Replace chained None checks with a single if all(v is not None for v in (a, b, c))
  • Use enumerate() instead of manual index tracking
  • Use zip() to iterate over multiple sequences in parallel
  • Use pathlib for file paths and with statements for resource handling

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers