format: prettify entire project

This commit is contained in:
Rim
2025-04-02 06:50:39 -04:00
parent 86f0782a98
commit 7ccc0be712
1711 changed files with 755867 additions and 235931 deletions

View File

@ -28,9 +28,18 @@ function hasInvalidCharacters(value) {
if (isEscaped) {
// continue as always
} else if (character == Marker.SINGLE_QUOTE || character == Marker.DOUBLE_QUOTE) {
} else if (
character == Marker.SINGLE_QUOTE ||
character == Marker.DOUBLE_QUOTE
) {
isQuote = !isQuote;
} else if (!isQuote && (character == Marker.CLOSE_CURLY_BRACKET || character == Marker.EXCLAMATION || character == LESS_THAN || character == Marker.SEMICOLON)) {
} else if (
!isQuote &&
(character == Marker.CLOSE_CURLY_BRACKET ||
character == Marker.EXCLAMATION ||
character == LESS_THAN ||
character == Marker.SEMICOLON)
) {
isInvalid = true;
break;
} else if (!isQuote && i === 0 && RELATION_PATTERN.test(character)) {
@ -61,16 +70,23 @@ function removeWhitespace(value, format) {
var wasRelation = false;
var wasWhitespace = false;
var withCaseAttribute = CASE_ATTRIBUTE_PATTERN.test(value);
var spaceAroundRelation = format && format.spaces[Spaces.AroundSelectorRelation];
var spaceAroundRelation =
format && format.spaces[Spaces.AroundSelectorRelation];
var i, l;
for (i = 0, l = value.length; i < l; i++) {
character = value[i];
isNewLineNix = character == Marker.NEW_LINE_NIX;
isNewLineWin = character == Marker.NEW_LINE_NIX && value[i - 1] == Marker.CARRIAGE_RETURN;
isNewLineWin =
character == Marker.NEW_LINE_NIX &&
value[i - 1] == Marker.CARRIAGE_RETURN;
isQuoted = isSingleQuoted || isDoubleQuoted;
isRelation = !isAttribute && !isEscaped && roundBracketLevel === 0 && RELATION_PATTERN.test(character);
isRelation =
!isAttribute &&
!isEscaped &&
roundBracketLevel === 0 &&
RELATION_PATTERN.test(character);
isWhitespace = WHITESPACE_PATTERN.test(character);
if (wasEscaped && isQuoted && isNewLineWin) {
@ -111,11 +127,19 @@ function removeWhitespace(value, format) {
} else if (!isWhitespace && wasRelation && spaceAroundRelation) {
stripped.push(Marker.SPACE);
stripped.push(character);
} else if (isWhitespace && (isAttribute || roundBracketLevel > 0) && !isQuoted) {
} else if (
isWhitespace &&
(isAttribute || roundBracketLevel > 0) &&
!isQuoted
) {
// skip space
} else if (isWhitespace && wasWhitespace && !isQuoted) {
// skip extra space
} else if ((isNewLineWin || isNewLineNix) && (isAttribute || roundBracketLevel > 0) && isQuoted) {
} else if (
(isNewLineWin || isNewLineNix) &&
(isAttribute || roundBracketLevel > 0) &&
isQuoted
) {
// skip newline
} else if (isRelation && wasWhitespace && !spaceAroundRelation) {
stripped.pop();
@ -136,12 +160,12 @@ function removeWhitespace(value, format) {
}
return withCaseAttribute ?
stripped.join('').replace(CASE_RESTORE_PATTERN, '$1 $2]') :
stripped.join('');
stripped.join('').replace(CASE_RESTORE_PATTERN, '$1 $2]')
: stripped.join('');
}
function removeQuotes(value) {
if (value.indexOf('\'') == -1 && value.indexOf('"') == -1) {
if (value.indexOf("'") == -1 && value.indexOf('"') == -1) {
return value;
}
@ -157,7 +181,13 @@ function tidyRules(rules, removeUnsupported, adjacentSpace, format, warnings) {
var repeated = [];
function removeHTMLComment(rule, match) {
warnings.push('HTML comment \'' + match + '\' at ' + formatPosition(rule[2][0]) + '. Removing.');
warnings.push(
"HTML comment '" +
match +
"' at " +
formatPosition(rule[2][0]) +
'. Removing.'
);
return '';
}
@ -165,10 +195,19 @@ function tidyRules(rules, removeUnsupported, adjacentSpace, format, warnings) {
var rule = rules[i];
var reduced = rule[1];
reduced = reduced.replace(HTML_COMMENT_PATTERN, removeHTMLComment.bind(null, rule));
reduced = reduced.replace(
HTML_COMMENT_PATTERN,
removeHTMLComment.bind(null, rule)
);
if (hasInvalidCharacters(reduced)) {
warnings.push('Invalid selector \'' + rule[1] + '\' at ' + formatPosition(rule[2][0]) + '. Ignoring.');
warnings.push(
"Invalid selector '" +
rule[1] +
"' at " +
formatPosition(rule[2][0]) +
'. Ignoring.'
);
continue;
}
@ -183,7 +222,10 @@ function tidyRules(rules, removeUnsupported, adjacentSpace, format, warnings) {
continue;
}
if (removeUnsupported && reduced.indexOf(ASTERISK_FIRST_CHILD_PLUS_HTML_HACK) > -1) {
if (
removeUnsupported &&
reduced.indexOf(ASTERISK_FIRST_CHILD_PLUS_HTML_HACK) > -1
) {
continue;
}
@ -203,7 +245,13 @@ function tidyRules(rules, removeUnsupported, adjacentSpace, format, warnings) {
}
if (list.length == 1 && list[0][1].length === 0) {
warnings.push('Empty selector \'' + list[0][1] + '\' at ' + formatPosition(list[0][2][0]) + '. Ignoring.');
warnings.push(
"Empty selector '" +
list[0][1] +
"' at " +
formatPosition(list[0][2][0]) +
'. Ignoring.'
);
list = [];
}