DecSec2030/find-duplicates
GitHub: DecSec2030/find-duplicates
面向 TypeScript/React/Vue/Svelte 项目的结构性代码重复检测工具,通过 AST 分析识别变量名不同但结构相同的重复代码块。
Stars: 0 | Forks: 0
# 查找重复项
[](https://github.com/DecSec2030/find-duplicates/actions/workflows/test.yml)
[](https://github.com/DecSec2030/find-duplicates/releases/latest)
[](https://opensource.org/licenses/MIT)
**查找结构化代码重复项**,适用于 TypeScript、React、Vue 和 Svelte 项目 —— 即使变量名不同也能识别。使用 **Python**(参考实现)和 **Go**(零依赖二进制文件)实现。
## 功能
- 检测**结构性重复**(不仅是字符串匹配)
- 支持 **React/TS, Vue, Svelte**
- 输出格式:**text、JSON、Mermaid 图表**
- **Go 二进制文件** (3.4 MB)、**Python 二进制文件** (11 MB)、**Docker**
- 过滤选项:`--ignore-pattern`、`--min-occurrences`、`--group-by-dir`
- 跨 Python + Go 实现的 78+ 测试
## 快速开始
### Go 二进制文件 (Linux、macOS、Windows — 3.4 MB,无依赖)
```
curl -L -o find-dups https://github.com/DecSec2030/find-duplicates/releases/latest/download/find-dups-linux-amd64
chmod +x find-dups
sudo mv find-dups /usr/local/bin/
```
对于 macOS ARM:将 `linux` 替换为 `darwin`;对于 Windows:使用 `windows` + `.exe`。
### Python 独立二进制文件 (11 MB)
```
curl -L -o find-dups https://github.com/DecSec2030/find-duplicates/releases/latest/download/find-duplicates
chmod +x find-dups
sudo mv find-dups /usr/local/bin/
```
### 使用 Docker
```
docker run --rm -v "$(pwd):/workspace" -w /workspace decsec2030/find-duplicates .
```
## 用法
```
# 基本分析
find-dups .
# JSON 输出 (用于 CI/CD)
find-dups . --json | jq '.percentage'
# Mermaid 图表
find-dups . --mermaid > graph.md
# 使用选项
find-dups src/ --min-lines 3 --top 10 --ignore tests/
```
## 示例输出
### 文本
```
============================================================
DUPLICATE ANALYSIS REPORT
============================================================
Total source files: 128
Files with duplicates: 34
Duplicate-affected ratio: 26.6%
Total duplicate groups: 12
Total duplicated blocks: 48
```
### Mermaid 图表
```
graph TD
src_components_UserCard_tsx[src/components/UserCard.tsx]
src_components_ProfileCard_tsx[src/components/ProfileCard.tsx]
src_components_UserCard_tsx -->|3| src_components_ProfileCard_tsx
```
## 支持的扩展名
| 语言 | 扩展名 |
|-----------|-------------|
| TypeScript | `.ts` |
| React | `.tsx` |
| Vue | `.vue` |
| Svelte | `.svelte` |
## CLI 选项
| 标志 | 描述 |
|--------------------------|-------------------------------------------|
| `--json` | 以 JSON 格式输出报告 |
| `--mermaid` | 以 Mermaid 格式输出重复图表 |
| `--pretty` | 美化打印 JSON 输出 |
| `--min-lines N` | 最小代码块行数(默认:5) |
| `--top N` | 显示前 N 个片段(默认:5) |
| `--ignore DIRS` | 额外要忽略的目录 |
| `--no-gitignore` | 跳过 `.gitignore` 解析 |
| `--min-occurrences N` | 代码块必须重复的最小次数(默认:2)|
| `--ignore-pattern P` | 跳过包含特定模式的代码块(可重复使用)|
| `--group-by-dir` | 按目录分组统计信息 |
## 开发
### Python
```
git clone https://github.com/DecSec2030/find-duplicates.git
cd find-duplicates
pip install -e .
pip install pytest pytest-cov
pytest tests/ -v --cov=find_duplicates
```
### Go
```
cd go/find-dups
go build -o find-dups .
go test -v ./...
./find-dups -path /my/project
```
## Docker
```
docker build -t find-duplicates .
docker run --rm -v "$(pwd):/workspace" -w /workspace find-duplicates . --json
```
## 许可证
MIT
标签:EVTX分析, Go, Linux安全, LNA, Python, Ruby工具, SBOM分析, Svelte, TypeScript, Vue, 云安全监控, 代码分析, 凭证管理, 安全插件, 文件系统扫描, 无后门, 日志审计, 请求拦截, 逆向工具, 静态分析