Skip to content

🕵 YAML lint

Dokumentacja techniczna joba

yamllint to narzędzie do walidacji składni i stylu YAML. W naszej pipeline służy do walidacji wszystkich plików YAML (.yml i .yaml) w repozytorium, upewniając się, że są poprawnie sformatowane przed buildowaniem.


$ yamllint .
./common/rules/main.yml
  42:1       error    wrong indentation: expected 2 but found 1
./docs/architecture.md
  (pominięte nie jest YAML)
./tests/valid.yml
  (OK brak błędów)

---
extends: default

rules:
  # Wyłączone dla elastyczności
  line-length: disable
  comments-indentation: disable

  # Wszystkie inne reguły active
  indentation:
    spaces: 2
  colons:
    max-spaces-after: 1
  commas:
    max-spaces-after: 1
  # itd...
RegułaOpisDomyślnie
indentationSpójność wcięć (musi być 2 spacje)✅ active
truthyWartości bool muszą być true/false, nie yes/no✅ active
commentsKomentarze muszą mieć # i spację✅ active
colonsMax 1 spacja po :✅ active
commasMax 1 spacja po ,✅ active
bracketsSpacje w [...]✅ active
bracesSpacje w {...}✅ active
line-lengthMax długość linii (default 80)❌ DISABLED
comments-indentationWcięcie komentarzy❌ DISABLED

Jeśli chcesz zmienić reguły, edytuj .yamllint.yml w root repozytorium:

---
extends: default

rules:
  line-length:
    max: 120  # Pozwól na dłuższe linie
  indentation:
    spaces: 4  # Zmień z 2 na 4 spacje
  comments-indentation: enable  # Włącz walidację wcięcia komentarzy

Problem:

# ❌ BŁĄD
services:
 api:     # 1 spacja zamiast 2
  image: node:20

Komunikat:

  2:1  error  wrong indentation: expected 2 but found 1

Naprawa:

# ✅ POPRAWNIE
services:
  api:     # 2 spacje
    image: node:20

Problem:

# ❌ BŁĄD
features:
  experimental: yes  # YAML truthy value
  debug: no

Komunikat:

  2:24  error  truthy value should be one of [true, false]

Naprawa:

# ✅ POPRAWNIE
features:
  experimental: true
  debug: false

Problem:

# ❌ BŁĄD
metadata:
  author : "John"   # Spacja PRZED :
  email:  john@x.com  # 2 spacje ПОСЛЕ :

Komunikat:

  3:10  error  too many spaces after colon

Naprawa:

# ✅ POPRAWNIE
metadata:
  author: "John"
  email: john@x.com

Problem:

# ❌ BŁĄD
items:
  - name : test  # Spacja przed :
  -name: test    # Brak spacji po -
  - [1,2,3,]     # Przecinek na końcu

Komunikat:

  2:9   error  too many spaces after comma
  3:3   error  wrong indentation
  4:9   error  trailing comma

Naprawa:

# ✅ POPRAWNIE
items:
  - name: test
  - name: test
  - [1, 2, 3]    # Spacja po przecinku, brak na końcu

---
stages:
  - validate
  - build
  - test

convention-commits:
  stage: validate
  script:
    - npm install
    - npm run validate:commits
  only:
    - merge_requests
    - /^feat\/.*$/
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-server
  labels:
    app: api
spec:
  replicas: 3
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: myrepo/api:1.0
          ports:
            - containerPort: 3000
          env:
            - name: NODE_ENV
              value: production
---
version: "3.8"

services:
  api:
    image: node:20
    container_name: myapp-api
    ports:
      - "3000:3000"
    environment:
      NODE_ENV: production
      DATABASE_URL: postgresql://db:5432/myapp
    depends_on:
      - database

  database:
    image: postgres:15
    container_name: myapp-db
    environment:
      POSTGRES_PASSWORD: secret
    volumes:
      - db_data:/var/lib/postgresql/data

volumes:
  db_data: