Enforce Property Spacing (key-spacing)

This rule enforces spacing around the colon in object literal properties. It can verify each property individually, or it can ensure vertical alignment of groups of properties in an object literal.

Rule Details

This rule will warn when spacing in properties does not match the specified options. In the case of long lines, it is acceptable to add a new line wherever whitespace is allowed. There are three modes:

1. Individual

Use the beforeColon, afterColon and mode options to enforce having one space or zero spaces on each side, using true or false, respectively. The default is no whitespace between the key and the colon and one space between the colon and the value.

mode option can be either "strict" or "minimum" and defaults to "strict". In strict mode, it enforces exactly 1 space before or after the colon where as in minimum mode, it enforces at least 1 space but more are okay.

2. Vertically align values "align": "value"

Use the align option to enforce vertical alignment of values in an object literal. This mode still respects beforeColon and afterColon where possible, but it will pad with spaces after the colon where necessary. Groups of properties separated by blank lines are considered distinct and can have different alignment than other groups. Single line object literals will not be checked for vertical alignment, but each property will still be checked for beforeColon and afterColon.

3. Vertically align colons "align": "colon"

The align option can also vertically align colons and values together. Whereas with "value" alignment, padding belongs right of the colon, with "colon" alignment, padding goes to the left of the colon. Except in the case of padding, it still respects beforeColon and afterColon. As with "value" alignment, groups of properties separated by blank lines are considered distinct and can have different alignment than other groups.