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