Skip to content

Commit

Permalink
Allow min_attrs=1 for force-expand-multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
ang-zeyu committed Apr 20, 2021
1 parent 6edbfb5 commit d8bcf29
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/src/html/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
if (this._is_wrap_attributes_force &&
last_tag_token.attr_count >= this._options.wrap_attributes_min_attrs &&
(last_token.type !== TOKEN.TAG_OPEN || // ie. second attribute and beyond
(this._is_wrap_attributes_force_expand_multiline && last_tag_token.attr_count > 1))) {
this._is_wrap_attributes_force_expand_multiline)) {
printer.print_newline(false);
wrapped = true;
}
Expand Down
34 changes: 34 additions & 0 deletions test/data/html/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,40 @@ exports.test_data = {
'</cmpnt>'
]
}]
}, {
name: "Test wrap_attributes_min_attrs = 1 with force/force-xx options",
description: "",
matrix: [{
// Should not wrap, by design
options: [
{ name: "wrap_attributes", value: "'force'" },
{ name: "wrap_attributes_min_attrs", value: "1" }
],
indent_attr: ' ',
newline_end: ' '
}, {
// Should not wrap, by design
options: [
{ name: "wrap_attributes", value: "'force-aligned'" },
{ name: "wrap_attributes_min_attrs", value: "1" }
],
indent_attr: ' ',
newline_end: ' '
}, {
// Should wrap
options: [
{ name: "wrap_attributes", value: "'force-expand-multiline'" },
{ name: "wrap_attributes_min_attrs", value: "1" }
],
indent_attr: '\n ',
newline_end: '\n'
}],
tests: [{
input: [
'<input type="one attribute"/>'
],
output: '<input{{indent_attr}}type="one attribute"{{newline_end}}/>'
}]
}, {
name: "Handlebars Indenting Off",
description: "Test handlebar behavior when indenting is off",
Expand Down

0 comments on commit d8bcf29

Please sign in to comment.