-
-
Notifications
You must be signed in to change notification settings - Fork 773
list indention style is different from pyyaml #432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
IMHO this request is specific and there are no big reasons to change output format or add an option. I tend to close it. |
@puzrin After doing a small evaluation I'm pretty sure most of (many) frameworks are doing what |
You request a breaking change without valuable profit (at least, i could not understand it) - i don't like such balance. |
Why would following the industry convention would be a "breaking request"? Especially if both specifications are valid. If nothing else, this could easily be just a new flag in safeSave options. The "profit" here is that other libraries and software (i.e. applications where you cannot easily edit the source code, e.g. kubernetes) dumps the condensed format. So when you export from one software and then edit with js-yaml, you have to constantly fight with whitespace in commits. This seems unreasonable, since it's a fairly straightforward patch. |
"industry convention" is marketing bullshit bingo slang. I'd suggest to focus on technical arguments instead. What's wrong with "other libraries and software"? If dumper produce valid yaml, why should someone fight with spaces? |
industry convention is what other devs sadly have to deal with in their day-to-day reality, may it be supporting the Internet Explorer or they way whitespace is handled...
The technical argument is interoperability. Other tools make it different. It's absolutely fine to pick the current behaviour as a standard, but what's wrong with adding an optional setting, so the output can be reused with other libraries and platforms that decided to handle this case in a different way? |
Adding "everything possible" make API messy very quickly. Current repo has conservative accept policy.
I'd like to understand, what's wrong right now? Output is valid yaml. Other yaml parser should accept it ok. |
And I do totally agree. But it's not that the proposal is completely messing with the output (let's configure an option to dump XML), but a different behaviour others have adopted.
My use case (and I can think of others): Some different tool chains work with a YAML content, and
|
Ok, finally, i understand possible use case. IMHO, your request is not about spaces, but about making output look like libyaml. Can you guarantee, that array spaces is the only difference? It would be strange to have later additional requests about new options for quotes etc. From the other hand, wouldn't it be better to use native libyaml wrapper for your [specific?] needs? There are should be some. |
I require this feature. The yaml that It is not too much to request that there be an option for this functionality. Perhaps if I get some time, I'll submit a PR. |
I agree with @puzrin though, in that: This issue should be called "Cannot specify optional indentation of array elements", this issue shouldn't have anything to do with pyyaml. |
@thewilli In the meantime, here's this regex-based workaround for us: const output: string = yaml.safeDump(workflow, { lineWidth: Infinity });
// This un-indents array elements to match the un-indented style.
// yaml.safeDump style:
// abc:
// - 1
// - 2
// - 3
// un-indented style:
// abc:
// - 1
// - 2
// - 3
const fixedOutput: string = output.replace(/(\s+)(\s\s\-)(.*\n)/g, '$1-$3'); EDIT: Nevermind, this doesn't work because it doesn't un-indent the object properties in object arrays. |
I have a PR open here: #461 |
Addresses issue #432 by adding a `noArrayIndent` option to optionally not add an extra level of indentation to array elements. When `noArrayIndent` option is set to `false` (or not provided), output is: ``` array: - a - b - c ``` When `noArrayIndent` option is set to `true`, output is: ``` array: - a - b - c ``` This helps avoid diffs when parsing, modifying, and generating valid yaml that does *not* use extra indentation for arrays.
consider the following
pyyaml
code (try yourself):which outputs
and the comparable
js-yaml
counterpart (try yourself):which outputs
You can see that
pyyaml
doesn't add spaces to lists (because-
counts as indention). I know both are valid, but it would be great if we could a similar output aspyyaml
(especially as this project started as some kind of fork)?Changing this line to
changes the behaviour so it should be possible to add a configuration setting to allow both behaviours.
The text was updated successfully, but these errors were encountered: