php / pecl-file_formats-yaml

YAML-1.1 parser and emitter
https://pecl.php.net/package/yaml
MIT License
72 stars 32 forks source link

yaml_emit Incorrectly Indents List Items Same as Parent #91

Open mpql opened 3 weeks ago

mpql commented 3 weeks ago

Hey there! I appreciate the work y'all do, and wanted to report a probable bug behavior I found.

I am on PHP 8.3.13, using the 2.2.4 version of the yaml extension — each the latest stable version, as of this writing.

$ php -v
# PHP 8.3.13 (cli) (built: Nov  4 2024 23:34:58) (NTS)
# Copyright (c) The PHP Group
# Zend Engine v4.3.13, Copyright (c) Zend Technologies
$ php -r 'echo phpversion() . "\n";'
# 8.3.13
$ php -r 'echo phpversion("yaml") . "\n";'
# 2.2.4

Given a file input.yaml (with line 6 being a blank line present, but omitted by GitHub):

---
root:
  node:
    - list item
...

We can parse and emit said file with the following code:

php -r 'echo yaml_emit(yaml_parse_file("input.yaml"));' > output.yaml

rendering output.yaml (with line 6 again being a blank line):

---
root:
  node:
  - list item
...

Note the newly incorrect indentation of the list item on line 4. yamllint throws an error for the same line.

$ yamllint -v
# yamllint 1.35.1
$ yamllint output.yaml
# output.yaml
#   4:3       error    wrong indentation: expected 4 but found 2  (indentation)

I've got a workaround on my end, though it's specific to my rather esoteric use case — but I figured I'd do my due diligence and report the issue.

bd808 commented 3 weeks ago

This is a stylistic difference rather than a bug. Your project has adopted a style rule that is valid but not necessary.

mpql commented 3 weeks ago

This is a stylistic difference rather than a bug. Your project has adopted a style rule that is valid but not necessary.

Neither the program ingesting my yaml nor yamllint are my projects. That said, how do I tell yaml_emit not to stylistically mangle my input?