diff --git a/changelog_unreleased/html/11827.md b/changelog_unreleased/html/11827.md new file mode 100644 index 000000000..64380852e --- /dev/null +++ b/changelog_unreleased/html/11827.md @@ -0,0 +1 @@ +#### Reverts #7865, keeping class names on the same line (#11827 by @jlongster) diff --git a/src/language-html/syntax-attribute.js b/src/language-html/syntax-attribute.js index 130d77855..47de2e84d 100644 --- a/src/language-html/syntax-attribute.js +++ b/src/language-html/syntax-attribute.js @@ -1,9 +1,8 @@ "use strict"; const parseSrcset = require("parse-srcset"); -const getLast = require("../utils/get-last.js"); const { - builders: { group, ifBreak, indent, join, line, softline }, + builders: { ifBreak, join, line }, } = require("../document/index.js"); function printImgSrcset(value) { @@ -60,50 +59,8 @@ function printImgSrcset(value) { ); } -const prefixDelimiters = [":", "__", "--", "_", "-"]; - -function getClassPrefix(className) { - const startIndex = className.search(/[^_-]/); - if (startIndex !== -1) { - for (const delimiter of prefixDelimiters) { - const delimiterIndex = className.indexOf(delimiter, startIndex); - if (delimiterIndex !== -1) { - return className.slice(0, delimiterIndex); - } - } - } - return className; -} - function printClassNames(value) { - const classNames = value.trim().split(/\s+/); - - // Try keeping consecutive classes with the same prefix on one line. - const groupedByPrefix = []; - let previousPrefix; - for (let i = 0; i < classNames.length; i++) { - const prefix = getClassPrefix(classNames[i]); - if ( - prefix !== previousPrefix && - // "home-link" and "home-link_blue_yes" should be considered same-prefix - prefix !== classNames[i - 1] - ) { - groupedByPrefix.push([]); - } - getLast(groupedByPrefix).push(classNames[i]); - previousPrefix = prefix; - } - - return [ - indent([ - softline, - join( - line, - groupedByPrefix.map((classNames) => group(join(line, classNames))) - ), - ]), - softline, - ]; + return value.trim().split(/\s+/).join(" "); } module.exports = { diff --git a/tests/format/angular/angular/__snapshots__/jsfmt.spec.js.snap b/tests/format/angular/angular/__snapshots__/jsfmt.spec.js.snap index 0f0b5368a..da59661d4 100644 --- a/tests/format/angular/angular/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/angular/angular/__snapshots__/jsfmt.spec.js.snap @@ -110,9 +110,7 @@ printWidth: 1
{{ copyTypes[ @@ -8063,9 +8052,7 @@ can be found in the LICENSE file at http://angular.io/license

top @@ -8086,9 +8073,7 @@ can be found in the LICENSE file at http://angular.io/license [hidden]="isUnchanged")

{{ title @@ -8135,9 +8120,7 @@ can be found in the LICENSE file at http://angular.io/license (keyup)=" (0) " - class=" - context - " + class="context" > Type something: @@ -8150,9 +8133,7 @@ can be found in the LICENSE file at http://angular.io/license
top @@ -8174,9 +8155,7 @@ can be found in the LICENSE file at http://angular.io/license )

top @@ -8466,9 +8431,7 @@ can be found in the LICENSE file at http://angular.io/license /> top @@ -8545,9 +8508,7 @@ can be found in the LICENSE file at http://angular.io/license top @@ -8709,9 +8670,7 @@ can be found in the LICENSE file at http://angular.io/license

top @@ -8805,9 +8764,7 @@ can be found in the LICENSE file at http://angular.io/license
top @@ -8823,11 +8780,7 @@ can be found in the LICENSE file at http://angular.io/license
Bad curly @@ -8836,11 +8789,7 @@ can be found in the LICENSE file at http://angular.io/license
top @@ -8948,9 +8893,7 @@ can be found in the LICENSE file at http://angular.io/license top @@ -9025,9 +8968,7 @@ can be found in the LICENSE file at http://angular.io/license
Click me @@ -9087,9 +9026,7 @@ can be found in the LICENSE file at http://angular.io/license
top @@ -9147,9 +9084,7 @@ can be found in the LICENSE file at http://angular.io/license
top @@ -9222,9 +9157,7 @@ bindon-ngModel (ngModelChange)="setUppercaseName($event)" top @@ -9349,11 +9282,7 @@ bindon-ngModel
Bad curly @@ -9371,9 +9300,7 @@ bindon-ngModel
top @@ -9506,9 +9433,7 @@ bindon-ngModel
top @@ -9636,9 +9561,7 @@ bindon-ngModel
top @@ -9653,9 +9576,7 @@ bindon-ngModel
top @@ -9708,9 +9625,7 @@ bindon-ngModel separator

top @@ -9805,9 +9716,7 @@ bindon-ngModel trackBy

top @@ -10096,9 +9993,7 @@ bindon-ngModel
top @@ -10166,9 +10061,7 @@ bindon-ngModel > top @@ -10222,9 +10115,7 @@ bindon-ngModel }} top @@ -10302,9 +10193,7 @@ bindon-ngModel
top @@ -10401,9 +10290,7 @@ See console log:
top @@ -10440,9 +10327,7 @@ See console log:
top @@ -10494,9 +10379,7 @@ See console log:
top @@ -10558,9 +10441,7 @@ See console log:

top @@ -10583,17 +10464,13 @@ can be found in the LICENSE file at http://angular.io/license #heroForm="ngForm" >
@@ -316,11 +304,7 @@ printWidth: 80
=====================================output===================================== - + @@ -537,34 +465,10 @@ width="205px" alt="Yahoo"/>