Skip to main content

A CLI tool for static code analysis and fixing using Gemini AI

Project description

SDLC-Automation

Graduation project - CLI Backend for Static Issue Analysis and Fixing

Overview

This project provides a command-line interface (CLI) tool called ejd that helps developers analyze and fix static issues in their code using configurable rule sets and LLM integration.

Installation

pip install -e .

Usage

Basic Command Structure

ejd -si fix "path/to/your/file.py"

Interactive Workflow

  1. Run the command with your source file path
  2. The tool will prompt you to enter a rule set file path
  3. Both files are validated and loaded into variables
  4. The data is prepared for LLM processing

Example Usage

# Fix static issues in a Python file
ejd -si fix "src/main.py"

# The tool will then prompt:
# 📋 Please enter the path to the rule set file: rules/python_rules.txt

Features

  • ✅ File validation for both source and rule set files
  • 🔧 Interactive rule set path input with validation
  • 💾 Automatic loading of file contents into variables
  • 🤖 Ready-to-use data structure for LLM integration
  • � Non-destructive workflow - creates fixed files while preserving originals
  • �🚀 Extensible architecture for future enhancements

Gemini Flash 2.5 Integration

This tool is integrated with Google's Gemini Flash 2.5 model for intelligent static code analysis and automated fixing.

Setup

  1. Install dependencies (automatically handled during installation):

    pip install -e .
    
  2. Get your Gemini API key:

  3. Configure the API key (choose one method):

    Option A: Using the setup script (Recommended)

    python setup_gemini.py
    

    Option B: Manual configuration

    # Create a .env file in the project root
    echo "GOOGLE_API_KEY=your_actual_api_key_here" > .env
    

    Option C: Environment variable

    # Windows PowerShell
    $env:GOOGLE_API_KEY="your_actual_api_key_here"
    
    # Windows CMD
    set GOOGLE_API_KEY=your_actual_api_key_here
    

How It Works

  1. Analysis: Gemini analyzes your source code against the provided rules
  2. Issue Detection: Identifies code quality, security, and performance issues
  3. Automated Fixing: Generates corrected code that addresses all issues
  4. Interactive Review: Shows you what issues were found and asks for confirmation before applying fixes

Example Analysis Results

The tool provides detailed analysis including:

  • Issues Found: Line-by-line breakdown of problems
  • Issue Types: Code quality, security vulnerabilities, performance issues
  • Rule Violations: Which specific rules were violated
  • Fixed Code: Complete corrected version of your code
  • Best Practice Suggestions: Additional recommendations for improvement
  • Markdown Report: Comprehensive analysis saved as a formatted markdown file

Markdown Report Features

Each analysis generates a detailed markdown report with:

  • Structured Summary: Overview of all changes and improvements
  • Issues Table: Organized table with line numbers, types, descriptions, and violated rules
  • Complete Fixed Code: Full corrected source code in syntax-highlighted blocks
  • Additional Suggestions: Best practice recommendations and improvement tips
  • Timestamped Documentation: Generated date/time and source file information

Reports are automatically saved with timestamps (e.g., test_file_analysis_report_20251017_153045.md) for easy tracking and review.

Sample Output

🤖 Preparing to send data to Gemini Flash 2.5...
🔗 Testing connection to Gemini...
✅ Connected to Gemini successfully!
🎉 Analysis completed successfully!
📊 Issues found: 8
📄 Detailed markdown report saved to: test_file_analysis_report_20251017_153045.md

🐛 Issues identified:
   1. Line 2: Unused import 'sys' - Remove unused imports
   2. Line 15: SQL injection vulnerability - Use parameterized queries
   3. Line 25: Missing type hints - Add type annotations for better code clarity
   4. Line 30: Class name should be capitalized - Follow PEP 8 naming conventions
   5. Line 45: Use list comprehension for better performance

� Preview of fixed code (first 200 characters):
   # Fixed Python file - all static issues resolved
   import os
   import requests
   from typing import List, Optional
   import sqlite3
   
   def calculate_total(items: List[int]) -> int:...

�💡 Would you like to create a fixed version? (y/n): y
✅ Fixed version created: test_file-fixed.py
📁 Original file preserved: test_file.py
📝 Summary: Fixed 8 issues including security vulnerabilities and code quality improvements

💡 Additional suggestions:
   1. Consider adding docstrings to all functions and classes
   2. Use more descriptive variable names where possible
   3. Add error handling for file operations and user inputs

File Structure

ejad/
├── __init__.py
├── cli.py           # Main CLI entry point
└── static_issue.py  # Static issue fixing logic

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ejd-0.1.6.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ejd-0.1.6-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file ejd-0.1.6.tar.gz.

File metadata

  • Download URL: ejd-0.1.6.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for ejd-0.1.6.tar.gz
Algorithm Hash digest
SHA256 ac44fc04ca37c199832ef05688736f76445b49cb9a24ce9d45591ed1796a5752
MD5 c3533c26284d8413d2838ccdd211d6f1
BLAKE2b-256 1ee19d5cc6468b7f4dedca912a5573cfc0db63b84c39f4e400366d3b878ee8f2

See more details on using hashes here.

File details

Details for the file ejd-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: ejd-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for ejd-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 feb7a848bd544a9774b232479a958d14700dc2bee6bdf66c6e0002c09e15537e
MD5 8fc7810e69193ca4f8a14cde7e16325e
BLAKE2b-256 bfc53570113f00c98d90d7f97e5aae9801bf5a7101d81b9ed56b285da4d452f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page