Skip to main content

AST-based code consistency checker and fixer using pure algorithms

Project description

AX - AST-Based Code Consistency Checker

Keep your codebase consistent across multiple languages using pure algorithmic analysis

AX is an intelligent code consistency checker and fixer that helps maintain consistent coding patterns across your entire project. It uses pure AST-based analysis with advanced algorithms to identify inconsistencies, logical errors, security issues, and performance problems.

Features

  • Cross-File Consistency Analysis: Learns patterns from your project and ensures consistency
  • Multi-Language Support: Python, JavaScript, TypeScript, Java, Go, Rust, and more
  • Pure AST Analysis: Uses abstract syntax tree parsing for reliable detection
  • Auto-Fix Capabilities: Automatically fixes issues with configurable confidence thresholds
  • Logical Error Detection: Finds bugs like missing operators, unreachable code, infinite loops
  • Security Scanning: Detects hardcoded secrets, SQL injection risks, unsafe deserialization
  • Performance Analysis: Identifies N+1 queries, inefficient loops, unnecessary conversions
  • Interactive Fixes: Review and approve fixes with diff preview
  • Project-Wide Learning: Automatically detects and enforces your team's coding patterns
  • Fast and Efficient: Pure algorithmic approach with caching for speed

What AX Checks

Consistency Issues

  • Naming conventions (snake_case vs camelCase)
  • None/Null checking patterns (is None vs == None)
  • Type hint usage consistency
  • Error handling patterns (exceptions vs return values)
  • Import styles
  • String quote preferences
  • Docstring conventions

Logical Errors

  • Missing augmented operators (x = x + 1 vs x += 1)
  • Incorrect comparisons
  • Unreachable code after return/raise
  • Infinite loops without break
  • Loop variable modifications
  • Missing return statements
  • Unused variables
  • Off-by-one errors

Security Issues

  • Hardcoded secrets (API keys, passwords, tokens)
  • SQL injection vulnerabilities
  • Command injection risks
  • Unsafe deserialization (pickle)
  • Weak cryptography (MD5, SHA1)
  • Unsafe eval/exec usage
  • Missing file encoding

Performance Problems

  • N+1 query patterns
  • Inefficient loops (list comprehension opportunities)
  • Repeated expensive computations
  • Inefficient string concatenation
  • Unnecessary type conversions
  • Missing caching opportunities

Installation

For Users (PyPI)

pip install axcode

After installation, the ax command will be available globally.

For Development

# Clone the repository
git clone https://github.com/CAVELAB-HK/AX.git
cd AX

# Install in development mode
pip install -e .

# Install development dependencies
pip install -e ".[dev]"

Quick Start

1. Install

pip install axcode

2. Verify Installation

ax --help

3. Analyze and Fix Your Code

# Analyze and fix a single file
ax myfile.py

# Analyze and fix entire project
ax .

# Just analyze without fixing
ax myfile.py --analyze-only

# Auto-fix all high-confidence issues
ax myfile.py --auto

# Fix specific directory recursively
ax ./src --recursive

# Output results as JSON
ax myfile.py --json

4. Use in Your IDE (Optional)

Install the VS Code or Cursor extension for real-time feedback:

  • VS Code: Search "AX Consistency" in the marketplace
  • Cursor: See extensions documentation (if available)

Usage

CLI Commands

# Analyze and fix files
ax <file_or_directory>        # Analyze and fix interactively
ax <file> --auto              # Auto-fix high-confidence issues
ax <file> --analyze-only      # Just analyze without fixing
ax <file> --json              # Output results in JSON format

# Options
ax <directory> -r             # Recursive (default: true)
ax . --include "*.py"         # Include specific patterns
ax . --exclude "test_*.py"    # Exclude specific patterns

Python API

from pathlib import Path
from ax.core import AnalysisPipeline, FixExecutor

# Initialize pipeline
pipeline = AnalysisPipeline(use_cache=True)

# Analyze a file
project_files = list(Path('.').rglob('*.py'))
result = pipeline.analyze_file(Path('myfile.py'), project_files)

# Generate and apply fixes
issues = result['issues']
fixes = pipeline.generate_fixes(Path('myfile.py'), issues)

executor = FixExecutor()
fix_result = executor.execute_fixes(Path('myfile.py'), fixes, auto=False)

print(f"Found {result['issue_count']} issues")
print(f"Applied {len(fix_result.get('changes', []))} fixes")

Configuration File

Create .axconfig.toml in your project root:

[analysis]
enabled_strategies = [
    "naming",
    "type_hints",
    "imports",
    "docstrings",
    "error_handling",
    "logical_errors",
    "security",
    "performance"
]
auto_fix_threshold = 0.9
interactive_threshold = 0.6
ignore_patterns = [
    "__pycache__/*",
    "*.pyc",
    ".git/*",
    "venv/*",
    "node_modules/*"
]

[cache]
enabled = true
directory = ".ax_cache"

[output]
format = "terminal"
colors = true
verbose = false

Examples

Before AX

def processData(data):
    if data == None:
        return
    total = 0
    password = "secret123"
    for item in items:
        total = total + item
    return total

After AX Fix

def process_data(data):
    if data is None:
        return
    total = 0
    password = os.getenv('PASSWORD')
    for item in items:
        total += item
    return total

IDE Extensions

VS Code Extension

  1. Install from marketplace: "AX Consistency"
  2. Or install manually: code --install-extension extensions/vscode-ax/ax-consistency-1.0.0.vsix
  3. Configure in settings (Cmd/Ctrl + ,):
    • ax.enabled: Enable/disable extension
    • ax.autoCheckOnSave: Check files on save
    • ax.autoFix: Automatically fix issues

Keyboard Shortcuts:

  • Cmd/Ctrl + Shift + A: Analyze current file
  • Cmd/Ctrl + Shift + F: Fix current file

Cursor Extension

See extensions/cursor-ax/INSTALL_CURSOR.md for installation instructions.

Architecture

AX uses a pure AST-based architecture:

  1. AST Parsing: Uses abstract syntax tree parsing for reliable pattern detection
  2. Pattern Learning: Learns dominant patterns from your project automatically
  3. Strategy System: Pluggable strategies for different types of checks (naming, logical errors, security, performance)
  4. Smart Caching: Caches results to avoid redundant analysis
  5. Fix Generation: Generates fixes with confidence scores for safe automated fixes

Development

Project Structure

AX/
├── ax/                      # Core package
│   ├── cli/                # CLI interface
│   ├── core/               # Core analysis engine
│   │   ├── pipeline.py     # AST-based pipeline
│   │   ├── parser.py       # AST parser
│   │   ├── fix_executor.py # Fix application engine
│   │   └── pattern_learner.py  # Pattern detection
│   ├── strategies/         # Analysis strategies
│   │   ├── naming.py
│   │   ├── logical_errors.py
│   │   ├── security.py
│   │   └── performance.py
│   ├── models/            # Data models
│   └── utils/             # Utility functions
├── extensions/             # IDE extensions
│   ├── vscode-ax/         # VS Code extension
│   └── cursor-ax/         # Cursor extension
└── tests/                 # Test suite

Running Tests

pytest tests/

Building Extensions

# VS Code extension
cd extensions/vscode-ax
npm install
npm run compile
npm run package

# Cursor extension
cd extensions/cursor-ax
npm install
npm run compile

Publishing to PyPI

First Time Setup

  1. Create accounts on PyPI and TestPyPI
  2. Install build tools:
    pip install build twine
    

Publishing Process

# 1. Update version in pyproject.toml
# 2. Build distribution
python -m build

# 3. Test on TestPyPI (optional)
python -m twine upload --repository testpypi dist/*

# 4. Publish to PyPI
python -m twine upload dist/*

After Publishing

Users can install with:

pip install ax-consistency

Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (pytest)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Troubleshooting

"AX CLI not found"

Make sure AX is installed and in your PATH:

pip install axcode
# Or for development:
pip install -e /path/to/AX

Extension Not Working

  1. Check that AX CLI is installed: ax --version
  2. Check extension settings in VS Code
  3. Restart VS Code/Cursor
  4. Check the extension output panel for errors

Analysis Too Slow

  1. Enable caching in .axconfig.toml
  2. Add ignore patterns for large dependencies
  3. Use --include flag to focus on specific file patterns

License

MIT License - see LICENSE file for details

Authors

Links

Contributing

Found a bug or have a feature request? Please open an issue on GitHub!

Acknowledgments

AX is built with:

  • Python's built-in AST module for parsing
  • Rich for beautiful terminal output
  • Typer for CLI interface
  • Advanced algorithmic analysis for reliable detection

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

axcode-0.2.2.tar.gz (43.1 kB view details)

Uploaded Source

Built Distribution

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

axcode-0.2.2-py3-none-any.whl (48.5 kB view details)

Uploaded Python 3

File details

Details for the file axcode-0.2.2.tar.gz.

File metadata

  • Download URL: axcode-0.2.2.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for axcode-0.2.2.tar.gz
Algorithm Hash digest
SHA256 cbf398a71da96ae8f5c19fd784951d1c73eb25cd7ec9bd854d7295cecf513d33
MD5 5c74cb76334ee9689b650a69cca4b426
BLAKE2b-256 f9f93c01a6fd48004cc006c858446bdf96571af02bc6dcbd9869b56540e7ad70

See more details on using hashes here.

File details

Details for the file axcode-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: axcode-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 48.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for axcode-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eeaa4aca6ebf5be792363575834c40bc417d9ac065a102104badca2dc262e5a3
MD5 c2c29b5c43377ed7e0e07bce9168beb8
BLAKE2b-256 a247a28bcd6b65372170fd623b8e3f82e4af389f06ebbf77a16c45fb301a05e6

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