Skip to content

Commit e6133d7

Browse files
feat: issue #376
1 parent 79c4c0e commit e6133d7

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

lib/rules/enforces-shorthand.js

+30-3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ module.exports = {
7373
// Helpers
7474
//----------------------------------------------------------------------
7575

76+
const placeContentOptions = ['center', 'start', 'end', 'between', 'around', 'evenly', 'baseline', 'stretch'];
77+
const placeItemsOptions = ['start', 'end', 'center', 'stretch'];
78+
const placeSelfOptions = ['auto', 'start', 'end', 'center', 'stretch'];
7679
// These are shorthand candidates that do not share the same parent type
7780
const complexEquivalences = [
7881
{
@@ -85,6 +88,27 @@ module.exports = {
8588
shorthand: 'size-',
8689
mode: 'value',
8790
},
91+
...placeContentOptions.map((opt) => {
92+
return {
93+
needles: [`content-${opt}`, `justify-${opt}`],
94+
shorthand: `place-content-${opt}`,
95+
mode: 'exact',
96+
};
97+
}),
98+
...placeItemsOptions.map((opt) => {
99+
return {
100+
needles: [`items-${opt}`, `justify-items-${opt}`],
101+
shorthand: `place-items-${opt}`,
102+
mode: 'exact',
103+
};
104+
}),
105+
...placeSelfOptions.map((opt) => {
106+
return {
107+
needles: [`self-${opt}`, `justify-self-${opt}`],
108+
shorthand: `place-self-${opt}`,
109+
mode: 'exact',
110+
};
111+
}),
88112
];
89113

90114
// Init assets
@@ -243,7 +267,9 @@ module.exports = {
243267
}
244268
// Test if the body of the class matches, eg. 'h-' inside 'h-10'
245269
if (mode === 'value') {
246-
const bodyMatch = inputSet.some((inputClassPattern) => `${mergedConfig.prefix}${inputClassPattern}` === remainingClass.body);
270+
const bodyMatch = inputSet.some(
271+
(inputClassPattern) => `${mergedConfig.prefix}${inputClassPattern}` === remainingClass.body
272+
);
247273
if ([undefined, null].includes(mergedConfig.theme.size)) {
248274
return false;
249275
}
@@ -362,8 +388,9 @@ module.exports = {
362388
} else if (hasY || hasX) {
363389
const xOrY = hasX ? 'x' : 'y';
364390
const xOrYType = getBodyByShorthand(targetGroups, classname.parentType, xOrY);
365-
const patchedName = `${cls.variants}${important}${minus}${mergedConfig.prefix}${xOrYType}${absoluteVal.length ? '-' + absoluteVal : ''
366-
}`;
391+
const patchedName = `${cls.variants}${important}${minus}${mergedConfig.prefix}${xOrYType}${
392+
absoluteVal.length ? '-' + absoluteVal : ''
393+
}`;
367394
const toBeReplaced = sameVariantAndValue
368395
.filter((c) => {
369396
const candidates = hasX ? ['l', 'r'] : ['t', 'b'];

tests/lib/rules/enforces-shorthand.js

+9
Original file line numberDiff line numberDiff line change
@@ -823,5 +823,14 @@ ruleTester.run("shorthands", rule, {
823823
},
824824
],
825825
},
826+
{
827+
code: `<div class="content-center justify-center sm:items-start sm:justify-items-start md:self-end md:justify-self-end lg:self-start lg:justify-self-center">issue #376</div>`,
828+
output: `<div class="place-content-center sm:place-items-start md:place-self-end lg:self-start lg:justify-self-center">issue #376</div>`,
829+
errors: [
830+
generateError(["content-center", "justify-center"], "place-content-center"),
831+
generateError(["sm:items-start", "sm:justify-items-start"], "sm:place-items-start"),
832+
generateError(["md:self-end", "md:justify-self-end"], "md:place-self-end"),
833+
],
834+
},
826835
],
827836
});

0 commit comments

Comments
 (0)