Loading...
Loading...
Validates YAML syntax and structure for all .yml and .yaml files in the project. Identifies common issues like invalid syntax, indentation errors, missing keys, type mismatches, and provides fixes. Use when editing, creating, or debugging YAML configuration files.
npx skill4agent add d-o-hub/rust-self-learning-memory yaml-validator# Comments start with #
key: value # Simple key-value
list: # Lists use dash prefix
- item1
- item2
nested: # Nested objects
key1: value1
key2: value2
multiline: | # Literal block scalar
Line 1
Line 2
flow: > # Folded block scalar
This is a long
sentence that foldsstring: "value" # Quoted string
unquoted: value # Unquoted string
number: 42 # Integer
float: 3.14 # Float
boolean: true # Boolean (true/false, yes/no, on/off)
null_value: null # Null
empty: ~ # Also null
multiline_string: |
This preserves
newlines# Correct
parent:
child: value
list:
- item1
- item2
# Incorrect - mixed tabs/spaces
parent:
child: value # Tab character!
# Incorrect - wrong indentation
parent:
child: value # Only 1 space# Wrong
parent:
child: value
# Correct
parent:
child: value# Wrong
key value
# Correct
key: value:{}[]# Wrong
message: Error: something went wrong
# Correct
message: "Error: something went wrong"# Wrong
config:
key: value1
key: value2
# Correct
config:
key: value1
other_key: value2yesnoonofftruefalse# Wrong - parsed as boolean true
country: YES
# Correct
country: "YES"------
# Your content here.github/workflows/*.ymlname: Workflow Name
on: [push, pull_request] # Event triggers
jobs:
job-name:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Step name
run: echo "Hello"on:runs-onsteps:docker-compose.ymlversion: "3.8"
services:
app:
image: node:18
ports:
- "3000:3000"
environment:
- NODE_ENV=production*.yamlapiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: container-name
image: nginx:latest# Basic syntax check
python3 -c "import yaml; yaml.safe_load(open('file.yml'))"
# With better error messages
python3 -c "
import yaml
try:
with open('file.yml') as f:
yaml.safe_load(f)
print('✓ Valid YAML')
except yaml.YAMLError as e:
print(f'✗ Error: {e}')
"# Install yamllint (recommended)
pip install yamllint
# Validate single file
yamllint file.yml
# Validate with config
yamllint -c .yamllint file.yml
# Check all YAML files
find . -name "*.yml" -o -name "*.yaml" | xargs yamllint
# Using Python (if yamllint not available)
python3 -c "
import yaml
import sys
errors = []
for file in sys.argv[1:]:
try:
with open(file) as f:
yaml.safe_load(f)
print(f'✓ {file}')
except Exception as e:
errors.append(f'✗ {file}: {e}')
print(f'✗ {file}: {e}')
sys.exit(1 if errors else 0)
" file1.yml file2.yml.yamllint---
yaml-files:
- '*.yml'
- '*.yaml'
rules:
braces:
min-spaces-inside: 0
max-spaces-inside: 0
brackets:
min-spaces-inside: 0
max-spaces-inside: 0
colons:
max-spaces-after: 1
max-spaces-before: 0
commas:
max-spaces-after: 1
max-spaces-before: 0
comments:
min-spaces-from-content: 1
require-starting-space: true
comments-indentation: disable
document-end: disable
document-start: disable
empty-lines:
max: 2
empty-values: disable
indentation:
spaces: 2
indent-sequences: true
check-multi-line-strings: false
key-duplicates: enable
key-ordering: disable
line-length:
max: 120
new-line-at-end-of-file: enable
new-lines:
type: unix
octal-values: disable
quoted-strings: disable
trailing-spaces: enable
truthy: disable## YAML Validation Report
### Summary
- Files Checked: 5
- Errors: 2
- Warnings: 3
- Status: FAIL
### file1.yml
✓ Valid YAML syntax
⚠ Warning (Line 15): Line too long (145 > 120)
### file2.yml
✗ Error (Line 8, Col 5): Invalid indentation
Current: 4 spaces
Expected: 2 spaces
✗ Error (Line 12): Duplicate key "name"
### file3.yml
✓ Valid YAML syntax
⚠ Warning (Line 20): Trailing spaces------
name: Rust CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: cargo test --all---
version: "3.8"
services:
app:
build: .
ports:
- "3000:3000"
environment:
NODE_ENV: production
depends_on:
- db
db:
image: postgres:15
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deployment
labels:
app: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:alpine
ports:
- containerPort: 80# Fix trailing spaces
sed -i 's/[[:space:]]*$//' file.yml
# Convert tabs to spaces
sed -i 's/\t/ /g' file.yml
# Ensure newline at end
sed -i -e '$a\' file.yml