A TypeScript implementation of yamllint, the YAML linter.
npm install yamllint-ts# Lint a file
yamllint-ts myfile.yaml
# Lint with a config file
yamllint-ts -c .yamllint.yaml myfile.yaml
# Lint with inline config
yamllint-ts -d '{extends: relaxed, rules: {line-length: {max: 120}}}' myfile.yamlyamllint-ts uses the same configuration format as Python yamllint. See the yamllint documentation for details.
yamllint-ts aims for full feature parity with Python yamllint. All linting rules are implemented and produce identical results for valid YAML files.
yamllint-ts uses the yaml package for YAML parsing, while Python yamllint uses PyYAML. These parsers have different error reporting behavior for malformed YAML:
| Aspect | Python yamllint (PyYAML) | yamllint-ts (eemeli/yaml) |
|---|---|---|
| Error messages | PyYAML-style messages (e.g., "could not find expected ':'") | yaml-style messages (e.g., "Implicit keys need to be on a single line") |
| Error positions | May differ by 1-2 lines | May differ by 1-2 lines |
| Error detection | Detects some errors earlier/later in parsing | Detects some errors earlier/later in parsing |
For this YAML with no_space_after:value on line 3 (missing space after colon):
---
good: value
no_space_after:value
extra_spaces: value- Python yamllint:
4:1 error syntax error: could not find expected ':' - yamllint-ts:
3:1 error syntax error: Implicit keys need to be on a single line
Both correctly identify the file as invalid, but with different error messages and line numbers.
- For valid YAML: 100% parity - all rules produce identical results
- For malformed YAML: Syntax errors are detected but may have different messages/positions
- Comparison testing: 144/160 tests match (90%), with all differences being syntax error reporting
Porting PyYAML's scanner (~2000 lines of Python) to TypeScript would be a significant undertaking. The current approach provides full linting functionality while leveraging a well-maintained, modern YAML parser. The trade-off of slightly different syntax error messages for invalid YAML was deemed acceptable.
All yamllint rules are supported:
anchorsbracesbracketscolonscommascommentscomments-indentationdocument-enddocument-startempty-linesempty-valuesfloat-valueshyphensindentationkey-duplicateskey-orderingline-lengthnew-line-at-end-of-filenew-linesoctal-valuesquoted-stringstrailing-spacestruthy
GPL-3.0 (same as Python yamllint)
This project is a TypeScript port of yamllint by Adrien Vergé, licensed under GPL-3.0. The original Python implementation provided the design, rules, and test cases that this port is based on.