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.4.0.tar.gz (50.6 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.4.0-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ascii_guard-1.4.0.tar.gz
  • Upload date:
  • Size: 50.6 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.4.0.tar.gz
Algorithm Hash digest
SHA256 085879d3ece5507edf9a16a2f0fbb233e421cbe3b89c716a112252c46db32de6
MD5 b95287132a2e5a0f2ab109a88eaed83f
BLAKE2b-256 df2891cd36eaa4e42eb9f74f0ed350354e1f0430b76d7939943112f792de43f1

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ascii_guard-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 30.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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e513f9c5f1c575b2a190a700373c2ce6e259de5146bf808678d338283d17c148
MD5 b0bcb778b863b4861077bb99a07bec1f
BLAKE2b-256 366920e33237bbd847f354849239b4b9eb91fe9cdfe858b1b6503d0c40d71101

See more details on using hashes here.

Provenance

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