Skip to content

Commit

Permalink
tests for hudochenkov#78
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Małolepszy committed Oct 7, 2024
1 parent 3a6ece9 commit 3010dc0
Show file tree
Hide file tree
Showing 2 changed files with 34 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;
}
22 changes: 22 additions & 0 deletions rules/properties-alphabetical-order/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ testRule({
{
code: 'a { font-size: 1px; -moz-osx-font-smoothing: grayscale; -webkit-font-smoothing: antialised; font-weight: bold; }',
},
{
// blocked by https://github.com/hudochenkov/stylelint-order/issues/78
skip: true,
code: 'a { display: block; margin: 0 auto 5px 0; Margin: 0 auto 5px 0; width: auto; }',
},
{
// blocked by https://github.com/hudochenkov/stylelint-order/issues/78
skip: true,
code: 'a { display: block; Margin: 0 auto 5px 0; margin: 0 auto 5px 0; width: auto; }',
},
{
// blocked by https://github.com/hudochenkov/stylelint-order/issues/78
skip: true,
code: 'a { align: center: Border-width: 1px; Border-top-width: 2px; color: red; }',
},
],

reject: [
Expand Down Expand Up @@ -131,6 +146,13 @@ testRule({
fixed: '@media print { color: red; top: 0; }',
message: messages.expected('color', 'top'),
},
{
// blocked by https://github.com/hudochenkov/stylelint-order/issues/78
skip: true,
code: 'a { align: center; Border-top-width: 2px; Border-width: 1px; color: red; }',
fixed: 'a { align: center; Border-width: 1px; Border-top-width: 2px; color: red; }',
message: messages.expected('Border-width', 'Border-top-width'),
},
],
});

Expand Down

0 comments on commit 3010dc0

Please sign in to comment.