Skip to content

Add "noArrayIndent" option#461

Merged
puzrin merged 1 commit intonodeca:masterfrom
jacob-hd:jacob
Jan 4, 2019
Merged

Add "noArrayIndent" option#461
puzrin merged 1 commit intonodeca:masterfrom
jacob-hd:jacob

Conversation

@jacob-hd
Copy link
Copy Markdown
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.

Comment thread lib/js-yaml/dumper.js Outdated
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
Copy Markdown
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.

Comment thread .gitignore Outdated
benchmark/implementations/*
!/benchmark/implementations/current/
.idea
package-lock.json
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread package.json Outdated
{
"name": "js-yaml",
"version": "3.12.0",
"version": "3.13.0",
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread .gitignore Outdated
benchmark/implementations/*
!/benchmark/implementations/current/
.idea
package-lock.json
Copy link
Copy Markdown
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

Comment thread lib/js-yaml/dumper.js Outdated
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
Copy Markdown
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
Copy Markdown
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.

Comment thread package.json Outdated
{
"name": "js-yaml",
"version": "3.12.0",
"version": "3.13.0",
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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.

3 participants