codeprobe-code-smells
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStandalone Mode
独立模式
If invoked directly (not via the orchestrator), you must first:
- Read for the output contract, execution modes, and constraints.
../codeprobe/shared-preamble.md - Load applicable reference files from based on the project's tech stack.
../codeprobe/references/ - Default to mode unless the user specifies otherwise.
full
如果直接调用(不通过编排器),您必须先执行以下步骤:
- 阅读文件,了解输出约定、执行模式和约束条件。
../codeprobe/shared-preamble.md - 根据项目的技术栈,从目录加载适用的参考文件。
../codeprobe/references/ - 除非用户另有指定,否则默认使用模式。
full
Code Smells & Anti-Pattern Detector
Code Smells & Anti-Patterns 检测器
Domain Scope
领域范围
This sub-skill detects code smells and anti-patterns organized into these categories:
- Bloaters — Long Method, Large Class, Data Clumps, Primitive Obsession
- Object-Orientation Abusers — Feature Envy, Inappropriate Intimacy, Refused Bequest
- Change Preventers — Shotgun Surgery, Divergent Change
- Dispensables — Dead Code, Speculative Generality, Middle Man
- Couplers — Temporal Coupling
- Readability — Magic Numbers, Boolean Blindness, Deep Nesting
该子技能检测以下分类的code smells和anti-patterns:
- Bloaters — Long Method、Large Class、Data Clumps、Primitive Obsession
- Object-Orientation Abusers — Feature Envy、Inappropriate Intimacy、Refused Bequest
- Change Preventers — Shotgun Surgery、Divergent Change
- Dispensables — Dead Code、Speculative Generality、Middle Man
- Couplers — Temporal Coupling
- Readability — Magic Numbers、Boolean Blindness、Deep Nesting
What It Does NOT Flag
不会标记的内容
- Generated code — Migrations, compiled output, vendor directories (,
vendor/,node_modules/,dist/,build/), and auto-generated files (e.g., GraphQL codegen, Prisma client)..next/ - Test files with long setup methods — Test context is different; long or
setUp()methods arranging test data are expected and acceptable.beforeEach() - Configuration files with many entries — A config file with 50 key-value pairs is not a "Large Class" smell.
- Data migration files — These are procedural by nature and often contain long methods.
- Third-party code checked into the repository (e.g., vendored libraries).
- Structural issues already flagged by or
codeprobe-solid— Large classes may also be flagged as SRP violations or god objects. This sub-skill should still detect and report them, but the orchestrator will deduplicate overlapping findings at the same location.codeprobe-architecture
- 生成代码 — 迁移文件、编译输出、供应商目录(、
vendor/、node_modules/、dist/、build/)以及自动生成的文件(例如GraphQL codegen、Prisma client)。.next/ - 测试文件中的长初始化方法 — 测试上下文不同,用于安排测试数据的长或
setUp()方法是符合预期且可接受的。beforeEach() - 配置文件中的大量条目 — 包含50个键值对的配置文件不属于“Large Class”异味。
- 数据迁移文件 — 这类文件本质上是过程式的,通常包含长方法。
- 签入仓库的第三方代码(例如供应商库)。
- 已被或
codeprobe-solid标记的结构性问题 — 大类可能同时被标记为SRP违规或上帝对象。该子技能仍需检测并报告这些问题,但编排器会对同一位置的重复发现进行去重。codeprobe-architecture
Detection Instructions
检测说明
Configurable Thresholds
可配置阈值
Before analysis, check for a file in the project root. If present, load the section to adjust these defaults:
.codeprobe-config.jsonseverity_overrides| Threshold | Config Key | Default |
|---|---|---|
| Long Method LOC limit | | 30 |
| Large Class LOC limit | | 300 |
| Deep Nesting max levels | | 3 |
分析前,请检查项目根目录下是否存在文件。若存在,加载部分以调整以下默认值:
.codeprobe-config.jsonseverity_overrides| 阈值 | 配置键 | 默认值 |
|---|---|---|
| Long Method LOC限制 | | 30 |
| Large Class LOC限制 | | 300 |
| 深层嵌套最大层级 | | 3 |
Bloaters
Bloaters
| ID Prefix | Smell | Signal | How to Detect | Default Threshold | Severity |
|---|---|---|---|---|---|
| Long Method | Function/method exceeds LOC threshold | Count lines in each function/method body (excluding blank lines and single-line comments). Compare against | > 30 LOC | Minor |
| Large Class | Class exceeds LOC threshold | Count total lines in each class definition. Compare against | > 300 LOC | Major |
| Data Clumps | Same 3+ params passed together in 3+ places | Search for function/method signatures. Identify groups of 3+ parameters that appear together in 3+ different function signatures or call sites. These should be extracted into a parameter object or value object. | 3+ params, 3+ occurrences | Minor |
| Primitive Obsession | String/int used where a value object is warranted | Look for string/integer variables representing domain concepts: email addresses (validated by regex inline), money amounts (numeric + currency passed separately), phone numbers, status strings compared in multiple places, ZIP codes, UUIDs passed as plain strings through multiple layers. | Pattern recognition | Minor |
| ID前缀 | 异味类型 | 信号 | 检测方式 | 默认阈值 | 严重程度 |
|---|---|---|---|---|---|
| Long Method | 函数/方法超出LOC阈值 | 统计每个函数/方法体的行数(不包括空行和单行注释),与 | > 30 LOC | Minor |
| Large Class | 类超出LOC阈值 | 统计每个类定义的总行数,与 | > 300 LOC | Major |
| Data Clumps | 相同的3个及以上参数在3个及以上位置一起传递 | 搜索函数/方法签名,识别出现在3个及以上不同函数签名或调用位置的3个及以上参数组。这些参数应提取为参数对象或值对象。 | 3+参数,3+出现次数 | Minor |
| Primitive Obsession | 使用字符串/整数代替值对象 | 查找代表领域概念的字符串/整数变量:通过内联正则验证的电子邮件地址、单独传递的金额(数值+货币)、电话号码、在多个位置比较的状态字符串、邮政编码、作为纯字符串在多层传递的UUID。 | 模式识别 | Minor |
Object-Orientation Abusers
Object-Orientation Abusers
| ID Prefix | Smell | Signal | How to Detect | Default Threshold | Severity |
|---|---|---|---|---|---|
| Feature Envy | Method accesses another object's data 3x+ more than its own | Count how many times a method references | 3+ external accesses | Minor |
| Inappropriate Intimacy | Class accessing another's private/protected internals | Search for reflection-based access ( | Any occurrence | Major |
| Refused Bequest | Subclass inherits but doesn't use most of parent's methods | Examine subclasses: if the parent has N public methods and the subclass overrides fewer than 30% of them while also not calling | Unused majority of parent methods | Minor |
| ID前缀 | 异味类型 | 信号 | 检测方式 | 默认阈值 | 严重程度 |
|---|---|---|---|---|---|
| Feature Envy | 方法访问另一个对象的数据次数是自身的3倍及以上 | 统计方法引用 | 3+外部访问 | Minor |
| Inappropriate Intimacy | 类访问另一个类的私有/受保护内部成员 | 搜索基于反射的访问( | 任何出现情况 | Major |
| Refused Bequest | 子类继承但未使用父类的大部分方法 | 检查子类:若父类有N个公共方法,子类重写的方法不足30%,且大部分方法未调用 | 未使用父类的大部分方法 | Minor |
Change Preventers
Change Preventers
| ID Prefix | Smell | Signal | How to Detect | Default Threshold | Severity |
|---|---|---|---|---|---|
| Shotgun Surgery | Changing one concept requires edits in 5+ files | Search for a single concept (e.g., a field name, a status value, a business rule) that appears across many files. If the same constant, column name, or business term appears in 5+ files without being centralized behind a single source of truth, flag it. | 5+ files for one concept | Major |
| Divergent Change | One class modified for 3+ unrelated reasons | Examine large classes (> 200 LOC). Check whether the methods cluster around distinct, unrelated concerns. If a single class handles user authentication, email formatting, AND report generation, it has divergent change — any of those 3 areas changing forces this class to change. | 3+ distinct concerns | Major |
| ID前缀 | 异味类型 | 信号 | 检测方式 | 默认阈值 | 严重程度 |
|---|---|---|---|---|---|
| Shotgun Surgery | 修改一个概念需要编辑5个及以上文件 | 搜索出现在多个文件中的单一概念(例如字段名、状态值、业务规则)。若同一常量、列名或业务术语出现在5个及以上文件中,且未集中在单一数据源背后,则标记该问题。 | 一个概念涉及5+文件 | Major |
| Divergent Change | 一个类因3个及以上无关原因被修改 | 检查大类(>200 LOC),查看方法是否围绕不同的无关关注点聚类。若单个类同时处理用户认证、邮件格式和报告生成,则存在Divergent Change——这些3个领域中的任何一个发生变化,都会导致该类需要修改。 | 3+不同关注点 | Major |
Dispensables
Dispensables
| ID Prefix | Smell | Signal | How to Detect | Default Threshold | Severity |
|---|---|---|---|---|---|
| Dead Code | Unreachable branches, unused imports, commented-out code blocks | Search for: (1) | Any occurrence | Minor |
| Speculative Generality | Abstractions/interfaces with only one implementation and no foreseeable second | Search for interfaces, abstract classes, or generic type parameters that have exactly one concrete implementation. If the abstraction does not appear in a DI container config or test mock, and the domain doesn't suggest future variants, flag it as premature abstraction. | Single implementation | Suggestion |
| Middle Man | Class that only delegates to another class with no added logic | Look for classes where every method simply calls the same method on an injected dependency and returns the result, with no added logic, validation, transformation, or error handling. The class adds an unnecessary indirection layer. | Pure delegation in all methods | Minor |
| ID前缀 | 异味类型 | 信号 | 检测方式 | 默认阈值 | 严重程度 |
|---|---|---|---|---|---|
| Dead Code | 不可达分支、未使用的导入、注释掉的代码块 | 搜索:(1) 文件中从未被引用的 | 任何出现情况 | Minor |
| Speculative Generality | 只有一个实现且预计不会有第二个实现的抽象/接口 | 搜索只有一个具体实现的接口、抽象类或泛型类型参数。若该抽象未出现在DI容器配置或测试模拟中,且领域不暗示未来会有变体,则标记为过早抽象。 | 单一实现 | Suggestion |
| Middle Man | 仅委托给另一个类且无额外逻辑的类 | 查找所有方法仅调用注入依赖的相同方法并返回结果,且无额外逻辑、验证、转换或错误处理的类。该类添加了不必要的间接层。 | 所有方法均为纯委托 | Minor |
Couplers
Couplers
| ID Prefix | Smell | Signal | How to Detect | Default Threshold | Severity |
|---|---|---|---|---|---|
| Temporal Coupling | Methods must be called in specific order but nothing enforces it | Look for patterns where: (1) method A must be called before method B but there's no compile-time or runtime check, (2) | Implicit ordering dependency | Major |
| ID前缀 | 异味类型 | 信号 | 检测方式 | 默认阈值 | 严重程度 |
|---|---|---|---|---|---|
| Temporal Coupling | 方法必须按特定顺序调用但无任何强制机制 | 查找以下模式:(1) 方法A必须在方法B之前调用,但无编译时或运行时检查;(2) | 隐式顺序依赖 | Major |
Readability
Readability
| ID Prefix | Smell | Signal | How to Detect | Default Threshold | Severity |
|---|---|---|---|---|---|
| Magic Numbers | Hardcoded numeric/string literals without named constants in business logic | Search for numeric literals (other than 0, 1, -1) and string literals used in conditionals, calculations, or business logic. Flag values like | Any in logic paths | Minor |
| Boolean Blindness | Method with 2+ boolean params | Search for function/method signatures with 2 or more | 2+ boolean parameters | Minor |
| Deep Nesting | Indentation levels exceed threshold | Count nesting depth in each function: each | > 3 levels | Minor |
| ID前缀 | 异味类型 | 信号 | 检测方式 | 默认阈值 | 严重程度 |
|---|---|---|---|---|---|
| Magic Numbers | 业务逻辑中使用未命名常量的硬编码数值/字符串字面量 | 搜索条件判断、计算或业务逻辑中使用的数值字面量(0、1、-1除外)和字符串字面量。标记出现在逻辑路径中且无命名常量的值,如 | 逻辑路径中的任何出现情况 | Minor |
| Boolean Blindness | 包含2个及以上布尔参数的方法 | 搜索包含2个及以上 | 2+布尔参数 | Minor |
| Deep Nesting | 缩进层级超过阈值 | 统计每个函数的嵌套深度:每个嵌套在其他结构中的 | >3层级 | Minor |
ID Prefix & Fix Prompt Examples
ID前缀与修复提示示例
All findings use the prefix, numbered sequentially: , , etc.
SMELL-SMELL-001SMELL-002所有发现均使用前缀,并按顺序编号:、等。
SMELL-SMELL-001SMELL-002Fix Prompt Examples
修复提示示例
- "Extract lines 45-90 of into a private method
UserService@register— the method is 120 LOC doing 3 unrelated things: input validation (lines 45-65), data normalization (lines 66-80), and persistence (lines 81-90). Keep persistence invalidateAndNormalizeInput()and extract the other two concerns."register() - "Replace the magic number at line 55 of
86400with a named constantapp/Services/CacheService.phpdefined at the top of the class."SECONDS_PER_DAY = 86400 - "Refactor in
processOrder(bool $isExpress, bool $requiresSignature, bool $isFragile)(line 30) to accept aOrderProcessor.phpvalue object instead of 3 boolean parameters. Create aShippingOptionsclass with named properties."ShippingOptions - "Remove the commented-out code block at lines 88-105 of — this is dead code from a previous implementation. If needed later, it can be recovered from version control."
PaymentGateway.php - "In , the
ReportGenerator.phpmethod at line 20 is 95 LOC. Extract the data-fetching logic (lines 25-50) intogenerate()and the formatting logic (lines 51-85) intofetchReportData(). TheformatReport()method should orchestrate these two steps."generate()
- "将的第45-90行提取为私有方法
UserService@register——该方法有120 LOC,处理3项无关事务:输入验证(第45-65行)、数据标准化(第66-80行)和持久化(第81-90行)。将持久化逻辑保留在validateAndNormalizeInput()中,提取另外两项逻辑。"register() - "将第55行的魔术数字
app/Services/CacheService.php替换为类顶部定义的命名常量86400。"SECONDS_PER_DAY = 86400 - "重构第30行的
OrderProcessor.php,使其接受processOrder(bool $isExpress, bool $requiresSignature, bool $isFragile)值对象而非3个布尔参数。创建带有命名属性的ShippingOptions类。"ShippingOptions - "移除第88-105行的注释代码块——这是旧实现的死代码。若后续需要,可从版本控制系统恢复。"
PaymentGateway.php - "在中,第20行的
ReportGenerator.php方法有95 LOC。将数据获取逻辑(第25-50行)提取到generate(),将格式化逻辑(第51-85行)提取到fetchReportData()。formatReport()方法应协调这两个步骤。"generate()