From d8bcf29f682e6a9d084c5d8c9ba00b8bb60e38b6 Mon Sep 17 00:00:00 2001 From: Ze Yu Date: Tue, 20 Apr 2021 14:18:45 +0800 Subject: [PATCH] Allow min_attrs=1 for force-expand-multiline --- js/src/html/beautifier.js | 2 +- test/data/html/tests.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/js/src/html/beautifier.js b/js/src/html/beautifier.js index 714cfc930..b6bcb8346 100644 --- a/js/src/html/beautifier.js +++ b/js/src/html/beautifier.js @@ -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; } diff --git a/test/data/html/tests.js b/test/data/html/tests.js index ae83739a3..23cfc4c9f 100644 --- a/test/data/html/tests.js +++ b/test/data/html/tests.js @@ -1258,6 +1258,40 @@ exports.test_data = { '' ] }] + }, { + 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: [ + '' + ], + output: '' + }] }, { name: "Handlebars Indenting Off", description: "Test handlebar behavior when indenting is off",