Code Simplifier

作者 pproencacf93c57cac89无许可证215 个星标收录于 2026年10月8日更新于 2026年10月8日仓库7周前更新

Code simplification skill for improving clarity, consistency, and maintainability while preserving exact behavior. Use when simplifying code, reducing complexity, cleaning up recent changes, applying refactoring patterns, or improving readability. Triggers on tasks involving code cleanup, simplification, refactoring, or readability improvements.

AI 生成的概览

一套包含 47 条规则的参考指南,用于在保持行为完全不变的前提下简化代码。

功能
该技能提供按 8 个类别组织的 47 条代码简化规则,涵盖上下文发现、行为保持、命名、重复消除、死代码清理和语言惯用法。每条规则都有独立的参考文件,包含说明以及错误与正确写法的对比示例。它还定义了工作流程:先了解项目上下文,将范围限制在近期修改的代码,按优先级应用改写,验证行为未变,并保持差异最小。
适用场景
适用于清理或简化近期修改的代码、减少嵌套与复杂度或重复、改进命名与可读性,以及应用特定语言的惯用写法。也用于审查代码的可维护性问题。
运行要求
仅包含指令与参考文档,不附带脚本。需要代理能够读取项目文件,例如 CLAUDE.md 以及 lint 或格式化配置。

Community Code Simplification Best Practices

Comprehensive code simplification guide for AI agents and LLMs. Contains 47 rules across 8 categories, prioritized by impact from critical (context discovery, behavior preservation) to incremental (language idioms). Each rule includes detailed explanations, real-world examples comparing incorrect vs. correct implementations, and specific impact metrics.

Core Principles

  1. Context First: Understand project conventions before making any changes
  2. Behavior Preservation: Change how code is written, never what it does
  3. Scope Discipline: Focus on recently modified code, keep diffs small
  4. Clarity Over Brevity: Explicit, readable code beats clever one-liners

When to Apply

Reference these guidelines when:

  • Simplifying or cleaning up recently modified code
  • Reducing nesting, complexity, or duplication
  • Improving naming and readability
  • Applying language-specific idiomatic patterns
  • Reviewing code for maintainability issues

Rule Categories by Priority

PriorityCategoryImpactPrefixRules
1Context DiscoveryCRITICALctx-4
2Behavior PreservationCRITICALbehave-6
3Scope ManagementHIGHscope-5
4Control Flow SimplificationHIGHflow-9
5Naming and ClarityMEDIUM-HIGHname-6
6Duplication ReductionMEDIUMdup-5
7Dead Code EliminationMEDIUMdead-5
8Language IdiomsLOW-MEDIUMidiom-7

Quick Reference

1. Context Discovery (CRITICAL)

  • ctx-read-claude-md [blocked] - Always read CLAUDE.md before simplifying
  • ctx-detect-lint-config [blocked] - Check for linting and formatting configs
  • ctx-follow-existing-patterns [blocked] - Match existing code style in file and project
  • ctx-project-over-generic [blocked] - Project conventions override generic best practices

2. Behavior Preservation (CRITICAL)

  • behave-preserve-outputs [blocked] - Preserve all return values and outputs
  • behave-preserve-errors [blocked] - Preserve error messages, types, and handling
  • behave-preserve-api [blocked] - Preserve public function signatures and types
  • behave-preserve-side-effects [blocked] - Preserve side effects (logging, I/O, state changes)
  • behave-no-semantics-change [blocked] - Forbid subtle semantic changes
  • behave-verify-before-commit [blocked] - Verify behavior preservation before finalizing

3. Scope Management (HIGH)

  • scope-recent-code-only [blocked] - Focus on recently modified code only
  • scope-minimal-diff [blocked] - Keep changes small and reviewable
  • scope-no-unrelated-refactors [blocked] - No unrelated refactors
  • scope-no-global-rewrites [blocked] - Avoid global rewrites and architectural changes
  • scope-respect-boundaries [blocked] - Respect module and component boundaries

4. Control Flow Simplification (HIGH)

  • flow-early-return [blocked] - Use early returns to reduce nesting
  • flow-guard-clauses [blocked] - Use guard clauses for preconditions
  • flow-no-nested-ternaries [blocked] - Never use nested ternary operators
  • flow-explicit-over-dense [blocked] - Prefer explicit control flow over dense expressions
  • flow-flatten-nesting [blocked] - Flatten deep nesting to maximum 2-3 levels
  • flow-single-responsibility [blocked] - Each code block should do one thing
  • flow-positive-conditions [blocked] - Prefer positive conditions over double negatives
  • flow-optional-chaining [blocked] - Use optional chaining and nullish coalescing
  • flow-boolean-simplification [blocked] - Simplify boolean expressions

5. Naming and Clarity (MEDIUM-HIGH)

  • name-intention-revealing [blocked] - Use intention-revealing names
  • name-nouns-for-data [blocked] - Use nouns for data, verbs for actions
  • name-avoid-abbreviations [blocked] - Avoid cryptic abbreviations
  • name-consistent-vocabulary [blocked] - Use consistent vocabulary throughout
  • name-avoid-generic [blocked] - Avoid generic names
  • name-string-interpolation [blocked] - Prefer string interpolation over concatenation

6. Duplication Reduction (MEDIUM)

  • dup-rule-of-three [blocked] - Apply the rule of three
  • dup-no-single-use-helpers [blocked] - Avoid single-use helper functions
  • dup-extract-for-clarity [blocked] - Extract only when it improves clarity
  • dup-avoid-over-abstraction [blocked] - Prefer duplication over premature abstraction
  • dup-data-driven [blocked] - Use data-driven patterns over repetitive conditionals

7. Dead Code Elimination (MEDIUM)

  • dead-remove-unused [blocked] - Delete unused code artifacts
  • dead-delete-not-comment [blocked] - Delete code, never comment it out
  • dead-remove-obvious-comments [blocked] - Remove comments that state the obvious
  • dead-keep-why-comments [blocked] - Keep comments that explain why, not what
  • dead-remove-todo-fixme [blocked] - Remove stale TODO/FIXME comments

8. Language Idioms (LOW-MEDIUM)

  • idiom-ts-strict-types [blocked] - Use strict types over any (TypeScript)
  • idiom-ts-const-assertions [blocked] - Use const assertions and readonly (TypeScript)
  • idiom-rust-question-mark [blocked] - Use ? for error propagation (Rust)
  • idiom-rust-iterator-chains [blocked] - Use iterator chains when clearer (Rust)
  • idiom-python-comprehensions [blocked] - Use comprehensions for simple transforms (Python)
  • idiom-go-error-handling [blocked] - Handle errors immediately (Go)
  • idiom-prefer-language-builtins [blocked] - Prefer language and stdlib builtins

Workflow

  1. Discover context: Read CLAUDE.md, lint configs, examine existing patterns
  2. Identify scope: Focus on recently modified code unless asked to expand
  3. Apply transformations: Use rules in priority order (CRITICAL first)
  4. Verify behavior: Ensure outputs, errors, and side effects remain identical
  5. Keep diffs minimal: Small, focused changes that are easy to review

How to Use

Read individual reference files for detailed explanations and code examples:

  • Section definitions [blocked] - Category structure and impact levels
  • Rule template [blocked] - Template for adding new rules

Reference Files

FileDescription
references/_sections.md [blocked]Category definitions and ordering
assets/templates/_template.md [blocked]Template for new rules
metadata.json [blocked]Version and reference information

来源与署名

来源:pproenca/dot-skills位于skills/.curated/code-simplifier提交cf93c57

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架