YAML fragments are supported in docker-compose.yaml.
The following minimal example has its &anchor broken when formatted:
version: "3.5"
x-anchor: &anchor
FOO: bar
services:
example:
image: alpine
Formatting makes the following change:
version: "3.5"
x-anchor:
&anchor
FOO: bar
services:
example:
image: alpine
I would expect the compose formatter to not insert newlines that break supported syntax.