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.2.0.tar.gz (39.0 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.2.0-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ascii_guard-1.2.0.tar.gz
  • Upload date:
  • Size: 39.0 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.2.0.tar.gz
Algorithm Hash digest
SHA256 9405c6e7a9161985c5d0538979c379037d30f111ddf2e8702076d22a2116baa0
MD5 1e186eb4bd542e8fe09bc55628d0f99f
BLAKE2b-256 a864c2d62e55affb74956552869ca3e9d09943ab3104905987e403357a2990a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for ascii_guard-1.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: ascii_guard-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 26.1 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9181f181bc2a8a4d74400e5cf1f4e705cf8d046db971e07a982ac3856387c81
MD5 848b0d293c4c51fadfb5cf8d271c5ce5
BLAKE2b-256 f24cdc223482eaf27567bff53bd3d7dbf2fa20ba518f14fb5040148780772297

See more details on using hashes here.

Provenance

The following attestation bundles were made for ascii_guard-1.2.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