Skip to content

goinboxme/universal_code_validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌟 Universal Code Validator v3.0

Python Version License Platform Code Quality

Comprehensive code quality analyzer untuk ANY Python project dengan Role-Aware Validation

Universal Code Validator adalah tool analisis kode Python yang menggunakan AST (Abstract Syntax Tree) untuk mendeteksi masalah kualitas kode secara mendalam. Yang membuatnya unik adalah kemampuan Role-Aware Validation yang secara otomatis mendeteksi apakah kode Anda adalah SCRIPT, ENGINE, atau FRAMEWORK, lalu menyesuaikan metrik validasi sesuai konteks.

πŸ“± Cross-Platform Ready!

Bekerja di Desktop (Windows/Linux/macOS) dan Android (Pydroid 3/Termux) - No external dependencies!

✨ Fitur Utama

🎯 Role-Aware Validation (NEW in v3.0)

  • Deteksi otomatis peran kode: SCRIPT / ENGINE / FRAMEWORK dengan confidence score
  • Adaptive rule weighting - Complexity penalty disesuaikan dengan role:
    • SCRIPT: Strict validation (weight 1.0x)
    • ENGINE: Balanced approach (weight 0.6-0.7x)
    • FRAMEWORK: Lenient on complexity (weight 0.3-0.4x)
  • Context-intelligent scoring - Tidak ada false positive pada framework yang kompleks
  • Zero penalty untuk kompleksitas yang memang diperlukan (lihat: UNIVERSAL_CODE_VALIDATOR_V3.py detected as FRAMEWORK = no complexity penalty!)

πŸ” Comprehensive Analysis (AST-Based)

  • βœ… Syntax & Parsing - Deteksi error sintaks sebelum runtime
  • πŸ”’ Security Vulnerabilities - Context-aware (no false positives dari comments/strings)
    • exec() detection dengan severity scoring
    • Command injection patterns
    • Path traversal vulnerabilities
    • Pickle usage warnings
  • πŸ“Š Complexity Metrics - Role-normalized scoring
    • Cyclomatic complexity (per function)
    • Cognitive complexity (human readability)
    • Max nesting depth detection
  • ⚑ Performance Issues - Deteksi bottleneck potensial
    • Inefficient loops
    • Repeated operations
    • Memory-intensive patterns
  • πŸ“ Code Quality - PEP 8 & best practices
    • Function/class length violations
    • Parameter count warnings
    • Code duplication hints
  • πŸ“– Documentation Coverage - Docstring analysis
    • Missing docstrings detection
    • Comment ratio calculation
  • 🚫 Anti-patterns - Deteksi code smell
    • Empty except blocks ⭐ (see output: detects all empty excepts!)
    • God objects
    • Dead code
  • πŸ”§ Maintainability Index - Halstead metrics calculation

πŸ“ˆ Advanced Metrics

  • Cyclomatic Complexity: Independent code paths
  • Cognitive Complexity: Mental effort to understand
  • Maintainability Index: 0-100 scale (calculated per file)
  • Documentation Coverage: Percentage of documented code
  • Security Risk Score: Weighted by role
  • Role Classification Confidence: 0-100%

πŸš€ Deployment Features

  • βœ… Zero Dependencies - Pure Python stdlib only
  • βœ… Cross-Platform - Windows/Linux/macOS/Android
  • βœ… Interactive Mode - Perfect untuk mobile (no CLI args needed)
  • βœ… Batch Processing - Analyze multiple files at once
  • βœ… Real-time Progress - Streaming output saat analysis
  • βœ… Multiple Report Formats - Console + HTML + JSON

πŸš€ Quick Start

Instalasi

πŸ–₯️ Desktop (Windows/Linux/macOS)

# Clone repository
git clone https://github.com/goinboxme/universal-code-validator.git
cd universal-code-validator

# Tidak perlu dependency eksternal - Pure Python!
python UNIVERSAL_CODE_VALIDATOR_V3.py

πŸ“± Android (Pydroid 3 / Termux)

# Di Termux
pkg install python git
git clone https://github.com/goinboxme/universal-code-validator.git
cd universal-code-validator
python UNIVERSAL_CODE_VALIDATOR_V3.py

# Di Pydroid 3
# Download file UNIVERSAL_CODE_VALIDATOR_V3.py
# Buka di Pydroid 3 dan run!

Penggunaan

Mode 1: Command Line Arguments

# Analyze single file
python UNIVERSAL_CODE_VALIDATOR_V3.py myfile.py

# Analyze entire directory
python UNIVERSAL_CODE_VALIDATOR_V3.py /path/to/project

# Analyze current directory (where the script is located)
python UNIVERSAL_CODE_VALIDATOR_V3.py .

Mode 2: Interactive Menu (Perfect untuk Android!)

# Run tanpa arguments untuk menu interaktif
python UNIVERSAL_CODE_VALIDATOR_V3.py

# Anda akan melihat:
╔════════════════════════════════════════════════════════════════╗
β•‘           🌟 UNIVERSAL CODE VALIDATOR v3.0.0 🌟              β•‘
β•‘                                                               β•‘
β•‘     Analyze ANY Python code without prior knowledge           β•‘
β•‘   Now with ROLE-AWARE VALIDATION - Context-Intelligent!      β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Usage options:
  1. Analyze single file:    python validator.py myfile.py
  2. Analyze directory:      python validator.py /path/to/project
  3. Analyze current dir:    python validator.py .

Enter file or directory path (or '.' for current): 

# Ketik '.' untuk scan folder saat ini
# Atau ketik nama file: mycode.py
# Atau ketik path lengkap: /sdcard/projects/myapp.py

πŸ“Š Output & Reports

Validator menghasilkan 3 jenis output:

1. Real-time Console Output (Streaming Progress)

πŸ” Scanning for Python files in: .
πŸ“ Found 13 Python file(s)

================================================================================
πŸ”¬ ANALYZING FILES
================================================================================

[1/13] Analyzing: ENGINEERING_MASTER.py
    🎯 Detected Role: SCRIPT (confidence: 70%)
    🟠 2 HIGH priority issue(s)
    πŸ“Š Maintainability: 40.0/100

[2/13] Analyzing: AI_CTE_ASSIST.py
    🎯 Detected Role: SCRIPT (confidence: 70%)
    βœ… No issues found
    πŸ“Š Maintainability: 61.0/100

[11/13] Analyzing: UNIVERSAL_CODE_VALIDATOR_V3.py
    🎯 Detected Role: FRAMEWORK (confidence: 100%)
    πŸ“Š Maintainability: 39.6/100

================================================================================
πŸ“Š ANALYSIS SUMMARY
================================================================================

πŸ“ Project: .
πŸ“… Timestamp: 2026-02-07T18:59:22
πŸ†• Validator Version: 3.0.0
πŸ“ Files Analyzed: 13
πŸ“ Total Lines: 14,968

🎯 Role Distribution:
   FRAMEWORK: 3 file(s) (23%)
   SCRIPT: 10 file(s) (77%)

🎯 Overall Score: 31.6/100 (Role-Normalized)
πŸ† Grade: D - NEEDS IMPROVEMENT

πŸ› Issues Found:
   Total: 322
   πŸ”΄ Critical: 2
   🟠 High: 18

πŸ“Š Metrics:
   Functions: 521
   Classes: 108
   Avg Complexity: 3.68
   Avg Maintainability: 42.7/100

πŸ”’ Security: 11 issue(s)
⚑ Performance: 27 issue(s)
πŸ”„ Complexity: 101 issue(s)

================================================================================
🎯 ROLE-SPECIFIC INSIGHTS
================================================================================

πŸ“„ MINI_AI_AGENT_V6.py
   Role: SCRIPT (confidence: 70%)
   Expected Complexity: LOW
   Actual Complexity: 44.0
   Verdict: ABOVE expected range
   Reasoning:
     β€’ SCRIPT: Linear utility/helper code
     β€’ Simple structure (45 functions, 4 classes)
     β€’ LOC: 1281
   Issues (role-adjusted): 18

πŸ“„ UNIVERSAL_CODE_VALIDATOR_V3.py
   Role: FRAMEWORK (confidence: 100%)
   Expected Complexity: HIGH
   Actual Complexity: 21.0
   Verdict: WITHIN expected range βœ…
   Reasoning:
     β€’ FRAMEWORK: Meta-analyzer/orchestrator pattern detected
     β€’ Multiple visitor/analyzer patterns detected (11)
     β€’ Very high max complexity (21)
   Issues (role-adjusted): 69

================================================================================
πŸ”΄ TOP CRITICAL/HIGH ISSUES
================================================================================

πŸ”΄ CRITICAL Security Vulnerability
   πŸ“„ MINI_AI_AGENT_V5.py:631
   ❗ Using exec() can execute arbitrary code
   βš–οΈ  Role-adjusted weight: 0.8x
   πŸ’‘ Refactor to avoid exec()

🟠 HIGH Anti-pattern
   πŸ“„ AI_PATTERN_ANALYZER.py:250
   ❗ Empty except block silently ignores errors
   πŸ’‘ Log the error or handle it appropriately

================================================================================
πŸ’‘ RECOMMENDATIONS
================================================================================

πŸ”΄ URGENT: Fix critical issues immediately!
πŸ”’ Security: Address 11 security issue(s)

βœ… Next Steps:
   1. Review the HTML report in your browser
   2. Check role classifications - are they accurate?
   3. Fix critical and high priority issues first
   4. Run the validator again to track improvements

================================================================================
✨ Analysis Complete!
================================================================================

2. HTML Report (Interactive Dashboard)

  • πŸ“Š Visual dashboard dengan role distribution chart
  • πŸ“„ Per-file role analysis dengan confidence score
  • 🎨 Color-coded issue severity (Critical/High/Medium/Low)
  • βš–οΈ Role-adjusted weight indicators
  • πŸ’‘ Detailed metrics & actionable suggestions
  • πŸ–₯️ Dapat dibuka di browser desktop atau Android

File generated: code_analysis_YYYYMMDD_HHMMSS.html

3. JSON Report (Machine-readable)

{
  "project_path": ".",
  "timestamp": "2026-02-07T18:59:22",
  "validator_version": "3.0.0",
  "total_files": 13,
  "total_lines": 14968,
  "role_distribution": {
    "FRAMEWORK": 3,
    "SCRIPT": 10
  },
  "overall_score": 31.6,
  "critical_issues": 2,
  "high_issues": 18,
  "file_analyses": [...]
}

File generated: code_analysis_YYYYMMDD_HHMMSS.json

  • βœ… Perfect untuk CI/CD integration
  • βœ… Easy parsing untuk automated workflows
  • βœ… Version control friendly

🎯 Role Classification Explained

SCRIPT (Linear Utilities)

  • Karakteristik: Simple, sequential logic
  • Contoh: CLI tools, helper scripts, utilities
  • Validasi: Strict pada complexity & maintainability

ENGINE (Logic-Heavy Systems)

  • Karakteristik: State management, complex algorithms
  • Contoh: Data processors, game engines, business logic
  • Validasi: Balanced approach, fokus pada security

FRAMEWORK (Meta-Analyzers)

  • Karakteristik: Visitor patterns, high abstraction
  • Contoh: Code analyzers, compilers, orchestrators
  • Validasi: Lenient pada complexity, strict pada security

πŸ“‹ Requirements

  • Python 3.7+
  • No external dependencies! (Pure Python standard library)
  • Platform: Linux, Windows, macOS, Android (Termux/Pydroid 3)

βœ… Tested On:

  • βœ… Ubuntu 20.04+ / Debian / Fedora
  • βœ… Windows 10/11
  • βœ… macOS 11+ (Big Sur and later)
  • βœ… Android 7+ with Termux
  • βœ… Android 7+ with Pydroid 3

πŸ“± Android-Specific Tips

Termux Setup

# Install Python dan Git
pkg update && pkg upgrade
pkg install python git

# Clone dan run
git clone https://github.com/goinboxme/universal-code-validator.git
cd universal-code-validator
python UNIVERSAL_CODE_VALIDATOR_V3.py .

Pydroid 3 Setup

  1. Download UNIVERSAL_CODE_VALIDATOR_V3.py dari GitHub
  2. Simpan di folder yang sama dengan kode Anda
  3. Buka di Pydroid 3
  4. Tap Run (▢️)
  5. Input: ketik . untuk scan folder saat ini

Path Tips untuk Android

# Current directory (recommended)
.

# Specific file in same folder
mycode.py

# Internal storage
/sdcard/projects/myapp.py

# Termux home
/data/data/com.termux/files/home/projects/

# Pydroid 3 directory
/storage/emulated/0/Pydroid/

Viewing HTML Reports on Android

# Setelah analysis selesai:
# File: code_analysis_YYYYMMDD_HHMMSS.html

# Cara 1: File Manager
# Buka dengan Chrome/Firefox/browser apapun

# Cara 2: Termux (with termux-open)
pkg install termux-tools
termux-open code_analysis_*.html

# Cara 3: Share file HTML ke desktop via:
# - Google Drive / Dropbox
# - Email attachment
# - USB transfer

πŸ› οΈ Configuration

Edit THRESHOLDS dan ROLE_WEIGHTS di dalam script untuk menyesuaikan:

THRESHOLDS = {
    'max_function_length': 50,
    'max_class_length': 300,
    'max_cyclomatic_complexity': 10,
    'max_cognitive_complexity': 15,
    'max_nesting_depth': 4,
    'max_parameters': 5,
    'min_maintainability_index': 20,
    'min_comment_ratio': 0.10,
    'min_docstring_coverage': 0.50,
}

πŸ’‘ Use Cases

1. Mobile Development on Android ⭐

# Di Termux atau Pydroid 3
python UNIVERSAL_CODE_VALIDATOR_V3.py .

# Perfect untuk:
# - Learning Python on the go
# - Quick code quality checks
# - Coding practice validation
# - Portfolio project assessment

2. Pre-commit Hook (Desktop)

# .git/hooks/pre-commit
#!/bin/bash
python UNIVERSAL_CODE_VALIDATOR_V3.py . --json-only
if [ $? -ne 0 ]; then
    echo "Code quality check failed!"
    exit 1
fi

3. CI/CD Integration

# .github/workflows/code-quality.yml
- name: Code Quality Check
  run: |
    python UNIVERSAL_CODE_VALIDATOR_V3.py . --json-only

4. Code Review Automation (Desktop/Android)

# Desktop: Review specific files
git diff --name-only main | grep '\.py$' | xargs python UNIVERSAL_CODE_VALIDATOR_V3.py

# Android: Quick check before committing
python UNIVERSAL_CODE_VALIDATOR_V3.py mychanged_file.py

5. Learning & Education

# Perfect untuk mahasiswa/pelajar yang coding di Android
# - Check homework assignments
# - Validate practice exercises
# - Learn best practices
# - Prepare for code reviews

πŸ“Έ Screenshots

Console Output

Console Analysis

HTML Report

HTML Dashboard

Role Classification

Role Analysis

🀝 Contributing

Contributions are welcome! Silakan:

  1. Fork repository ini
  2. Buat feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add some AmazingFeature')
  4. Push ke branch (git push origin feature/AmazingFeature)
  5. Buka Pull Request

πŸ“ Changelog

v3.0.0 (Latest)

  • ✨ NEW: Role-Aware Validation system
  • ✨ NEW: Adaptive rule weighting
  • ✨ NEW: Context-intelligent scoring
  • πŸ› Fixed: Zero false positives on framework complexity

v2.1

  • ✨ Context-aware security scanning (AST-based)
  • πŸ› Eliminated false positives from strings/comments
  • πŸ› Duplicate issue detection prevention

v2.0

  • Complete rewrite with AST-based analysis
  • Added multiple report formats
  • Enhanced metric calculations

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspired by tools like pylint, flake8, and radon
  • Built with Python's powerful ast module
  • Thanks to the open-source community

πŸ“§ Contact

⭐ Star History

If you find this project useful, please consider giving it a star!

❓ FAQ

Q: Bisa dijalankan di Android?

A: Ya! 100% compatible dengan Termux dan Pydroid 3. Tidak perlu root atau dependencies eksternal.

Q: Apakah perlu install library tambahan?

A: Tidak sama sekali. Pure Python standard library - langsung run!

Q: Apa bedanya dengan pylint/flake8?

A:

  • βœ… Role-aware validation (unique feature!)
  • βœ… Zero dependencies vs puluhan dependencies
  • βœ… Cross-platform termasuk Android
  • βœ… Context-intelligent scoring
  • βœ… Interactive mode untuk mobile

Q: File HTML report tidak bisa dibuka di Android?

A: Bisa! Gunakan file manager, pilih file HTML, buka dengan Chrome/Firefox. Atau gunakan termux-open di Termux.

Q: Kenapa script saya dapat score rendah?

A: Check "Role Classification" - jika salah deteksi (misal: ENGINE detected as SCRIPT), complexity penalty jadi terlalu tinggi. Ini normal untuk code yang memang complex by design.

Q: Apa arti "role-adjusted weight"?

A: Ini multiplier yang diterapkan ke severity issue berdasarkan role:

  • SCRIPT: 1.0x (full penalty)
  • ENGINE: 0.6-0.7x (reduced penalty)
  • FRAMEWORK: 0.3-0.5x (minimal penalty)

Q: Bisa analyze project dengan 1000+ files?

A: Ya, tapi butuh waktu. Untuk project besar, consider analyze per module/package.

Q: Report JSON untuk apa?

A: Untuk:

  • CI/CD automation
  • Trend tracking (compare JSON across commits)
  • Custom dashboard integration
  • Automated quality gates

Q: Confidence 70% vs 100% itu artinya?

A:

  • 100% = Pasti (detected visitor pattern, high complexity)
  • 70% = Probably (default untuk simple scripts)
  • Lower confidence = might need manual review

Made with ❀️ and Python - Runs Everywhere!

Releases

No releases published

Packages

 
 
 

Contributors

Languages