Skip to content

commas

What this rule does

Controls the number of spaces before and after commas (,) in flow mappings and flow sequences.

Why this matters

  • Readability. [1, 2, 3] is easier to scan than [1,2 , 3].
  • Consistent diffs. Normalising comma spacing prevents whitespace-only diffs.

Configuration

[rules.commas]
level = "error"
max-spaces-before = 0
min-spaces-after = 1
max-spaces-after = 1
Option Default Description
max-spaces-before 0 Maximum spaces before the comma. Use -1 to disable.
min-spaces-after 1 Minimum spaces after the comma.
max-spaces-after 1 Maximum spaces after the comma. Use -1 to disable.

Examples

✅ Allowed (defaults)

list: [10, 20, 30, {x: 1, y: 2}]

❌ Reported (defaults)

list: [10, 20 ,30,   {x: 1,   y: 2}]

🔧 After ryl --fix

list: [10, 20, 30, {x: 1, y: 2}]

Automatic fixing

ryl --fix normalises whitespace around commas to satisfy the configured limits. Disable with:

[fix]
fixable = ["ALL"]
unfixable = ["commas"]
  • braces and brackets — spacing inside the flow delimiters themselves.
  • colons — the analogous rule for mapping colons.