Skip to content
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

Add "noArrayIndent" option #461

Merged
merged 1 commit into from Jan 4, 2019
Merged

Add "noArrayIndent" option #461

merged 1 commit into from Jan 4, 2019

Conversation

jacob-hd
Copy link
Contributor

@jacob-hd jacob-hd commented Jan 4, 2019

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.

@@ -107,6 +107,7 @@ function encodeHex(character) {
function State(options) {
this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
this.indent = Math.max(1, (options['indent'] || 2));
this.indentArrays = (options['indentArrays'] === undefined) ? true : !!options['indentArrays'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaulting to true to maintain backwards-compatibility.

.gitignore Outdated
@@ -5,3 +5,4 @@ doc
benchmark/implementations/*
!/benchmark/implementations/current/
.idea
package-lock.json
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package lock should either be committed or ignored. Seeing as it isn't committed, I'm ignoring it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't touch configs if PR is not related

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "js-yaml",
"version": "3.12.0",
"version": "3.13.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I'm supposed to version bump or not...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change configs.

Copy link
Member

@puzrin puzrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • squash all to single commit pleaze

.gitignore Outdated
@@ -5,3 +5,4 @@ doc
benchmark/implementations/*
!/benchmark/implementations/current/
.idea
package-lock.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't touch configs if PR is not related

@@ -107,6 +107,7 @@ function encodeHex(character) {
function State(options) {
this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
this.indent = Math.max(1, (options['indent'] || 2));
this.indentArrays = (typeof options['indentArrays'] === 'undefined') ? true : !!options['indentArrays'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest noArrayIndent instead of such logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, done.

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "js-yaml",
"version": "3.12.0",
"version": "3.13.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change configs.

@jacob-hd
Copy link
Contributor Author

jacob-hd commented Jan 4, 2019

@puzrin I have completed all requested changes, and squashed all the commits down to a single commit as requested. Thanks

@jacob-hd
Copy link
Contributor Author

jacob-hd commented Jan 4, 2019

FYI: I highly recommend you use "squash merges" functionality in the repository settings, rather than requiring contributors to rewrite history on their feature branches.

@jacob-hd jacob-hd changed the title Add "indentArrays" option Add "noArrayIndent" option Jan 4, 2019
@puzrin puzrin merged commit 784d1d0 into nodeca:master Jan 4, 2019
@puzrin
Copy link
Member

puzrin commented Jan 4, 2019

Thanks! I know about "squash merges". But it just more convenient for review to to collapse long tail of commits, when only couple of files affected.

@puzrin
Copy link
Member

puzrin commented Feb 18, 2019

@jacob-hd could you take a look at #468 (comment)?

Seems indents become broken when top level array contains objects

@puzrin
Copy link
Member

puzrin commented Apr 24, 2019

@jacob-hd

node -e "console.log(require('js-yaml').dump({ test: [[1, 2], [3,4]]}, { noArrayIndent: true }))"

=>

- - 1
- 2
- - 3
- 4

One more example of bad behaviour. Seems initial PR has not enougth nested samples.

@procaconsul
Copy link

Following on from what @puzrin said about the issue with noArrayIndent, the following also does not work:

node -e "console.log(require('js-yaml').dump({ test: [1, 2, 3, 4]]}, { noArrayIndent: true }))"

=>

test:
  - 1
  - 2
  - 3
  - 4

vs expected

test:
- 1
- 2
- 3
- 4

I suspect that the issue might be resulting from an earlier fix by @diberry (namely https://github.com/diberry/js-yaml/commit/18a871cf69435309598393be86006e39abc9d492), where the level should be >= 0, rather than just > 0, but I am not entirely sure. Just trying to provide a pointer :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants