Metadata-Version: 2.4
Name: codeXglitch
Version: 1.0.1
Summary: Lightweight, offline static code analysis tool for Python
Author-email: CHANDU SR <chhhanduuu@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/chandusrchandusr5-droid/codeXglitch
Project-URL: Bug Tracker, https://github.com/chandusrchandusr5-droid/codeXglitch/issues
Keywords: static-analysis,security,linter,ast,python,code-quality
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Security
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# codeXglitch 🔍

[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Analysis: AST--Based](https://img.shields.io/badge/Analysis-AST--Based-brightgreen.svg)]()
[![Offline: 100%](https://img.shields.io/badge/Offline-100%25-success.svg)]()

**codeXglitch** is a lightweight, 100% offline static code analysis library for Python. It parses Python Abstract Syntax Trees (AST) to detect security vulnerabilities, logic errors, code smells, and performance bottlenecks—without requiring cloud services or external dependencies.

---

## ✨ Key Features

- 🛡️ **100% Offline Security & Code Analysis**: Operates locally with zero network calls or API dependencies.
- ⚡ **Lightning Fast (AST-Based)**: Parses native Python Abstract Syntax Trees in milliseconds.
- 🔒 **Security Vulnerability Detection**: Catch `eval()`/`exec()` usage, hardcoded API secrets, `shell=True` command injection, unsafe YAML loaders, and insecure temp files.
- 🧠 **Logic Error Scanner**: Detect literal division by zero, bare `except:` clauses, unreachable/redundant conditions, and boolean comparison anti-patterns.
- 🚀 **Performance Smell Detection**: Highlight deeply nested O(N³) loops and overly verbose functions.
- 🖥️ **CLI & Python API**: Use via terminal command-line tool or import directly into Python applications.

---

## 🚀 Quick Start

### 1. Installation

Install locally in editable mode or build standard distribution wheel:

```bash
git clone https://github.com/chandusrchandusr5-droid/codeXglitch.git
cd codeXglitch
pip install .
```

### 2. Command Line Interface (CLI)

Run static analysis on any file or directory:

```bash
# Analyze a single file
codexglitch my_script.py

# Analyze an entire project directory
codexglitch ./src

# Generate & analyze a sample test file
codexglitch --sample

# Export results as structured JSON
codexglitch ./src --json
```

---

## 📋 Rule Reference

| Category | Rule ID | Description | Severity |
| :--- | :--- | :--- | :--- |
| **SECURITY** | `SEC001` | Use of dangerous `eval()` or `exec()` functions | `HIGH` |
| **SECURITY** | `SEC002` | Subprocess invocation with `shell=True` | `HIGH` |
| **SECURITY** | `SEC003` | Potential hardcoded API keys, tokens, or passwords | `HIGH` |
| **SECURITY** | `SEC004` | Insecure `tempfile.mktemp()` usage | `MEDIUM` |
| **SECURITY** | `SEC005` | Unsafe `yaml.load()` without explicit `Loader` | `HIGH` |
| **LOGIC** | `LOG001` | Division or modulo by literal zero | `HIGH` |
| **LOGIC** | `LOG002` | Bare `except:` catching system-level exceptions | `MEDIUM` |
| **LOGIC** | `LOG003` | Redundant `if True:` or unreachable `if False:` | `LOW` / `MEDIUM` |
| **LOGIC** | `LOG004` | Boolean comparison anti-pattern (`x == True`) | `LOW` |
| **LOGIC** | `LOG005` | Return statement inside `finally:` block | `HIGH` |
| **PERFORMANCE** | `PERF001` | Deeply nested loops (3+ nesting levels) | `MEDIUM` |
| **PERFORMANCE** | `PERF004` | Function line count exceeds 50 lines | `LOW` |

---

## 🐍 Python API Usage

You can also use `codeXglitch` directly inside your Python scripts or CI pipelines:

```python
from codexglitch import scan_code, scan_file, CodeAnalyzer

# Scan inline source code
code = """
def calculate():
    secret_key = "sk_live_123456789"
    return 100 / 0
"""

findings = scan_code(code)

for item in findings:
    print(f"[{item['severity']}] Line {item['line']}: {item['message']}")
    print(f"  Suggestion: {item['suggestion']}")
```

---

## 🧪 Running Unit Tests

Run the test suite to verify AST rules and analyzer execution:

```bash
python -m unittest discover tests
```

---

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
