Skip to content

Commit

Permalink
[WIP] First attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Małolepszy committed Oct 8, 2024
1 parent ad96331 commit 46a70cc
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions rules/checkAlphabeticalOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,32 @@ function isShorthand(a, b) {
return longhands.includes(b);
}

function hasPrefix(propName) {
return vendor.prefix(propName).length > 0;
}

export function checkAlphabeticalOrder(firstPropData, secondPropData) {
const firstUnprefixedNameLC = firstPropData.unprefixedName.toLowerCase();
const secondUnprefixedNameLC = secondPropData.unprefixedName.toLowerCase();

// OK if the first is shorthand for the second:
if (isShorthand(firstPropData.unprefixedName, secondPropData.unprefixedName)) {
if (isShorthand(firstUnprefixedNameLC, secondUnprefixedNameLC)) {
return true;
}

// Not OK if the second is shorthand for the first:
if (isShorthand(secondPropData.unprefixedName, firstPropData.unprefixedName)) {
if (isShorthand(firstUnprefixedNameLC, secondUnprefixedNameLC)) {
return false;
}

// If unprefixed prop names are the same, compare the prefixed versions
if (firstPropData.unprefixedName === secondPropData.unprefixedName) {
// If first property has no prefix and second property has prefix
if (
!vendor.prefix(firstPropData.name).length &&
vendor.prefix(secondPropData.name).length
) {
if (firstUnprefixedNameLC === secondUnprefixedNameLC) {
if (!hasPrefix(firstPropData.name) && hasPrefix(secondPropData.name)) {
return false;
}

return true;
}

return firstPropData.unprefixedName < secondPropData.unprefixedName;
return firstUnprefixedNameLC < secondUnprefixedNameLC;
}

0 comments on commit 46a70cc

Please sign in to comment.