Token导航 LogoToken导航TokenDH.com
研究检索只读github未标认证来源可访问许可证需确认审计通过

refactor-method-complexity-reduce重构方法复杂度降低

Agent Skill

refactor-method-complexity-reduce 用于记录任务执行中的错误、用户纠正、经验和能力缺口,适合在 Codex、Claude、Cursor、Gemini CLI 中希望让 Agent 持续沉淀问题、修正和最佳实践时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

209,328

周安装

8,892

GitHub Stars

31,714

下载量

73,336
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:refactor-method-complexity-reduce(重构方法复杂度降低)
来源仓库:https://github.com/github/awesome-copilot
仓库路径:skills/refactor-method-complexity-reduce
安装命令:
npx skills add https://github.com/github/awesome-copilot --skill refactor-method-complexity-reduce
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/github/awesome-copilot --skill refactor-method-complexity-reduce

简介

通过提取辅助方法来重构方法以降低认知复杂性。

  • 分析嵌套条件、循环和复杂布尔表达式以识别重构机会
  • 将验证逻辑、特定于类型的处理和重复代码块提取到重点帮助器方法中
  • 简化主要方法流程,同时保留所有原始功能和错误处理
  • 包括强制性测试验证,以确认零测试失败和认知复杂性等于或低于目标阈值

SKILL.md

Refactor Method to Reduce Cognitive Complexity

Objective

Refactor the method ${input:methodName}, to reduce its cognitive complexity to ${input:complexityThreshold} or below, by extracting logic into focused helper methods.

Instructions

  1. Analyze the current method to identify sources of cognitive complexity:

- Nested conditional statements - Multiple if-else or switch chains - Repeated code blocks - Multiple loops with conditions - Complex boolean expressions

  1. Identify extraction opportunities:

- Validation logic that can be extracted into a separate method - Type-specific or case-specific processing that repeats - Complex transformations or calculations - Common patterns that appear multiple times

  1. Extract focused helper methods:

- Each helper should have a single, clear responsibility - Extract validation into separate Validate* methods - Extract type-specific logic into handler methods - Create utility methods for common operations - Use appropriate access levels (static, private, async)

  1. Simplify the main method:

- Reduce nesting depth - Replace massive if-else chains with smaller orchestrated calls - Use switch statements where appropriate for cleaner dispatch - Ensure the main method reads as a high-level flow

  1. Preserve functionality:

- Maintain the same input/output behavior - Keep all validation and error handling - Preserve exception types and error messages - Ensure all parameters are properly passed to helpers

  1. Best practices:

- Make helper methods static when they don't need instance state - Use null checks and guard clauses early - Avoid creating unnecessary local variables - Consider using tuples for multiple return values - Group related helper methods together

Implementation Approach

  • Extract helper methods before refactoring the main flow
  • Test incrementally to ensure no regressions
  • Use meaningful names that describe the extracted responsibility
  • Keep extracted methods close to where they're used
  • Consider making repeated code patterns into generic methods

Result

The refactored method should:

  • Have cognitive complexity reduced to the target threshold of ${input:complexityThreshold} or below
  • Be more readable and maintainable
  • Have clear separation of concerns
  • Be easier to test and debug
  • Retain all original functionality

Testing and Validation

CRITICAL: After completing the refactoring, you MUST:

  1. Run all existing tests related to the refactored method and its surrounding functionality
  2. MANDATORY: Explicitly verify test results show "failed=0"

- NEVER assume tests passed - always examine the actual test output - Search for the summary line containing pass/fail counts (e.g., "passed=X failed=Y") - If the summary shows any number other than "failed=0", tests have FAILED - If test output is in a file, read the entire file to locate and verify the failure count - Running tests is NOT the same as verifying tests passed - Do not proceed until you have explicitly confirmed zero failures

  1. If any tests fail (failed > 0):

- State clearly how many tests failed - Analyze each failure to understand what functionality was broken - Common causes: null handling, empty collection checks, condition logic errors - Identify the root cause in the refactored code - Correct the refactored code to restore the original behavior - Re-run tests and verify "failed=0" in the output - Repeat until all tests pass (failed=0)

  1. Verify compilation - Ensure there are no compilation errors
  2. Check cognitive complexity - Confirm the metric is at or below the target threshold of ${input:complexityThreshold}

Confirmation Checklist

  • Code compiles without errors
  • Test results explicitly state "failed=0" (verified by reading the output)
  • All test failures analyzed and corrected (if any occurred)
  • Cognitive complexity is at or below the target threshold of ${input:complexityThreshold}
  • All original functionality is preserved
  • Code follows project conventions and standards

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.86%
按下载量换算25,565

Claude

28.98%
按下载量换算21,253

Cursor

19.18%
按下载量换算14,066

Gemini CLI

8.43%
按下载量换算6,182

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills