Co-Pilot / 辅助式
更新于 24 days ago

code-dedup-skills

Xxiaodong-wu
0.0k
xiaodong-wu/code-dedup-skills
82
Agent 评分

💡 摘要

一个代码分析工具,检测重复代码、死代码并建议结构改进。

🎯 适合人群

软件开发人员代码维护者DevOps工程师质量保证团队技术负责人

🤖 AI 吐槽:看起来很能打,但别让配置把人劝退。

安全分析中风险

风险:Medium。建议检查:是否执行 shell/命令行指令;是否发起外网请求(SSRF/数据外发);依赖锁定与供应链风险。以最小权限运行,并在生产环境启用前审计代码与依赖。

Code Dedup

Comprehensive code analysis for duplicate detection, dead code elimination, and structure optimization

AI-friendly code analysis platform that detects duplicate code, identifies dead code, and suggests structural improvements. Powered by MinHash LSH for O(n) performance.

Installation

npm install

Quick Start

# Analyze a project node src/cli.js analyze ./src # Check for duplicates node src/cli.js check-dup ./src # Check for dead code node src/cli.js check-dead ./src # Check structure issues node src/cli.js check-struct ./src

Features

  • O(n) Duplicate Detection - MinHash LSH algorithm for fast approximate matching
  • Dead Code Detection - AST-based static analysis to find unused code
  • Structure Analysis - Complexity, function length, and nesting metrics
  • AI-Friendly API - Simple function calls returning structured JSON
  • Multiple Formats - JSON, console, and HTML output

Usage

import { analyzeCode, checkDuplicates, checkDeadCode, checkStructure } from './skills/code-dedup/src/index.js'; // Comprehensive analysis const result = await analyzeCode('./src', { analyses: ['dedup', 'deadCode', 'structure'] }); console.log(result.summary); // { status: 'success', filesAnalyzed: 42, issuesFound: 15 } // Individual checks const duplicates = await checkDuplicates('./src', { minSimilarity: 0.85 }); const deadCode = await checkDeadCode('./src', { ignoreExports: true }); const structure = await checkStructure('./src', { maxComplexity: 10 });

CLI Options

# Custom similarity threshold node src/cli.js analyze ./src --min-similarity 0.9 # Specific analyses node src/cli.js analyze ./src --analyses dedup,deadCode # JSON output node src/cli.js analyze ./src --format json --output report.json # Custom config node src/cli.js analyze ./src --max-complexity 8 --max-function-length 30

Configuration

Duplicate Detection

  • minLines: Minimum lines (default: 5)
  • minSimilarity: Similarity 0-1 (default: 0.85)
  • ignoreWhitespace: Ignore whitespace (default: true)
  • ignoreComments: Ignore comments (default: true)

Dead Code Detection

  • ignoreExports: Ignore exports (default: true)
  • ignoreTestFiles: Ignore tests (default: true)
  • whitelistPatterns: Symbol patterns to ignore

Structure Analysis

  • maxComplexity: Max cyclomatic complexity (default: 10)
  • maxFunctionLength: Max lines per function (default: 50)
  • maxParameters: Max parameters (default: 5)

Output Format

{ "summary": { "status": "success", "filesAnalyzed": 42, "issuesFound": 15, "durationMs": 234 }, "results": { "duplicates": [...], "deadCode": [...], "structure": {...} }, "recommendations": [...] }

Performance

  • Small (<100 files): <2s
  • Medium (100-1K files): <10s
  • Large (>1K files): <30s

Supported Languages

  • JavaScript (ES6+)
  • TypeScript
  • JSX/TSX
  • Python (experimental)

Documentation

See SKILL.md for complete documentation.

Integration

CI/CD Pipeline

- name: Check code quality run: node src/cli.js analyze ./src --format json --output report.json

Pre-commit Hook

{ "husky": { "hooks": { "pre-commit": "node src/cli.js analyze ./src" } } }

License

MIT - see LICENSE.txt

Part of the Agent Skills Ecosystem

Visit skills.sh to discover more skills for AI agents.

五维分析
清晰度9/10
创新性7/10
实用性9/10
完整性8/10
可维护性8/10
优缺点分析

优点

  • 使用MinHash LSH快速检测重复代码。
  • 全面的死代码分析。
  • 支持多种输出格式。
  • 轻松集成到CI/CD管道中。

缺点

  • 仅限于特定语言。
  • 对Python的支持仍在实验阶段。
  • 对于初学者,配置可能较复杂。
  • 性能可能因项目大小而异。

相关技能

ccmp

A
toolCo-Pilot / 辅助式
86/ 100

“看起来很能打,但别让配置把人劝退。”

claude-mods

A
toolCo-Pilot / 辅助式
86/ 100

“看起来很能打,但别让配置把人劝退。”

agentic-qe

A
toolCo-Pilot / 辅助式
86/ 100

“看起来很能打,但别让配置把人劝退。”

免责声明:本内容来源于 GitHub 开源项目,仅供展示和评分分析使用。

版权归原作者所有 xiaodong-wu.