comments¶
What this rule does¶
Controls formatting of # comments — whether a space is required
after the #, and how far inline comments must sit from preceding
content.
Why this matters¶
- Legibility.
#commentand# commentread very differently; enforcing a space keeps comments visually distinct from directive-like prefixes. - Inline comments. Pushing inline comments away from values prevents visual collisions when values change length; capping the gap keeps them next to the value they describe.
Configuration¶
[rules.comments]
level = "error"
require-starting-space = true
ignore-shebangs = true
min-spaces-from-content = 2
max-spaces-from-content = -1
| Option | Default | Description |
|---|---|---|
require-starting-space |
true |
Require at least one space between # and the comment text. |
ignore-shebangs |
true |
Skip #! shebang lines when require-starting-space is on. |
min-spaces-from-content |
2 |
Minimum spaces between code and an inline # comment. Use -1 to disable. |
max-spaces-from-content |
-1 |
Maximum spaces between code and an inline # comment; -1 (the default) disables it. Must be at least 1 and at least min-spaces-from-content. TOML only. |
Spaces and tabs each count as one. Setting max-spaces-from-content reports
deliberately column-aligned inline comments, and --fix collapses the alignment.
A comment after a block scalar header (key: >- # note) is checked like any other
inline comment, where yamllint skips it; see
How ryl differs from yamllint.
Examples¶
Allowed (defaults)¶
Reported (defaults)¶
After ryl check --fix¶
Reported (min-spaces-from-content = 2, max-spaces-from-content = 2)¶
After ryl check --fix¶
Automatic fixing¶
ryl check --fix inserts the missing space after #, pads inline comments
to the configured min-spaces-from-content, and replaces a gap wider than
max-spaces-from-content with that many spaces. Disable with:
Related rules¶
comments-indentation— controls the vertical alignment of standalone comments.