๐ง Multi-language code analyzer and auto-fixer with Docker sandbox support
Project description
Pactfix
๐ง 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c07ec8de736fd56d3ae81ab0274c9199b9aaa4764a8a7cff9329821fe22016c
|
|
| MD5 |
3710f6c3d834076d5e91f5793387bfbe
|
|
| BLAKE2b-256 |
c31a4a0c60d52b8cff29c4b67e25c8fd597b57fa75965249d715eb55f45e2e81
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2552612ddd38dbe32d48e3e5e57da4c738cc88767a2e77e08f89268afa867d0e
|
|
| MD5 |
adb09014f2d3804c518ad0f9503dbeb4
|
|
| BLAKE2b-256 |
d4c98f7dd052310ec8f033a064b35d8e3da9e8c9e749d804942b85f633e0945f
|