Skip to main content

๐Ÿ”ง Multi-language code analyzer and auto-fixer with Docker sandbox support

Project description

Pactfix

PyPI version Python versions License Downloads Tests

๐Ÿ”ง Multi-language code analyzer and auto-fixer with Docker sandbox support

Pactfix automatically detects and fixes issues in 24+ languages and formats including Bash, Python, Docker, Kubernetes, Terraform, and more. Perfect for code quality, CI/CD pipelines, and development workflows.

โœจ Key Features

  • ๐ŸŽฏ Auto-fix issues - Automatically correct common problems
  • ๐Ÿณ Docker sandbox - Test fixes in isolated environments
  • ๐Ÿงช Run tests - Execute tests after applying fixes
  • ๐Ÿ“ฆ Project-wide - Scan entire codebases at once
  • ๐Ÿ” 24+ languages - From Bash to Kubernetes YAML
  • ๐Ÿ“ Detailed reports - JSON output for CI/CD integration

๐Ÿš€ Quick Install

pip install pactfix

Requires Python 3.10+

๐Ÿ“– Basic Usage

Fix a Single File

# Analyze only
pactfix script.sh

# Fix and save to new file
pactfix script.sh -o fixed.sh

# Fix with explanatory comments
pactfix script.sh --comment -o fixed.sh

Fix Entire Projects

# Fix all files in place with comments
pactfix --path ./my-project --comment

# Create fixed copies in .pactfix/ directory
pactfix --path ./my-project

Docker Sandbox Testing

# Test fixes in Docker container
pactfix --path ./my-project --sandbox

# Test and run tests in container
pactfix --path ./my-project --sandbox --test

๐Ÿ”ง Language Examples

Bash/Shell

# Input
echo "$(ssh user@host cmd") >> file

# Fixed
echo "$(ssh user@host cmd)" >> file  # โœ… Fixed quote position

Python

# Input
def func(items=[]):
    print "hello"

# Fixed
def func(items=None):  # โœ… Avoid mutable defaults
    if items is None:
        items = []
    print("hello")  # โœ… Use print() function

Dockerfile

# Input
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install python3

# Fixed
FROM ubuntu:22.04  # โœ… Use specific version
RUN apt-get update && apt-get install -y python3 && rm -rf /var/lib/apt/lists/*  # โœ… Combine & cleanup

Docker Compose

# Input
services:
  web:
    image: nginx:latest
    privileged: true

# Fixed
services:
  web:
    image: nginx:1.25  # โœ… Versioned image
    # privileged: true  # โœ… Removed for security

Kubernetes

# Input
apiVersion: apps/v1
kind: Deployment
spec:
  template:
    spec:
      containers:
      - name: app
        image: nginx:latest

# Fixed
apiVersion: apps/v1
kind: Deployment
spec:
  template:
    spec:
      containers:
      - name: app
        image: nginx:1.25  # โœ… Versioned image
        resources:  # โœ… Added resource limits
          limits:
            cpu: 500m
            memory: 512Mi

Terraform

# Input
resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"
  access_key    = "AKIAIOSFODNN7EXAMPLE"
}

# Fixed
resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"
  access_key    = var.access_key  # โœ… Use variable
}

variable "access_key" {
  description = "AWS access key"
  type        = string
  sensitive   = true
}

๐Ÿ” Supported Languages

Language Status Features
Bash/Shell โœ… Full Syntax fixes, quoting, error handling
Python โœ… Full Python 3 fixes, best practices
Dockerfile โœ… Full Security, best practices
Docker Compose โœ… Full Version pinning, security
Kubernetes โœ… Full Resource limits, security
Terraform โœ… Full Security, variables, tagging
GitHub Actions โœ… Full Best practices
GitLab CI โœ… New Syntax, best practices
Jenkinsfile โœ… New Declarative pipeline fixes
SQL โœ… Full Syntax, security
Nginx โœ… Full Best practices
Ansible โœ… Full Best practices
And 10+ more ๐Ÿšง In Progress Various config formats

๐Ÿ“Š CI/CD Integration

GitHub Actions

- name: Run Pactfix
  run: |
    pip install pactfix
    pactfix --path ./src --json > pactfix-report.json
    
- name: Upload Report
  uses: actions/upload-artifact@v3
  with:
    name: pactfix-report
    path: pactfix-report.json

Pre-commit Hook

# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: pactfix
        name: pactfix
        entry: pactfix
        language: system
        args: [--comment]
        types: [text]

๐Ÿ› ๏ธ Advanced Options

# Force specific language
pactfix script.py -l python

# Verbose output
pactfix --path ./src --verbose

# JSON output for automation
pactfix script.sh --json

# Batch analyze directory
pactfix --batch ./config

# Generate Dockerfiles
pactfix --init-dockerfiles ./dockerfiles/

# List all supported languages
pactfix --list-languages

๐Ÿ“ Output Formats

Console Output

โœ… script.sh: 3 errors, 2 warnings, 5 fixes [bash]
โŒ Line 5: [SC1073] Misplaced quote
โš ๏ธ  Line 10: [SC2086] Unquoted variable
๐Ÿ“‹ Line 5: Fixed quote position
๐Ÿ“‹ Line 10: Added quotes around variable

JSON Output

{
  "language": "bash",
  "errors": [
    {
      "line": 5,
      "code": "SC1073",
      "message": "Misplaced quote",
      "severity": "error"
    }
  ],
  "fixes": [
    {
      "line": 5,
      "description": "Fixed quote position",
      "before": "echo \"$(cmd\")",
      "after": "echo \"$(cmd)\""
    }
  ],
  "fixedCode": "..."
}

๐Ÿงช Testing

Pactfix includes comprehensive tests:

# Run all tests
pytest

# Run specific language tests
pytest tests/test_bash.py

# Run with coverage
pytest --cov=pactfix

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide.

๐Ÿ“„ License

Apache License 2.0 - see LICENSE for details.

๐Ÿ”— Links


Built with โค๏ธ by the Pactown team

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

pactfix-1.0.6.tar.gz (76.6 kB view details)

Uploaded Source

Built Distribution

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

pactfix-1.0.6-py3-none-any.whl (91.9 kB view details)

Uploaded Python 3

File details

Details for the file pactfix-1.0.6.tar.gz.

File metadata

  • Download URL: pactfix-1.0.6.tar.gz
  • Upload date:
  • Size: 76.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pactfix-1.0.6.tar.gz
Algorithm Hash digest
SHA256 0c07ec8de736fd56d3ae81ab0274c9199b9aaa4764a8a7cff9329821fe22016c
MD5 3710f6c3d834076d5e91f5793387bfbe
BLAKE2b-256 c31a4a0c60d52b8cff29c4b67e25c8fd597b57fa75965249d715eb55f45e2e81

See more details on using hashes here.

File details

Details for the file pactfix-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: pactfix-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 91.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pactfix-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2552612ddd38dbe32d48e3e5e57da4c738cc88767a2e77e08f89268afa867d0e
MD5 adb09014f2d3804c518ad0f9503dbeb4
BLAKE2b-256 d4c98f7dd052310ec8f033a064b35d8e3da9e8c9e749d804942b85f633e0945f

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