From b68883ba0b277f1b7c67501f22c6c62a70205f14 Mon Sep 17 00:00:00 2001 From: Mradul Singh Date: Mon, 16 Nov 2026 03:59:48 +0530 Subject: [PATCH] Sort gap, place-* and other missing shorthands before their longhands With properties-order: 'alphabetical', gap, place-content, place-items, place-self and contain-intrinsic-size were sorted after some of their longhands (column-gap, align-content, ...), because they were missing from the shorthand list. The shorthand then overrides the longhand. Also add the other shorthands from Stylelint's list: font-variant, font-synthesis, scroll-margin, scroll-padding (and their block/inline forms), and text-decoration-thickness for text-decoration. Refs hudochenkov/stylelint-order#224 --- CHANGELOG.md | 1 + ...operties-alphabetical-shorthand-modern.css | 34 +++++++++++++++ ...alphabetical-shorthand-modern.expected.css | 34 +++++++++++++++ .../__tests__/isShorthand.test.js | 16 +++++++ .../__tests__/properties-order.js | 5 +++ lib/properties-order/shorthandData.js | 42 ++++++++++++++++++- 6 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand-modern.css create mode 100644 lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand-modern.expected.css diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cca4c9..ca4b095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## Unreleased * Fixed `order`: an at-rule pattern with `parameter` no longer matches at-rules that have no parameters. +* Fixed `properties-order: 'alphabetical'`: `gap`, `place-content`, `place-items`, `place-self` and `contain-intrinsic-size` are now sorted before their longhands. Also added `font-variant`, `font-synthesis`, `scroll-margin`, `scroll-padding` and `text-decoration-thickness` to the shorthand list. * Improved performance. Sorting is about 2x to 10x faster depending on the stylesheet: roughly 4–5× on typical CSS using both `order` and `properties-order`, and more on large rules or stylesheets with many rules or comments ## 10.0.0 diff --git a/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand-modern.css b/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand-modern.css new file mode 100644 index 0000000..e229470 --- /dev/null +++ b/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand-modern.css @@ -0,0 +1,34 @@ +a { + column-gap: 2px; + gap: 1px; +} + +a { + justify-content: end; + align-content: start; + place-content: center; +} + +a { + justify-items: end; + place-items: center; + align-items: start; +} + +a { + align-self: start; + place-self: center; + justify-self: end; +} + +a { + contain-intrinsic-width: 30px; + contain-intrinsic-height: 20px; + contain-intrinsic-size: 10px; +} + +a { + gap: 1px; + row-gap: 3px; + column-gap: 2px; +} diff --git a/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand-modern.expected.css b/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand-modern.expected.css new file mode 100644 index 0000000..fef9659 --- /dev/null +++ b/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand-modern.expected.css @@ -0,0 +1,34 @@ +a { + gap: 1px; + column-gap: 2px; +} + +a { + place-content: center; + align-content: start; + justify-content: end; +} + +a { + place-items: center; + align-items: start; + justify-items: end; +} + +a { + place-self: center; + align-self: start; + justify-self: end; +} + +a { + contain-intrinsic-size: 10px; + contain-intrinsic-height: 20px; + contain-intrinsic-width: 30px; +} + +a { + gap: 1px; + column-gap: 2px; + row-gap: 3px; +} diff --git a/lib/properties-order/__tests__/isShorthand.test.js b/lib/properties-order/__tests__/isShorthand.test.js index 645aad4..e588f6e 100644 --- a/lib/properties-order/__tests__/isShorthand.test.js +++ b/lib/properties-order/__tests__/isShorthand.test.js @@ -23,3 +23,19 @@ test('border-inline is shorthand for border-top-color', () => { test('border-top-color is not shorthand for border-inline', () => { expect(isShorthand('border-top-color', 'border-inline')).toBe(false); }); + +test.each([ + ['gap', 'column-gap'], + ['place-content', 'justify-content'], + ['place-items', 'align-items'], + ['place-self', 'justify-self'], + ['contain-intrinsic-size', 'contain-intrinsic-width'], + ['font', 'font-variant-caps'], + ['font-synthesis', 'font-synthesis-weight'], + ['scroll-margin', 'scroll-margin-top'], + ['scroll-padding-inline', 'scroll-padding-inline-end'], + ['text-decoration', 'text-decoration-thickness'], +])('%s is shorthand for %s', (shorthand, longhand) => { + expect(isShorthand(shorthand, longhand)).toBe(true); + expect(isShorthand(longhand, shorthand)).toBe(false); +}); diff --git a/lib/properties-order/__tests__/properties-order.js b/lib/properties-order/__tests__/properties-order.js index 4264896..c6d4580 100644 --- a/lib/properties-order/__tests__/properties-order.js +++ b/lib/properties-order/__tests__/properties-order.js @@ -102,6 +102,11 @@ test('Should sort shorthand properties before their longhand versions', () => 'properties-order': 'alphabetical', })); +test('Should sort gap, place-* and contain-intrinsic-size before their longhands', () => + runTest('properties-alphabetical-shorthand-modern', { + 'properties-order': 'alphabetical', + })); + test('Should sort prefixed properties before unprefixed property in alphabetical order', () => runTest('prefixed-alphabetical', { 'properties-order': 'alphabetical', diff --git a/lib/properties-order/shorthandData.js b/lib/properties-order/shorthandData.js index 007b7da..e3967bb 100644 --- a/lib/properties-order/shorthandData.js +++ b/lib/properties-order/shorthandData.js @@ -281,6 +281,10 @@ export const shorthandData = { 'grid-area': ['grid-row-start', 'grid-column-start', 'grid-row-end', 'grid-column-end'], 'grid-column': ['grid-column-start', 'grid-column-end'], 'grid-gap': ['grid-row-gap', 'grid-column-gap'], + gap: ['row-gap', 'column-gap'], + 'place-content': ['align-content', 'justify-content'], + 'place-items': ['align-items', 'justify-items'], + 'place-self': ['align-self', 'justify-self'], 'grid-row': ['grid-row-start', 'grid-row-end'], 'grid-template': ['grid-template-columns', 'grid-template-rows', 'grid-template-areas'], offset: ['offset-anchor', 'offset-distance', 'offset-path', 'offset-position', 'offset-rotate'], @@ -296,7 +300,12 @@ export const shorthandData = { ], 'overscroll-behavior-block': ['overscroll-behavior-x', 'overscroll-behavior-y'], 'overscroll-behavior-inline': ['overscroll-behavior-x', 'overscroll-behavior-y'], - 'text-decoration': ['text-decoration-color', 'text-decoration-style', 'text-decoration-line'], + 'text-decoration': [ + 'text-decoration-color', + 'text-decoration-style', + 'text-decoration-line', + 'text-decoration-thickness', + ], 'text-emphasis': ['text-emphasis-style', 'text-emphasis-color'], mask: [ 'mask-image', @@ -323,4 +332,35 @@ export const shorthandData = { 'inset-block-end': ['top', 'bottom', 'left', 'right'], 'inset-inline-start': ['top', 'bottom', 'left', 'right'], 'inset-inline-end': ['top', 'bottom', 'left', 'right'], + 'contain-intrinsic-size': ['contain-intrinsic-width', 'contain-intrinsic-height'], + 'font-synthesis': [ + 'font-synthesis-weight', + 'font-synthesis-style', + 'font-synthesis-small-caps', + ], + 'font-variant': [ + 'font-variant-ligatures', + 'font-variant-position', + 'font-variant-caps', + 'font-variant-numeric', + 'font-variant-alternates', + 'font-variant-east-asian', + 'font-variant-emoji', + ], + 'scroll-margin': [ + 'scroll-margin-top', + 'scroll-margin-right', + 'scroll-margin-bottom', + 'scroll-margin-left', + ], + 'scroll-margin-block': ['scroll-margin-block-start', 'scroll-margin-block-end'], + 'scroll-margin-inline': ['scroll-margin-inline-start', 'scroll-margin-inline-end'], + 'scroll-padding': [ + 'scroll-padding-top', + 'scroll-padding-right', + 'scroll-padding-bottom', + 'scroll-padding-left', + ], + 'scroll-padding-block': ['scroll-padding-block-start', 'scroll-padding-block-end'], + 'scroll-padding-inline': ['scroll-padding-inline-start', 'scroll-padding-inline-end'], };