A powerful CLI tool for Go developers to scan, detect, and prevent duplicated or unused functions in your codebase.
Designed for code quality automation, especially useful in team collaboration, code review, and CI/CD pipelines.
- โ Detect all exported functions in a directory
- ๐ Compare old and new snapshots to find duplicated or similar functions
- ๐งน Detect unused functions that are defined but never called
- ๐ซ Ignore list support to skip known functions or third-party calls
- ๐ค GitHub CI/CD & PR auto-comment support
git clone https://github.com/ak4bento/code-function-watcher.git
cd code-function-watcher
go mod tidy
go run main.go scan <path> [-o output.json]
Example:
go run main.go scan ./ -o data/functions.json
This will scan all Go files recursively and extract exported function names + locations.
go run main.go compare <old.json> <new.json>
Example:
go run main.go compare data/functions-old.json data/functions-new.json
It will print potentially duplicated or very similar functions with similarity percentage (e.g., 94.5%).
go run main.go unused <path> --defined <functions.json> [--ignore ignore.txt]
Example:
go run main.go unused ./ --defined data/functions.json --ignore ignore.txt
Lists exported functions that were never called anywhere in your project.
Use a plain text file (e.g. ignore.txt
) to exclude functions from being detected as "unused":
log.Println
fmt.Errorf
main
Create a file .github/workflows/scan.yml
:
name: Code Function Watcher
on:
pull_request:
paths:
- '**/*.go'
jobs:
scan:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.21
- name: Install Dependencies
run: go mod tidy
- name: Run Function Comparison
run: |
go run main.go scan ./ -o data/functions-new.json
go run main.go compare data/functions-old.json data/functions-new.json > result.txt
- name: Upload Results
uses: actions/upload-artifact@v3
with:
name: compare-result
path: result.txt
Install peter-evans/create-or-update-comment
Extend your workflow:
- name: Post PR Comment
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
๐ **Function Comparison Report**
```
$(cat result.txt)
```
.
โโโ cmd/
โ โโโ compare.go
โ โโโ scan.go
โ โโโ unused.go
โโโ pkg/
โ โโโ compare/
โ โโโ exporter/
โ โโโ scanner/
โ โโโ unused/
โโโ data/
โ โโโ functions-old.json
โ โโโ functions-new.json
โโโ ignore.txt
โโโ main.go
Made with โค๏ธ by @ak4bento