vibecoded haproxy config linter in python stdlib only
  • Python 99.7%
  • Dockerfile 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-10-26 22:12:37 +01:00
src/haplint wip 2025-10-26 22:01:53 +01:00
tests wip 2025-10-26 22:01:53 +01:00
.editorconfig wip 2025-10-26 00:28:53 +02:00
.envrc add envrc 2025-10-25 23:43:21 +02:00
.gitignore fix: lint 2025-10-26 13:02:07 +01:00
.pre-commit-config.yaml wip 2025-10-26 13:35:00 +01:00
AGENTS.md wip 2025-10-26 22:01:53 +01:00
Dockerfile wip 2025-10-26 13:42:36 +01:00
opencode.json wip 2025-10-26 13:35:00 +01:00
pyproject.toml installable 2025-10-26 22:12:37 +01:00
README.md wip 2025-10-26 13:42:36 +01:00
Taskfile.yaml wip 2025-10-26 22:01:53 +01:00
uv.lock installable 2025-10-26 22:12:37 +01:00

haplint

A simple linter for HAProxy configuration files that validates syntax and checks for common configuration issues.

Features

  • Validates HAProxy configuration syntax
  • Checks for common configuration mistakes
  • Identifies unused ACLs and backends
  • Validates specific directives like bind, server, balance, timeout, option, and acl
  • Warns about deprecated directives
  • Reports detailed line-by-line errors and warnings

Installation

# Clone the repository
git clone <repository-url>
cd haplint

# Install dependencies (requires Python 3.12+)
pip install -e .

# Or using uv (recommended)
uv pip install -e .

Usage

Basic usage

# Lint a single configuration file
python -m haplint /path/to/haproxy.cfg

# Lint multiple configuration files
python -m haplint /path/to/haproxy1.cfg /path/to/haproxy2.cfg

# Suppress warnings (show only errors)
python -m haplint --quiet /path/to/haproxy.cfg

Example output

Checking test_haproxy.cfg...
  WARNING (line 13): Unusual bind address format: *

Summary:
  Errors: 0
  Warnings: 1

Validation Rules

Sections

  • Validates section declarations (global, defaults, frontend, backend, listen)
  • Ensures named sections have names
  • Tracks backend definitions and references

Bind Directive

  • Checks that bind directives have addresses
  • Warns about unusual address formats
  • Supports IPv4, IPv6, Unix sockets, and wildcards

Server Directive

  • Ensures servers have names and addresses
  • Warns when addresses might be missing ports

ACL Directive

  • Tracks ACL definitions and references
  • Warns about unused ACLs

Balance Directive

  • Validates balance algorithm names
  • Supports: roundrobin, static-rr, leastconn, first, source, uri, url_param, hdr, rdp-cookie

Timeout Directive

  • Validates timeout types
  • Supports: client, server, connect, check, queue, http-request, http-keep-alive, tunnel

Option Directive

  • Validates option names
  • Supports common options like httpclose, forceclose, http-server-close, forwardfor, etc.

Common Mistakes

  • Warns about deprecated directives:
    • clitimeouttimeout client
    • srvtimeouttimeout server
    • contimeouttimeout connect

Development

Setup

# Install development dependencies
pip install -e .

# Or using uv (recommended)
uv pip install -e .

Running Tests

# Run all tests
pytest

# Run unit tests
pytest tests/unit/

# Run integration tests
pytest tests/integration/

# Run specific test file
pytest tests/unit/rules/test_bind.py

# Run specific test
pytest -k test_valid_bind_with_address

Code Quality

# Format code
ruff format .

# Lint code
ruff check .

# Type check
basedpyright .

Requirements

  • Python 3.12+

License

MIT