Skip to main content

A minimal-dependency Python linter for detecting and fixing misaligned ASCII art boxes in documentation

Project description

ascii-guard

Zero-dependency Python linter for detecting and fixing misaligned ASCII art boxes in documentation.

License Python CI codecov Code style: ruff Type checked: mypy PRs Welcome


๐ŸŽฏ Why ascii-guard?

AI-generated ASCII flowcharts and diagrams often have subtle formatting errors where box borders are misaligned by 1-2 characters. This breaks visual integrity and makes documentation harder to read.

ascii-guard automatically detects and fixes these alignment issues, ensuring your ASCII art looks perfect.

โœจ Key Features

  • ๐Ÿš€ Minimal dependencies - Zero for Python 3.11+, one tiny dep for Python 3.10 (tomli)
  • ๐Ÿ’พ Tiny footprint - Lightweight and fast
  • ๐Ÿ”’ Minimal supply chain risk - Pure stdlib on 3.11+
  • โšก Quick startup - No import overhead
  • ๐Ÿ“ฆ Simple installation - One command, automatic dependency handling
  • ๐Ÿ›ก๏ธ Type-safe - Full mypy strict mode
  • โœ… Well tested - Comprehensive test coverage

๐Ÿ“ฆ Installation

For Users (AI Agents)

pip install ascii-guard

That's it! No other dependencies needed.

For Developers

# Clone repository
git clone https://github.com/fxstein/ascii-guard.git
cd ascii-guard

# Set up development environment (creates venv, installs dev deps)
./setup-venv.sh

# Activate virtual environment
source .venv/bin/activate

# Install pre-commit hooks
pre-commit install

๐Ÿš€ Quick Start

Check files for ASCII art issues

ascii-guard lint README.md
ascii-guard lint docs/**/*.md

Auto-fix alignment issues

ascii-guard fix README.md
ascii-guard fix --dry-run docs/guide.md  # Preview changes first

Example

Before (misaligned):

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Box Content         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ† Missing one character!

After (fixed):

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Box Content         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ† Perfect alignment โœ“

๐ŸŽจ Supported Box-Drawing Characters

ascii-guard supports Unicode box-drawing characters:

Type Characters Description
Horizontal โ”€ (U+2500) Horizontal line
Vertical โ”‚ (U+2502) Vertical line
Corners โ”Œ โ” โ”” โ”˜ Standard corners
T-junctions โ”œ โ”ค โ”ฌ โ”ด Connection points
Cross โ”ผ Four-way intersection
Heavy lines โ” โ”ƒ โ” โ”“ โ”— โ”› Bold variants
Double lines โ• โ•‘ โ•” โ•— โ•š โ• Double-line variants

๐Ÿ› ๏ธ Development

Project Structure

ascii-guard/
โ”œโ”€โ”€ src/ascii_guard/    # Source code (ZERO dependencies)
โ”‚   โ”œโ”€โ”€ __init__.py     # Package initialization
โ”‚   โ”œโ”€โ”€ cli.py          # CLI interface (argparse only)
โ”‚   โ””โ”€โ”€ core.py         # Linting logic (stdlib only)
โ”œโ”€โ”€ tests/              # Test suite (pytest)
โ”œโ”€โ”€ docs/               # Documentation
โ””โ”€โ”€ pyproject.toml      # Project configuration

Running Tests

# Run all tests with coverage
pytest

# Run specific test file
pytest tests/test_cli.py

# Run with verbose output
pytest -v

# Fast tests only (pre-commit)
pytest -m "not slow"

Linting and Type Checking

# Run all pre-commit hooks
pre-commit run --all-files

# Run linter only
ruff check .

# Run formatter
ruff format .

# Run type checker
mypy src/

Virtual Environment Isolation

ascii-guard uses strict virtual environment isolation to ensure minimal system pollution:

# Development dependencies are isolated in .venv/
# Runtime has minimal dependencies:
#   - Python 3.11+: Zero dependencies (uses stdlib tomllib)
#   - Python 3.10: One dependency (tomli for TOML config)
# All tools (ruff, mypy, pytest) are dev-only

# Verify minimal runtime dependencies
python -c "import ascii_guard; print('Success - no imports failed')"

๐Ÿ“‹ Validation Rules

ascii-guard checks for:

  1. Vertical alignment - All โ”‚ characters in a column align
  2. Horizontal alignment - All โ”€ characters connect properly
  3. Corner correctness - Corner characters match adjacent lines
  4. Width consistency - Top, middle, and bottom borders match
  5. Content fit - Content stays within box borders

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Development Setup

  1. Fork and clone the repository
  2. Run ./setup-venv.sh to set up your environment
  3. Make your changes
  4. Run tests and linters: pre-commit run --all-files
  5. Submit a pull request

Code Style

  • Minimal dependencies - Only essential runtime dependencies (tomli for Python 3.10)
  • Type-safe - All code must pass mypy --strict
  • Tested - Maintain high test coverage
  • Formatted - Code is auto-formatted with ruff

๐Ÿ“„ License

Apache License 2.0 - see LICENSE for details.

Copyright 2025 Oliver Ratzesberger


๐Ÿ”— Links


๐Ÿ™ Acknowledgments

Inspired by the need for better ASCII art formatting in AI-generated documentation.

Built with โค๏ธ using only Python's standard library.


Note: This project is in active development (v0.1.0-alpha). The core linter functionality is being implemented. Contributions and feedback are welcome!

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

ascii_guard-1.3.0.tar.gz (44.2 kB view details)

Uploaded Source

Built Distribution

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

ascii_guard-1.3.0-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

Details for the file ascii_guard-1.3.0.tar.gz.

File metadata

  • Download URL: ascii_guard-1.3.0.tar.gz
  • Upload date:
  • Size: 44.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ascii_guard-1.3.0.tar.gz
Algorithm Hash digest
SHA256 10ce844e12ba8426ca999f803c853d5994892b4b334449f52b91355f322d1312
MD5 3da4a4047cca252598bfe24b23c3efab
BLAKE2b-256 d3aff785d0addfca0bd63c42df887367ed8e55d64ee0fbf215af57eed502c08b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ascii_guard-1.3.0.tar.gz:

Publisher: release.yml on fxstein/ascii-guard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ascii_guard-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: ascii_guard-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 29.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ascii_guard-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a92803bc90f709a9e5db3d8fe9ad0ea2dbd709906adb94f2e05f3673dcfa27f
MD5 f3bb6b2f9d13f524405256190115fd30
BLAKE2b-256 cf171713aa3c09bb3b5a3a6d9e54341ceccbc45311663688fc7c858908ab6766

See more details on using hashes here.

Provenance

The following attestation bundles were made for ascii_guard-1.3.0-py3-none-any.whl:

Publisher: release.yml on fxstein/ascii-guard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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