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
Metadata
Release files for pactfix 1.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pactfix-1.0.8.tar.gz | 68.4 kB | Without provenance | Details for pactfix-1.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pactfix-1.0.8-py3-none-any.whl | Python 3 | none | any | Details for pactfix-1.0.8-py3-none-any.whl |
Total release size: 308.4 kB
Release files / pactfix-1.0.8.tar.gz
| Download URL | pactfix-1.0.8.tar.gz |
|---|---|
| Size | 68.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5581364e763d434b9d2ea6472f8a1916dd5ce83f5323e9ed2e4ad2f646cefdea
|
|
BLAKE2b-256 checksum How to use checksums |
a1772e9a9c2b83aa3c5dc634544f8c8b43d2678f3e91e4d8e65da88240fbe5ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / pactfix-1.0.8-py3-none-any.whl
| Download URL | pactfix-1.0.8-py3-none-any.whl |
|---|---|
| Size | 240.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b3eefa4356852853f8540913fa60855d58eb011895441f70e61b211212d55aab
|
|
BLAKE2b-256 checksum How to use checksums |
b3dd8f82cdb48b56eb4f959c6b2b637278e293557177a8e4735941ec23d52515
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for pactfix 1.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.