From 3010dc0e687d035e59ec86ec2a5690cdbee898ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Ma=C5=82olepszy?= Date: Mon, 7 Oct 2024 22:21:28 +0200 Subject: [PATCH] tests for #78 --- rules/checkAlphabeticalOrder.js | 21 ++++++++++-------- .../tests/index.js | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/rules/checkAlphabeticalOrder.js b/rules/checkAlphabeticalOrder.js index 9c5bdab..a315ac4 100644 --- a/rules/checkAlphabeticalOrder.js +++ b/rules/checkAlphabeticalOrder.js @@ -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; } diff --git a/rules/properties-alphabetical-order/tests/index.js b/rules/properties-alphabetical-order/tests/index.js index 4f5260c..da0c089 100644 --- a/rules/properties-alphabetical-order/tests/index.js +++ b/rules/properties-alphabetical-order/tests/index.js @@ -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: [ @@ -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'), + }, ], });