codeguard-cli
v1.0.0
Published
A lightweight, zero-dependency Node.js CLI tool for code cleanliness and risk analysis
Downloads
5
Maintainers
Readme
🔍 CodeGuard
Code Cleanliness & Risk Analysis Tool
CodeGuard is a lightweight, zero-dependency Node.js CLI tool that detects code quality issues and security risks in your projects.
✨ Features
- 🔍 Smart Code Scanning: Finds risky code like TODO, FIXME, eval(), console.log
- 📊 Risk Scoring: Assigns 1-10 risk scores to each issue
- 📈 Detailed Reports: JSON, HTML, and console reports
- 🚀 Zero Dependency: No external dependencies required
- ⚡ Fast: Quick scanning even for large projects
- 🎯 Multi-Language Support: JavaScript, TypeScript, Python, Java, C++ and more
🚀 Installation
# Install globally
npm install -g codeguard-cli
# Or use npx
npx codeguard-cli scan
# Or clone and install locally
git clone https://github.com/erencanucarr/codeguard-cli.git
cd codeguard-cli
npm link📖 Usage
Basic Usage
# Scan current directory
codeguard scan
# Scan specific directory
codeguard scan --path ./src
# Generate JSON report
codeguard scan --output json --file my-report
# Generate HTML report
codeguard scan --output html --file security-report
# Set minimum risk threshold
codeguard scan --risk-threshold 5Command Options
| Option | Description | Default |
|--------|-------------|---------|
| -p, --path <path> | Path to scan | . (current directory) |
| -o, --output <format> | Output format (json, html, console) | console |
| -f, --file <filename> | Report filename | codeguard-report |
| --ignore <patterns> | Ignore patterns (comma-separated) | node_modules,dist,build,.git |
| --risk-threshold <number> | Minimum risk score (0-10) | 3 |
| -h, --help | Show help message | - |
🎯 Risk Scores
| Score | Level | Examples |
|-------|-------|----------|
| 10 | 🔴 Critical | eval(), require('fs'), exec() |
| 8 | 🟠 High | TODO, FIXME, any, @ts-ignore |
| 6 | 🟡 Medium | console.log, debugger, alert() |
| 4 | 🔵 Low | eslint-disable, prettier-ignore |
| 2 | ⚪ Info | NOTE, INFO, WARNING |
📊 Detected Risks
🔴 Critical Security Risks (10 points)
eval()usagerequire('fs')file system accessrequire('child_process')system commandsexec()usageinnerHTMLXSS riskdocument.write()XSS risk
🟠 High Risks (8 points)
// TODO- Incomplete code// FIXME- Code needs fixing// HACK- Temporary solution// BUG- Known issueany- TypeScript any usage@ts-ignore- TypeScript ignorepassword =- Password variableapi_key =- API key variablesecret =- Secret variable
🟡 Medium Risks (6 points)
console.log()- Should be removed in productionconsole.error()- Error logsconsole.warn()- Warning logsdebugger;- Debug statementalert()- User experience issueconfirm()- Confirmation dialogsprompt()- Input dialogs
🔵 Low Risks (4 points)
// eslint-disable- ESLint disable// @ts-nocheck- TypeScript check disable// prettier-ignore- Prettier disable// stylelint-disable- Stylelint disable
📁 Supported File Types
- JavaScript:
.js,.jsx - TypeScript:
.ts,.tsx - Vue/Svelte:
.vue,.svelte - Python:
.py - Java:
.java - C/C++:
.c,.cpp - C#:
.cs - PHP:
.php - Ruby:
.rb - Go:
.go - Rust:
.rs - Swift:
.swift - Kotlin:
.kt - Scala:
.scala
📈 Sample Outputs
Console Report
📊 CodeGuard Report
Date: 2024-01-15T10:30:00.000Z
Path: ./src
Files Scanned: 25
Total Issues: 12
Risk Score: 78
📈 Summary:
🔴 Critical: 2
🟠 High: 5
🟡 Medium: 3
🔵 Low: 2
⚪ Info: 0
📁 File Details:
./src/utils.js (3 issues, 24 points)
🟠 Line 15:1 - TODO comment - incomplete code
// TODO: Optimize this function
🟡 Line 42:1 - console.log usage - should be removed in production
console.log('Debug info:', data);
🔴 Line 67:1 - eval() usage - security risk
eval(userInput);HTML Report
The HTML report provides a modern and interactive interface:
- 📊 Statistics cards
- 📈 Risk summary charts
- 📁 File-based detailed analysis
- 🎨 Color-coded risk levels
🔧 Configuration
Git Hooks Integration
Add to .git/hooks/pre-commit:
#!/bin/sh
echo "🔍 Running CodeGuard scan..."
codeguard scan --risk-threshold 5
if [ $? -ne 0 ]; then
echo "❌ CodeGuard found issues. Commit aborted."
exit 1
fi
echo "✅ CodeGuard scan passed."CI/CD Integration
GitHub Actions example:
name: CodeGuard Analysis
on: [push, pull_request]
jobs:
codeguard:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm install -g codeguard-cli
- run: codeguard scan --output json --file ci-report
- name: Upload report
uses: actions/upload-artifact@v3
with:
name: codeguard-report
path: ci-report.json🤝 Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📝 License
This project is licensed under the MIT License. See the LICENSE file for details.
🙏 Acknowledgments
- All contributors
- Open source community
- Projects that inspired code quality tools
Keep your code clean and secure with CodeGuard! 🚀
