Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for ignoring properties case for ordering. Related to #78 #196

Merged
merged 6 commits into from
Oct 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[WIP] First attempt
  • Loading branch information
Szymon Małolepszy committed Oct 8, 2024
commit 46a70cc159a1ea5f84b052fe6de75fd8fd29afa3
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;
}
Loading