A comprehensive static analysis linter for ANTLR v4 grammar files (.g4) that identifies common issues, enforces best practices, and improves grammar quality and maintainability.
- 24 Built-in Rules across 8 categories
- Configurable Rule Severity and thresholds
- Multiple Output Formats (JSON, XML, text, SARIF)
- Auto-fixing capabilities for deterministic issues
- CLI and Programmatic APIs
- IDE Integration ready
pip install antlr-v4-linter
# Lint a single grammar file
antlr-lint MyGrammar.g4
# Lint multiple files
antlr-lint src/**/*.g4
# Custom configuration
antlr-lint --config antlr-lint.json MyGrammar.g4
# JSON output
antlr-lint --format json MyGrammar.g4
- Syntax and Structure (S001-S003)
- Naming and Convention (N001-N003)
- Labeling and Organization (L001-L003)
- Complexity and Maintainability (C001-C003)
- Token and Lexer (T001-T003)
- Error Handling (E001-E002)
- Performance (P001-P002)
- Documentation (D001-D002)
Create an antlr-lint.json
file:
{
"rules": {
"S001": { "enabled": true, "severity": "error" },
"N001": { "enabled": true, "severity": "error" },
"C001": {
"enabled": true,
"severity": "warning",
"thresholds": {
"maxAlternatives": 10,
"maxNestingDepth": 5,
"maxTokens": 50
}
}
},
"excludePatterns": ["*.generated.g4"],
"outputFormat": "text"
}
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black src/ tests/
isort src/ tests/
# Type checking
mypy src/
MIT License