Skip to main content

CLI tool for detecting broken links and localhost URLs in project files

Project description

๐Ÿ›ก๏ธ LinkGuard

Fast, async link validation for developers. Catch broken links before your users do.

Python Version Version License: MIT Tests Test Coverage Status PRs Welcome

LinkGuard is a fast, async Python CLI tool that scans your project files for broken links and development URLs. Catch 404s before your users do, and ensure localhost references don't leak into production.


โœจ Features

  • ๐Ÿš€ Blazing Fast - Async validation checks hundreds of links in seconds
  • ๐ŸŽฏ Environment-Aware - Detect localhost/dev URLs that shouldn't reach production
  • ๐ŸŽจ Beautiful CLI - Rich progress bars and color-coded results
  • ๐Ÿ“Š Multiple Exports - JSON, CSV, and Markdown reports for automation
  • ๐Ÿ” Smart Extraction - Supports Markdown, HTML, JSON, JS/TS, and plain text
  • โš™๏ธ Zero Config - Works out of the box with sensible defaults
  • ๐Ÿ› ๏ธ Configurable - .linkguardignore and linkguard.config.json support
  • โœ… Production Ready - 91 tests, 71% coverage, comprehensive documentation

๐Ÿ“ฆ Installation

# Install from PyPI (coming soon)
pip install linkguard

# Or install from source
git clone https://github.com/anubhabx/link-guard.git
cd link-guard

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows (PowerShell)
.\venv\Scripts\Activate.ps1
# Linux/Mac
source venv/bin/activate

# Install in development mode (includes all dependencies)
pip install -e ".[dev]"

๐Ÿ’ก Tip: After installation with pip install -e ".[dev]", you can use linkguard directly instead of python -m linkguard.cli


๐Ÿš€ Quick Start

# Scan current directory
linkguard

# Scan specific directory
linkguard ./docs

# Production mode (flags localhost URLs as errors)
linkguard --mode prod

# Export results to JSON
linkguard --export report.json

# Custom timeout
linkguard --timeout 15

Example Output:

๐Ÿ” Scanning directory: ./docs
Mode: dev | Timeout: 10s

โœ“ Found 42 files to scan
โœ“ Extracted 156 URLs

๐ŸŒ Checking links...
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 100% 156/156

โ•ญโ”€ Scan Summary โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Files scanned       42     โ”‚
โ”‚ URLs found          156    โ”‚
โ”‚ Working links       152    โ”‚
โ”‚ Broken links        4      โ”‚
โ”‚ Rule violations     0      โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

๐Ÿ“– Documentation

Document Description
QUICKSTART.md Installation, basic usage, and common examples
FEATURES.md Complete feature list and capabilities
CONTRIBUTING.md Development setup, testing, and contribution guidelines
RELEASE_NOTES.md v1.0 release details and highlights
CHANGELOG.md Full version history and changes

โš™๏ธ Configuration

Command-Line Options

linkguard [DIRECTORY] [OPTIONS]

Options:
  --mode, -m          dev|prod        Scanning mode (default: dev)
  --timeout, -t       INTEGER         Request timeout in seconds (default: 10)
  --export, -e        PATH            Export to JSON/CSV/Markdown
  --concurrency, -c   INTEGER         Max concurrent requests (default: 50)
  --ignore, -i        TEXT            Comma-separated ignore patterns
  --verbose, -v                       Detailed output
  --help                              Show help

Configuration File

Create linkguard.config.json in your project root:

{
  "mode": "prod",
  "timeout": 15,
  "concurrency": 100,
  "ignore_patterns": ["node_modules/**", "*.min.js"],
  "exclude_urls": ["https://example.local"],
  "strict_ssl": false
}

See linkguard.config.json.example for all options.

Ignore File

Create .linkguardignore (gitignore-style syntax):

# Ignore directories
node_modules/
dist/**
build/

# Ignore file patterns
*.draft.md
temp-*.json

# Ignore domains
*.internal.company.com
example.local

๐Ÿ—๏ธ Supported File Types

Type Extensions What's Extracted
Markdown .md, .markdown [text](url) and bare URLs
HTML .html, .htm href, src attributes
JSON .json URL strings in values
JavaScript/TypeScript .js, .jsx, .ts, .tsx Bare URL patterns
Plain Text .txt HTTP/HTTPS URLs

Auto-excluded: .git, .venv, node_modules, __pycache__, dist, build


๐Ÿ”ง CI/CD Integration

GitHub Actions

name: Link Validation

on: [push, pull_request]

jobs:
  check-links:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.10'
      - name: Install LinkGuard
        run: pip install linkguard
      - name: Check links
        run: linkguard --mode prod --export report.json
      - name: Upload report
        if: failure()
        uses: actions/upload-artifact@v3
        with:
          name: link-report
          path: report.json

Exit Codes:

  • 0 - All links valid
  • 1 - Broken links or rule violations found
  • 2 - Configuration error

๐ŸŽฏ Use Cases

โœ… Documentation Sites - Ensure all links work before publishing
โœ… Open Source Projects - Validate README and wiki links
โœ… Marketing Sites - Check landing pages and blog posts
โœ… CI/CD Pipelines - Automated link checking on every commit
โœ… Pre-Production Checks - Catch localhost URLs before deployment
โœ… Content Migration - Validate links after CMS migrations


๐Ÿค Contributing

We welcome contributions! See CONTRIBUTING.md for:

  • Development setup and workflow
  • Testing guidelines (91 tests, 71% coverage)
  • Code style requirements (PEP 8, Black, type hints)
  • Pull request process

Quick Start:

git clone https://github.com/anubhabx/link-guard.git
cd link-guard
python -m venv venv
source venv/bin/activate  # or .\venv\Scripts\Activate.ps1 on Windows
pip install -e ".[dev]"
pytest tests/ -v

๐Ÿ—บ๏ธ Roadmap

โœ… v1.0 (Current - October 2025)

  • Production-ready release
  • Comprehensive documentation
  • 91 passing tests with 71% coverage
  • GitHub Actions CI/CD
  • Published to PyPI

๐Ÿšง v1.1.0 (Planned)

  • Retry logic with exponential backoff
  • Custom HTTP headers support
  • Relative URL resolution
  • Enhanced performance optimizations

๐Ÿ”ฎ v2.0.0 (Future)

  • Anchor link validation (#section)
  • Browser automation (Playwright) for bot detection bypass
  • Web dashboard for analytics
  • Webhook notifications (Slack/Discord)

See FEATURES.MD for complete roadmap.


๐Ÿ“Š Performance

Benchmarks (typical projects):

  • โœ… 100 links validated in ~2 seconds
  • โœ… 1,000 links validated in ~5 seconds
  • โœ… 10,000 files scanned in <30 seconds

Architecture:

  • Async I/O with aiohttp for concurrent requests
  • Semaphore-based concurrency control (default: 50)
  • Memory-efficient streaming file reads
  • HEAD request with smart GET fallback

๐Ÿ› Troubleshooting

Valid links marked as broken?

  • Some servers block automated requests โ†’ Increase timeout: --timeout 20

"Connection timeout" errors?

  • Network latency or slow servers โ†’ Try: --timeout 30

Ignore specific files/URLs?

  • Use .linkguardignore or add to linkguard.config.json

Command not found?

  • Ensure installed: pip install -e ".[dev]"
  • Or use: python -m linkguard.cli

SSL certificate errors?

  • LinkGuard skips SSL verification by default
  • Coming soon: --strict-ssl flag

See QUICKSTART.MD for more troubleshooting tips.


๐Ÿ“„ License

MIT License - see LICENSE file for details.


๐Ÿ™ Acknowledgments

Built with these amazing tools:

Special thanks to all contributors! ๐ŸŽ‰


๐Ÿ“ž Support


Made with โค๏ธ for the open-source community

If you find LinkGuard useful, please give it a โญ!

Documentation โ€ข Features โ€ข Contributing โ€ข Changelog

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

linkguard-1.0.1.tar.gz (44.1 kB view details)

Uploaded Source

Built Distribution

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

linkguard-1.0.1-py3-none-any.whl (30.2 kB view details)

Uploaded Python 3

File details

Details for the file linkguard-1.0.1.tar.gz.

File metadata

  • Download URL: linkguard-1.0.1.tar.gz
  • Upload date:
  • Size: 44.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for linkguard-1.0.1.tar.gz
Algorithm Hash digest
SHA256 82eaa59eb62189f930234c2190b1e15866fd8b311db3fe605f6d28ef38143917
MD5 680ea5c071e8748247aff5989d53fc4f
BLAKE2b-256 e992cbf55185bbb855e18182ead6742aa3ea4662a72908fd5b5d7c1ed80d01dd

See more details on using hashes here.

File details

Details for the file linkguard-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: linkguard-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 30.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for linkguard-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c9f3b8a93a1e9c85ce5ffde8960c3278eb877366dbb2fad30d561662384e476
MD5 2a142c24408d756fb93a38ac6fbf0c4c
BLAKE2b-256 e75df4094ec5f9e077d267a2c78c82ce4e5786cd47b16441a8ed39f0eb3448fb

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