YAML
These are the YAML language-specific coding styles. Anything mentions here overrides/adds to the "In General" guides.
#1 - Filename
#1 - Filename
The extension is .yml
.
#2 - Indents and Space
#2 - Indents and Space
- Use
space
as tab instead of\t
. - Use 4 spaces as standard indent.
- Avoid 1 space tab.
NOTE
Maintain tab alignment for consistency. That’s how YAML works.
#3 - Strings
#3 - Strings
Follow source code. Otherwise ,use double quote ("
).
#4 - Naming Convention
#4 - Naming Convention
- Use
snake_case
convention. - Avoid SPACE in the name. Use underscore
_
instead. - No space before the colon (
:
). - One space after the colon (
:
).
Example:
this_is_a_very_long_string_label: "string"
integer: 5
float: 10.0
boolean: true
#5 - Comments
#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
#6 - Collection
- 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.
Don’t Repeat Yourself.
- Make use of alias (&) to group repeated value.
- Use
<<:
to include them. - 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.