A tool to analyze code files and identify commented code/functions.
Detects commented-out HTML code blocks (<!-- -->)
- Reports: Files with commented code, comment size, ratios
- Use: Find dead HTML pages or large comment blocks
Detects commented-out functions (class methods and standalone)
- Reports: Files with commented functions, function names
- Use: Find dead PHP code and unused functions
Detects commented-out code in JavaScript/TypeScript files
- Reports: Files with commented blocks (multi-line
/* */and single-line//) - Use: Find unused logic and technical debt in frontend code
Detects unresolved Git merge conflict markers (<<<<<<<, =======, >>>>>>>)
- Reports: Files with conflict markers, line numbers
- Use: Find files pushed with unresolved merge conflicts
- Note: May detect some false positives in CSS/comment decorators
# Build
cd scripts/code-analyzer
go build -o code-analyzer
# Run (uses analysis-config.yaml by default)
./code-analyzer
# Run with custom config
./code-analyzer -config=my-config.yamlAll configuration is managed via the analysis-config.yaml file.
./code-analyzer./code-analyzer -config=staging-config.yamlThe analysis-config.yaml file controls all settings:
dir: "api" # Root directory to scan
output: "artifacts/analysis" # Output directory for JSON reports
gitlab_report: "gl-report.json" # Optional GitLab Code Quality report path
analyzers:
html:
enabled: true
min: 100 # Minimum bytes to report
min_ratio: 10 # Minimum comment ratio %
top: 50 # Top N files to report
sort: "ratio" # "ratio" or "bytes"
exclude: ["test", "backup"]
php:
enabled: true
min: 1 # Minimum commented functions
min_ratio: 0
top: 50
exclude: ["vendor", "tests"]
js:
enabled: true
top: 50
conflicts:
enabled: true| Flag | Default | Description |
|---|---|---|
-config |
analysis-config.yaml |
Path to YAML configuration file |
docker build -t code-analyzer .docker run --rm -v $(pwd):/app/data code-analyzerA GitHub Actions workflow (.github/workflows/docker-publish.yml) is included to build and publish the container image to GHCR on pushes to main.
Run standard Go tests:
go test ./... -vThe project uses golangci-lint for static analysis. A workflow (.github/workflows/lint.yml) runs this on every push.
The tool can generate a GitLab-compatible Code Quality report.
code-quality:
stage: test
image: ghcr.io/pixelvide/code-analyzer:latest
script:
- /app/code-analyzer -config=/app/analysis-config.yaml
artifacts:
reports:
codequality: gl-code-quality-report.json
paths:
- artifacts/*.json
- gl-code-quality-report.json
expire_in: 30 daysEnsure analysis-config.yaml has gitlab_report set to the desired output path.
scripts/code-analyzer/
βββ main.go # Entry point and CLI
βββ go.mod # Go module definition
βββ analyzers/
β βββ analyzer.go # Analyzer interface (contract)
β βββ html/ # HTML analyzer
β βββ php/ # PHP analyzer
β βββ js/ # JS/TS analyzer
β βββ conflicts/ # Conflicts analyzer
βββ models/ # Data structures
βββ utils/ # Shared utilities
βββ Dockerfile # Container definition
- Analyzer Interface: Defines the
Run(config)contract. - Rules: Each analyzer contains specific rules (e.g.,
CommentedCodeRule,CommentedFunctionsRule). - Configuration: Loaded from YAML, supporting per-analyzer settings.
- Create
analyzers/newlang/newlang.go. - Implement the
Analyzerinterface. - Register it in
main.go.
- Define a struct implementing the
Ruleinterface. - Add logic in
Apply(content string). - Register the rule in the Analyzer's
New...Analyzerfunction.