checkAlphabeticalOrder.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. const postcss = require('postcss');
  2. const shorthandData = require('./shorthandData');
  3. function isShorthand(a, b) {
  4. const longhands = shorthandData[a] || [];
  5. return longhands.includes(b);
  6. }
  7. module.exports = function checkAlphabeticalOrder(firstPropData, secondPropData) {
  8. // OK if the first is shorthand for the second:
  9. if (isShorthand(firstPropData.unprefixedName, secondPropData.unprefixedName)) {
  10. return true;
  11. }
  12. // Not OK if the second is shorthand for the first:
  13. if (isShorthand(secondPropData.unprefixedName, firstPropData.unprefixedName)) {
  14. return false;
  15. }
  16. // If unprefixed prop names are the same, compare the prefixed versions
  17. if (firstPropData.unprefixedName === secondPropData.unprefixedName) {
  18. // If first property has no prefix and second property has prefix
  19. if (
  20. !postcss.vendor.prefix(firstPropData.name).length &&
  21. postcss.vendor.prefix(secondPropData.name).length
  22. ) {
  23. return false;
  24. }
  25. return true;
  26. }
  27. return firstPropData.unprefixedName < secondPropData.unprefixedName;
  28. };