๐๏ธ Garbage Code Hunter
A humorous Rust code quality detector that roasts your garbage code with style! ๐ฅ
Inspiration from https://github.com/Done-0/fuck-u-code.git
Unlike traditional linters that give you dry, boring warnings, Garbage Code Hunter delivers sarcastic, witty, and brutally honest feedback about your code quality. It's like having a sassy code reviewer who isn't afraid to hurt your feelings (in a good way).
โจ Features
- ๐ญ Humorous Code Analysis: Get roasted with style while learning better coding practices
- ๐ Multi-language Support: Available in English and Chinese (more languages coming soon!)
- ๐ฏ Smart Detection: Identifies common code smells and anti-patterns
- ๐ Professional Reports: Generate detailed analysis reports in multiple formats
- ๐ง Highly Configurable: Customize output, filtering, and analysis depth
- ๐ Markdown Export: Perfect for documentation and CI/CD integration
- ๐ Fast & Lightweight: Built with Rust for maximum performance
๐ฏ Scoring System
Garbage Code Hunter includes a comprehensive scientific scoring system that evaluates your Rust code quality on a scale of 0-100, where:
- Lower scores = Better code quality ๐
- Higher scores = More problematic code ๐
๐ Score Ranges & Quality Levels
| Score Range | Quality Level | Emoji | Description |
|---|---|---|---|
| 0-20 | Excellent | ๐ | Outstanding code quality with minimal issues |
| 21-40 | Good | ๐ | Good code quality with minor improvements needed |
| 41-60 | Average | ๐ | Average code quality with room for improvement |
| 61-80 | Poor | ๐ | Poor code quality, refactoring recommended |
| 81-100 | Terrible | ๐ | Critical code quality issues, rewrite urgently needed |
๐งฎ Scoring Algorithm
The scoring system uses a multi-factor algorithm that considers:
1. Base Score Calculation
Each detected issue contributes to the base score using:
Issue Score = Rule Weight ร Severity Weight
2. Rule Weights (Impact Factor)
Different types of issues have different weights based on their impact:
| Category | Rule | Weight | Rationale |
|---|---|---|---|
| Safety Critical | unsafe-abuse |
5.0 | Memory safety violations |
| FFI Critical | ffi-abuse |
4.5 | Foreign function interface risks |
| Runtime Critical | unwrap-abuse |
4.0 | Potential panic sources |
| Architecture | lifetime-abuse |
3.5 | Complex lifetime management |
| Async/Concurrency | async-abuse |
3.5 | Async pattern misuse |
| Complexity | deep-nesting |
3.0 | Code maintainability |
| Performance | unnecessary-clone |
2.0 | Runtime efficiency |
| Readability | terrible-naming |
2.0 | Code comprehension |
3. Severity Weights
Issues are classified by severity with corresponding multipliers:
- Nuclear (๐ฅ): 10.0ร - Critical issues that can cause crashes or security vulnerabilities
- Spicy (๐ถ๏ธ): 5.0ร - Serious issues affecting maintainability or performance
- Mild (๐): 2.0ร - Minor issues with style or best practices
4. Density Penalties
Additional penalties based on issue concentration:
-
Issue Density: Problems per 1000 lines of code
- >50 issues/1000 lines: +25 penalty
- >30 issues/1000 lines: +15 penalty
- >20 issues/1000 lines: +10 penalty
- >10 issues/1000 lines: +5 penalty
-
File Complexity: Average issues per file
- >20 issues/file: +15 penalty
- >10 issues/file: +10 penalty
- >5 issues/file: +5 penalty
5. Severity Distribution Penalties
Extra penalties for problematic patterns:
- Nuclear Issues: First nuclear issue +20, each additional +5
- Spicy Issues: After 5 spicy issues, each additional +2
- Mild Issues: After 20 mild issues, each additional +0.5
๐ Metrics Included
The scoring system provides detailed metrics:
- Total Score: Overall code quality score (0-100)
- Category Scores: Breakdown by issue categories
- Issue Density: Problems per 1000 lines of code
- Severity Distribution: Count of nuclear/spicy/mild issues
- File Count: Number of analyzed Rust files
- Total Lines: Total lines of code analyzed
๐ฏ Interpretation Guide
For Excellent Code (0-20):
- Minimal issues detected
- Strong adherence to Rust best practices
- Good architecture and safety patterns
For Good Code (21-40):
- Few minor issues
- Generally well-structured
- Minor optimizations possible
For Average Code (41-60):
- Moderate number of issues
- Some refactoring beneficial
- Focus on complexity reduction
For Poor Code (61-80):
- Significant issues present
- Refactoring strongly recommended
- Address safety and complexity concerns
For Terrible Code (81-100):
- Critical issues requiring immediate attention
- Consider rewriting problematic sections
- Focus on safety, correctness, and maintainability
๐ฌ Scientific Approach
The scoring system is designed to be:
- Objective: Based on measurable code metrics
- Weighted: Critical issues have higher impact
- Contextual: Considers code size and complexity
- Actionable: Provides specific improvement areas
- Consistent: Reproducible results across runs
๐ช What It Detects
Naming Disasters
- Terrible variable names (
data,temp,info,obj) - Single-letter variables (except common loop counters)
- Generic meaningless identifiers
Code Structure Issues
- Deep nesting (Russian doll syndrome)
- Overly long functions
- Complex conditional logic
Rust-Specific Anti-patterns
unwrap()abuse (panic bombs ๐ฃ)- Unnecessary
clone()calls (memory waste) - Poor error handling patterns
๐ Installation
From Source
Using Cargo
๐ Usage
Basic Usage
# Analyze current directory
# Analyze specific file or directory
# Use make targets for convenience
Language Options
# Chinese output (default)
# English output
Advanced Options
# Verbose analysis with top 3 problematic files
# Only show summary
# Generate Markdown report
# Exclude files/directories
# Show only serious issues
๐จ Sample Output
English Mode
๐๏ธ Garbage Code Hunter ๐๏ธ
Preparing to roast your code...
๐ Code Quality Report
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Found some areas for improvement:
๐ Issue Statistics:
1 ๐ฅ Nuclear Issues (fix immediately)
138 ๐ถ๏ธ Spicy Issues (should fix)
34 ๐ Mild Issues (can ignore)
173 ๐ Total
๐ Code Quality Score
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Score: 60.9/100 ๐
๐ฏ Level: Average
๐ Lines of Code: 260
๐ Files: 1
๐ Issue Density: 66 issues/1k lines
๐ญ Issue Distribution:
๐ฅ Nuclear: 1
๐ถ๏ธ Spicy: 138
๐ Mild: 34
๐ Files with Most Issues
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1. func.rs (173 issues)
๐ func.rs
๐ฆ Nesting depth issues: 20 (depth 4-9)
๐ Code duplication issues: 9 (6 instances)
๐ท๏ธ Variable naming issues: 128 (a, b, c, d, e, ...)
๐ท๏ธ Variable naming issues: 13 (a, b, c, d, e, ...)
โ ๏ธ long function: 1
๐ Scoring Details
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Category Scores:
โ ๐ท๏ธ Naming 90 Terrible, urgent fixes needed
๐ฌ Congrats! Variables harder to understand than comments ๐
โ ๐งฉ Complexity 90 Terrible, urgent fixes needed
๐ฌ Complexity off the charts! Even AI gave up ๐ค
โ ๐ Duplication 90 Terrible, urgent fixes needed
๐ฌ Suggest renaming to ctrl-c-ctrl-v.rs ๐
โโ ๐ฆ Rust Basics 0 Excellent, keep it up
โโ โก Advanced Rust 0 Excellent, keep it up
โข ๐ Rust Features 69 Poor, refactoring recommended
๐ฌ More macros than my excuses ๐ญ
โโ ๐๏ธ Code Structure 0 Excellent, keep it up
๐งฎ Weighted Calculation:
Score calculation: (90.0ร0.25 + 90.0ร0.20 + 90.0ร0.15 + 0.0ร0.15 + 0.0ร0.10 + 69.4ร0.10 + 0.0ร0.05) รท 1.00 = 60.9
๐ Scoring Scale (higher score = worse code):
๐ 81-100: Terrible ๐ฅ 61-80: Poor โ ๏ธ 41-60: Average
โ
21-40: Good ๐ 0-20: Excellent
๐ Summary
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Average code quality, Score: 60.9/100, room for improvement
Found some serious issues, suggest fixing nuclear problems first ๐ฅ
๐ก Suggestions
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ก Use meaningful variable names that make code self-documenting (e.g., user_count instead of data)
๐ฏ Variable names should describe what they store, not the data type
๐ง Reduce nesting levels, consider extracting functions or using early returns (guard clauses)
๐๏ธ Complex conditional logic can be split into multiple small functions
โ๏ธ Split long functions into smaller ones, follow the single responsibility principle
๐ A function should ideally not exceed 20-30 lines for better understanding and testing
๐ Extract common code into functions to follow the DRY principle
๐๏ธ Consider creating utility functions or modules for repeated logic
Keep working hard to make your code better! ๐
Chinese Mode
๐๏ธ ๅๅพไปฃ็ ็ไบบ ๐๏ธ
ๆญฃๅจๅๅคๅๆงฝไฝ ็ไปฃ็ ...
๐ ๅๅพไปฃ็ ๆฃๆตๆฅๅ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
ๅ็ฐไบไธไบ้่ฆๆน่ฟ็ๅฐๆน๏ผ
๐ ้ฎ้ข็ป่ฎก:
1 ๐ฅ ๆ ธๅผน็บง้ฎ้ข (้่ฆ็ซๅณไฟฎๅค)
138 ๐ถ๏ธ ่พฃ็ผ็้ฎ้ข (ๅปบ่ฎฎไฟฎๅค)
34 ๐ ่ฝปๅพฎ้ฎ้ข (ๅฏไปฅๅฟฝ็ฅ)
173 ๐ ๆป่ฎก
๐ ไปฃ็ ่ดจ้่ฏๅ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ ๆปๅ: 60.9/100 ๐
๐ฏ ็ญ็บง: ไธ่ฌ
๐ ไปฃ็ ่กๆฐ: 260
๐ ๆไปถๆฐ้: 1
๐ ้ฎ้ขๅฏๅบฆ: 66 ้ฎ้ข/ๅ่ก
๐ญ ้ฎ้ขๅๅธ:
๐ฅ ๆ ธๅผน็บง: 1
๐ถ๏ธ ไธฅ้: 138
๐ ่ฝปๅพฎ: 34
๐ ้ฎ้ขๆๅค็ๆไปถ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1. func.rs (173 issues)
๐ func.rs
๐ฆ ๅตๅฅๆทฑๅบฆ้ฎ้ข: 20 (deep nesting)
๐ ไปฃ็ ้ๅค้ฎ้ข: 9 (20 instances)
๐ท๏ธ ๅ้ๅฝๅ้ฎ้ข: 128 (a, b, c, d, e, ...)
๐ท๏ธ ๅ้ๅฝๅ้ฎ้ข: 13 (a, b, c, d, e, ...)
โ ๏ธ long function: 1
๐ ่ฏๅ่ฏฆๆ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ ๅ็ฑป่ฏๅ่ฏฆๆ
:
โ ๐ท๏ธ ๅฝๅ่ง่ 90ๅ ็ณ็ณ๏ผๆฅ้ไฟฎๅค
๐ฌ ๆญๅ๏ผไฝ ๆๅ่ฎฉๅ้ๅๆฏๆณจ้่ฟ้พๆ ๐
โ ๐งฉ ๅคๆๅบฆ 90ๅ ็ณ็ณ๏ผๆฅ้ไฟฎๅค
๐ฌ ๅคๆๅบฆ็่กจ๏ผ่ฟAI้ฝ็ไธๆไบ ๐ค
โ ๐ ไปฃ็ ้ๅค 90ๅ ็ณ็ณ๏ผๆฅ้ไฟฎๅค
๐ฌ ๅปบ่ฎฎๆนๅไธบcopy-paste.rs ๐
โโ ๐ฆ Rustๅบ็ก 0ๅ ไผ็ง๏ผ็ปง็ปญไฟๆ
โโ โก ้ซ็บง็นๆง 0ๅ ไผ็ง๏ผ็ปง็ปญไฟๆ
โข ๐ Rustๅ่ฝ 69ๅ ่พๅทฎ๏ผๅปบ่ฎฎ้ๆ
๐ฌ ๅฎๅฎไนๆฏๆ็ๅๅฃ่ฟๅค ๐ญ
โโ ๐๏ธ ไปฃ็ ็ปๆ 0ๅ ไผ็ง๏ผ็ปง็ปญไฟๆ
๐งฎ ๅ ๆ่ฎก็ฎ:
่ฏๅ่ฎก็ฎ: (90.0ร0.25 + 90.0ร0.20 + 90.0ร0.15 + 0.0ร0.15 + 0.0ร0.10 + 69.4ร0.10 + 0.0ร0.05) รท 1.00 = 60.9
๐ ่ฏๅๆ ๅ (ๅๆฐ่ถ้ซไปฃ็ ่ถ็):
๐ 81-100: ็ณ็ณ ๐ฅ 61-80: ่พๅทฎ โ ๏ธ 41-60: ไธ่ฌ
โ
21-40: ่ฏๅฅฝ ๐ 0-20: ไผ็ง
๐ ๆป็ป
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ ไปฃ็ ่ดจ้ไธ่ฌ๏ผ่ฏๅ: 60.9/100๏ผ่ฟๆๆน่ฟ็ฉบ้ด
ๅ็ฐไบไธไบไธฅ้้ฎ้ข๏ผๅปบ่ฎฎไผๅ
ไฟฎๅคๆ ธๅผน็บง้ฎ้ข ๐ฅ
๐ก ๆน่ฟๅปบ่ฎฎ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ก ไฝฟ็จๆๆไน็ๅ้ๅ๏ผ่ฎฉไปฃ็ ่ช่งฃ้๏ผๆฏๅฆ็จ user_count ่ไธๆฏ data๏ผ
๐ฏ ๅ้ๅๅบ่ฏฅๆ่ฟฐๅฎๅญๅจ็ๅ
ๅฎน๏ผ่ไธๆฏๆฐๆฎ็ฑปๅ
๐ง ๅๅฐๅตๅฅๅฑๆฐ๏ผ่่ๆๅๅฝๆฐๆไฝฟ็จๆฉๆ่ฟๅ๏ผguard clauses๏ผ
๐๏ธ ๅคๆ็ๆกไปถ้ป่พๅฏไปฅๆๅๆๅคไธชๅฐๅฝๆฐ
โ๏ธ ๅฐ้ฟๅฝๆฐๆๅๆๅคไธชๅฐๅฝๆฐ๏ผ้ตๅพชๅไธ่่ดฃๅๅ
๐ ไธไธชๅฝๆฐๆๅฅฝไธ่ถ
่ฟ 20-30 ่ก๏ผ่ฟๆ ทๆดๅฎนๆ็่งฃๅๆต่ฏ
็ปง็ปญๅชๅ๏ผ่ฎฉไปฃ็ ๅๅพๆดๅฅฝ๏ผ๐
๐ ๏ธ Command Line Options
| Option | Short | Description |
|---|---|---|
--help |
-h |
Show help message |
--verbose |
-v |
Show detailed analysis report |
--top N |
-t N |
Show top N files with most issues (default: 5) |
--issues N |
-i N |
Show N issues per file (default: 5) |
--summary |
-s |
Only show summary conclusion |
--markdown |
-m |
Output Markdown format report |
--lang LANG |
-l LANG |
Output language (zh-CN, en-US) |
--exclude PATTERN |
-e PATTERN |
Exclude file/directory patterns |
--harsh |
Show only the worst offenders |
๐ง Development
Prerequisites
- Rust 1.70 or later
- Cargo
Building
# Debug build
# Release build
# Run tests
# Format code
# Run linter
Running Demo
This creates a sample file with intentionally bad code and runs the analyzer on it.
๐ฏ Examples
CI/CD Integration
# GitHub Actions example
- name: Code Quality Check
run: |
cargo install garbage-code-hunter
garbage-code-hunter --markdown --lang en-US src/ > quality-report.md
# Upload report as artifact or comment on PR
Pre-commit Hook
#!/bin/bash
# .git/hooks/pre-commit
if [; then
fi
๐ค Contributing
We welcome contributions! Here's how you can help:
- Add New Rules: Implement additional code smell detection
- Language Support: Add translations for more languages
- Improve Messages: Make the roasts even funnier (but still helpful)
- Documentation: Help improve docs and examples
- Bug Reports: Found a bug? Let us know!
Adding New Detection Rules
- Create a new rule in
src/rules/ - Implement the
Ruletrait - Add humorous messages in
src/i18n.rs - Add tests
- Submit a PR!
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Inspired by the need for more entertaining code reviews
- Built with โค๏ธ and a lot of โ
- Thanks to all the developers who write garbage code (we've all been there!)
๐ Links
Remember: The goal isn't to shame developers, but to make code quality improvement fun and memorable. Happy coding! ๐