YAML

These are the YAML language-specific coding styles. Anything mentions here overrides/adds to the "In General" guides.

#1 - Filename

The extension is .yml.

#2 - Indents and Space

  1. Use space as tab instead of \t.
  2. Use 4 spaces as standard indent.
  3. Avoid 1 space tab.

NOTE

Maintain tab alignment for consistency. That’s how YAML works.

#3 - Strings

Follow source code. Otherwise ,use double quote (").

#4 - Naming Convention

  1. Use snake_case convention.
  2. Avoid SPACE in the name. Use underscore _ instead.
  3. No space before the colon (:).
  4. One space after the colon (:).

Example:

this_is_a_very_long_string_label: "string"
integer: 5
float: 10.0
boolean: true

#5 - Comments

Keep it on its own line. You don’t need an inline comment. The label should be self-explanatory.

Example:

# Server launch date
date: "2001-12-14T21:59:43.10-05:00"

# NOT
date: "2001-12-14T21:59:43.10-05:00" # This is the server launch date

#6 - Collection

  1. Use tabulators for consistency and readability.

Example:

symfony-1.0:
    - PHP: 5.0
    - Propel: 1.2
    - python:
        - 2.7: 5.2
        - 3.3: 4.4

symfony-1.2:
    - PHP: 5.2
    - Propel: 1.3

Don’t Repeat Yourself.

  1. Make use of alias (&) to group repeated value.
  2. Use <<: to include them.
  3. Use * to call your alias group.

Example:

common: &default
    adapter: postgresql
    version: 1.0

development:
    <<: *default
    database: dev_development

test:
    <<: *default
    database: test_test

production:
    <<: *default
    database: test_production
    version: 0.5

That's all for YAML coding style.