slop

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Remove AI Code Slop

移除AI生成的冗余代码

Check the diff against a branch and remove all AI-generated slop introduced in this branch. Simplifies and refines code for clarity, consistency, and maintainability while preserving all functionality.
对比分支差异,移除当前分支中引入的所有AI生成的冗余代码。在保留所有功能的同时,简化并优化代码,提升代码的清晰度、一致性和可维护性。

Usage

使用方法

/slop [branch-name]
  • If no branch is provided, compare against main:
    /slop main
/slop [branch-name]
  • 如果未指定分支,则默认与main分支对比:
    /slop main

What is AI Code Slop?

什么是AI生成的冗余代码?

This includes:
  • Extra comments that a human wouldn't add or is inconsistent with the rest of the file
  • Extra defensive checks or try/catch blocks that are abnormal for that area of the codebase
  • Casts to
    any
    to get around type issues
  • Any other style that is inconsistent with the file
这包括:
  • 人类不会添加的、或与文件其余部分风格不一致的多余注释
  • 在代码库该区域中不符合常规的额外防御性检查或try/catch块
  • 为绕过类型问题而使用的
    any
    类型转换
  • 任何与文件风格不一致的其他代码写法

Core Principles

核心原则

1. Preserve Functionality

1. 保留功能

Never change what the code does - only how it does it. All original features, outputs, and behaviors must remain intact.
绝不改变代码的功能——仅优化实现方式。所有原有特性、输出和行为必须保持完整。

2. Apply Project Standards

2. 遵循项目标准

Follow the established coding standards from the project's CLAUDE.md or conventions:
  • Use proper import sorting and file organization
  • Follow language-specific patterns (ES modules, proper TypeScript types, etc.)
  • Maintain consistent naming conventions
  • Use proper error handling patterns
遵循项目CLAUDE.md中规定的编码标准或惯例:
  • 使用正确的导入排序和文件组织结构
  • 遵循语言特定的模式(ES模块、规范的TypeScript类型等)
  • 保持一致的命名规范
  • 使用正确的错误处理模式

3. Enhance Clarity

3. 提升清晰度

Simplify code structure by:
  • Reducing unnecessary complexity and nesting
  • Eliminating redundant code and abstractions
  • Improving readability through clear variable and function names
  • Consolidating related logic
  • Removing unnecessary comments that describe obvious code
  • IMPORTANT: Avoid nested ternary operators - prefer switch statements or if/else chains
  • Choose clarity over brevity - explicit code is often better than overly compact code
通过以下方式简化代码结构:
  • 减少不必要的复杂度和嵌套
  • 消除冗余代码和抽象
  • 通过清晰的变量和函数名称提升可读性
  • 整合相关逻辑
  • 移除描述明显代码的多余注释
  • 重要提示:避免嵌套三元运算符——优先使用switch语句或if/else链式结构
  • 优先选择清晰度而非简洁性——显式代码通常优于过度紧凑的代码

4. Maintain Balance

4. 保持平衡

Avoid over-simplification that could:
  • Reduce code clarity or maintainability
  • Create overly clever solutions that are hard to understand
  • Combine too many concerns into single functions
  • Remove helpful abstractions that improve code organization
  • Prioritize "fewer lines" over readability
避免过度简化导致以下问题:
  • 降低代码清晰度或可维护性
  • 创造难以理解的过度“巧妙”的解决方案
  • 将过多关注点合并到单个函数中
  • 移除有助于代码组织的有用抽象
  • 优先追求“更少代码行数”而非可读性

Process

操作流程

1. Get the diff

1. 获取差异

bash
undefined
bash
undefined

Compare against main branch

与main分支对比

git diff main...HEAD --stat
git diff main...HEAD --stat

Or against specific branch

或与指定分支对比

git diff $1 --stat
undefined
git diff $1 --stat
undefined

2. Review each changed file

2. 审查每个变更文件

For each changed file:
  • Read the current content
  • Compare with original (before changes)
  • Identify AI-generated slop patterns
  • Check for opportunities to improve elegance and consistency
对于每个变更的文件:
  • 阅读当前内容
  • 与原始内容(变更前)进行对比
  • 识别AI生成的冗余代码模式
  • 寻找提升代码优雅性和一致性的机会

3. Remove slop and refine

3. 移除冗余代码并优化

  • Remove unnecessary comments
  • Simplify overly defensive code
  • Remove
    any
    casts where possible
  • Restore natural code style
  • Apply project-specific best practices
  • Ensure all functionality remains unchanged
  • 移除不必要的注释
  • 简化过度防御性的代码
  • 尽可能移除
    any
    类型转换
  • 恢复自然的代码风格
  • 应用项目特定的最佳实践
  • 确保所有功能保持不变

4. Verify

4. 验证

bash
undefined
bash
undefined

Show remaining changes

查看剩余变更

git diff --stat
git diff --stat

Check tests still pass

检查测试是否仍能通过

npm test
undefined
npm test
undefined

Common Slop Patterns

常见冗余代码模式

  1. Over-commenting: Comments explaining obvious code
  2. Verbose error handling: Try/catch blocks where not needed
  3. Unnecessary type casts:
    x as any
    to bypass TypeScript
  4. Defensive programming: Checks for already-validated inputs
  5. Redundant validation: Duplicate null/undefined checks
  6. Nested ternaries: Complex nested ternary operators
  7. Overly compact code: Dense one-liners that sacrifice readability
  1. 过度注释:解释明显代码的注释
  2. 冗长错误处理:不必要的try/catch块
  3. 不必要的类型转换:使用
    x as any
    绕过TypeScript类型检查
  4. 过度防御性编程:对已验证的输入进行检查
  5. 冗余验证:重复的null/undefined检查
  6. 嵌套三元运算符:复杂的嵌套三元运算符
  7. 过度紧凑代码:牺牲可读性的密集单行代码

Refinement Guidelines

代码精炼指南

When refining code:
  1. Identify the modified sections - Only refine code that changed in the diff
  2. Analyze for improvement opportunities - Look for ways to enhance elegance and consistency
  3. Apply project standards - Follow established conventions and patterns
  4. Preserve functionality - Ensure behavior remains unchanged
  5. Verify improvements - The refined code should be simpler and more maintainable
  6. Document significant changes - Only document changes that affect understanding
优化代码时:
  1. 识别修改区域——仅优化差异中变更的代码部分
  2. 分析优化机会——寻找提升代码优雅性和一致性的方式
  3. 遵循项目标准——遵循既定的规范和模式
  4. 保留功能——确保代码行为保持不变
  5. 验证优化效果——优化后的代码应更简洁、更易于维护
  6. 记录重大变更——仅记录影响理解的变更

Code Style Preferences

代码风格偏好

  • Prefer explicit over compact - readable code beats clever code
  • Use descriptive names - clarity over brevity
  • Avoid deep nesting - flatten structure when possible
  • Remove redundant code - eliminate duplicates
  • Use language-appropriate patterns - follow idiomatic practices
  • 优先选择显式而非紧凑——可读性代码优于巧妙的代码
  • 使用描述性命名——清晰度优先于简洁性
  • 避免深层嵌套——尽可能扁平化结构
  • 移除冗余代码——消除重复内容
  • 使用适合语言的模式——遵循惯用写法