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 option to enforce flow syntax for arrays #653

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion dist/js-yaml.js
Expand Up @@ -2943,6 +2943,7 @@
this.schema = options['schema'] || _default;
this.indent = Math.max(1, (options['indent'] || 2));
this.noArrayIndent = options['noArrayIndent'] || false;
this.noArrayBlock = options['noArrayBlock'] || false;
this.skipInvalid = options['skipInvalid'] || false;
this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
Expand Down Expand Up @@ -3669,7 +3670,7 @@
}
}
} else if (type === '[object Array]') {
if (block && (state.dump.length !== 0)) {
if (block && (state.dump.length !== 0) && !state.noArrayBlock) {
if (state.noArrayIndent && !isblockseq && level > 0) {
writeBlockSequence(state, level - 1, state.dump, compact);
} else {
Expand Down
2 changes: 1 addition & 1 deletion dist/js-yaml.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/js-yaml.mjs
Expand Up @@ -2937,6 +2937,7 @@ function State(options) {
this.schema = options['schema'] || _default;
this.indent = Math.max(1, (options['indent'] || 2));
this.noArrayIndent = options['noArrayIndent'] || false;
this.noArrayBlock = options['noArrayBlock'] || false;
this.skipInvalid = options['skipInvalid'] || false;
this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
Expand Down Expand Up @@ -3663,7 +3664,7 @@ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
}
}
} else if (type === '[object Array]') {
if (block && (state.dump.length !== 0)) {
if (block && (state.dump.length !== 0) && !state.noArrayBlock) {
if (state.noArrayIndent && !isblockseq && level > 0) {
writeBlockSequence(state, level - 1, state.dump, compact);
} else {
Expand Down
3 changes: 2 additions & 1 deletion lib/dumper.js
Expand Up @@ -116,6 +116,7 @@ function State(options) {
this.schema = options['schema'] || DEFAULT_SCHEMA;
this.indent = Math.max(1, (options['indent'] || 2));
this.noArrayIndent = options['noArrayIndent'] || false;
this.noArrayBlock = options['noArrayBlock'] || false;
this.skipInvalid = options['skipInvalid'] || false;
this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
Expand Down Expand Up @@ -842,7 +843,7 @@ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
}
}
} else if (type === '[object Array]') {
if (block && (state.dump.length !== 0)) {
if (block && (state.dump.length !== 0) && !state.noArrayBlock) {
if (state.noArrayIndent && !isblockseq && level > 0) {
writeBlockSequence(state, level - 1, state.dump, compact);
} else {
Expand Down