vibecoded haproxy config linter in python stdlib only
- Python 99.7%
- Dockerfile 0.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| src/haplint | ||
| tests | ||
| .editorconfig | ||
| .envrc | ||
| .gitignore | ||
| .pre-commit-config.yaml | ||
| AGENTS.md | ||
| Dockerfile | ||
| opencode.json | ||
| pyproject.toml | ||
| README.md | ||
| Taskfile.yaml | ||
| uv.lock | ||
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, andacl - 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
binddirectives 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:
clitimeout→timeout clientsrvtimeout→timeout servercontimeout→timeout 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