Description
The pretty-format-yaml hook removes quotes from scalar values inside flow-style sequences ([...]), even when those values contain special characters (like colons :) that must be quoted to produce valid YAML. This formatting breakage leads to syntax errors when parsing output (e.g., with Docker Compose or YAML linters).
Steps to Reproduce
- Create a
docker-compose.yaml with the following content:
services:
nc:
image: nextcloud:31.0.7
restart: unless-stopped
healthcheck:
test: [CMD, curl, -f, "http://localhost/status.php"]
- Run
pretty-format-yaml via pre-commit.
- Formatter outputs:
services:
nc:
image: nextcloud:31.0.7
restart: unless-stopped
healthcheck:
test: [CMD, curl, -f, http://localhost/status.php]
- YAML parser reports:
while scanning a plain scalar
found unexpected ':'
Expected Behavior
Quotes around scalars with special characters inside flow sequences must be preserved per YAML specification. The formatter should:
- Detect when quoting is necessary and preserve it automatically.
- Or offer a
--preserve-quotes/--safe-syntax flag to avoid invalidating valid YAML.
Context
- YAML spec (1.1/1.2) mandates quotes for ambiguous scalars in flow sequences.
- Tools like Docker Compose rely on this, making the formatter’s behavior disruptive.
Proposal
Enhance pretty-format-yaml to:
- Automatically preserve necessary quotes in flow sequences.
- Or introduce a configuration option to enforce safe syntax preservation.
Description
The
pretty-format-yamlhook removes quotes from scalar values inside flow-style sequences ([...]), even when those values contain special characters (like colons:) that must be quoted to produce valid YAML. This formatting breakage leads to syntax errors when parsing output (e.g., with Docker Compose or YAML linters).Steps to Reproduce
docker-compose.yamlwith the following content:pretty-format-yamlvia pre-commit.Expected Behavior
Quotes around scalars with special characters inside flow sequences must be preserved per YAML specification. The formatter should:
--preserve-quotes/--safe-syntaxflag to avoid invalidating valid YAML.Context
Proposal
Enhance
pretty-format-yamlto: