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-watchergo mod tidygo run main.go scan <path> [-o output.json]Example:
go run main.go scan ./ -o data/functions.jsonThis 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.jsonIt 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.txtLists 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.txtInstall 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