Skip to content

Commit 6a5b055

Browse files
1 parent 50b7b91 commit 6a5b055

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

lib/rules/enforces-shorthand.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ module.exports = {
240240
const hasL = sameVariantAndValue.some((c) => c.shorthand === 'l') || (hasTL && hasBL);
241241
const hasX = sameVariantAndValue.some((c) => c.shorthand === 'x') || (hasL && hasR);
242242
const hasY = sameVariantAndValue.some((c) => c.shorthand === 'y') || (hasT && hasB);
243-
const hasAll = sameVariantAndValue.some((c) => c.shorthand === 'all') || (hasY && hasX);
243+
const hasAll =
244+
sameVariantAndValue.some((c) => c.shorthand === 'all') || !supportCorners
245+
? hasY && hasX
246+
: (hasL && hasR) || (hasT && hasB);
244247
const important = cls.important ? '!' : '';
245248
const isNegative = ('' + cls.value).substring(0, 1) === '-';
246249
const minus = isNegative ? '-' : '';
@@ -249,15 +252,15 @@ module.exports = {
249252
if (hasAll) {
250253
const all = getBodyByShorthand(targetGroups, classname.parentType, 'all');
251254
const val = absoluteVal.length ? '-' + absoluteVal : '';
252-
const patchedName = `${cls.variants}${important}${minus}${all}${val}`;
255+
const patchedName = `${cls.variants}${important}${minus}${mergedConfig.prefix}${all}${val}`;
253256
troubles.push([sameVariantAndValue.map((c) => c.name), patchedName]);
254257
cls.name = patchedName;
255258
cls.shorthand = 'all';
256259
validated.push(cls);
257260
} else if (hasY || hasX) {
258261
const xOrY = hasX ? 'x' : 'y';
259262
const xOrYType = getBodyByShorthand(targetGroups, classname.parentType, xOrY);
260-
const patchedName = `${cls.variants}${important}${minus}${xOrYType}${
263+
const patchedName = `${cls.variants}${important}${minus}${mergedConfig.prefix}${xOrYType}${
261264
absoluteVal.length ? '-' + absoluteVal : ''
262265
}`;
263266
const toBeReplaced = sameVariantAndValue
@@ -288,7 +291,7 @@ module.exports = {
288291
const side = hasT ? 't' : hasR ? 'r' : hasB ? 'b' : 'l';
289292
const sideBody = getBodyByShorthand(targetGroups, classname.parentType, side);
290293
const val = absoluteVal.length ? '-' + absoluteVal : '';
291-
const patchedName = `${cls.variants}${important}${minus}${sideBody}${val}`;
294+
const patchedName = `${cls.variants}${important}${minus}${mergedConfig.prefix}${sideBody}${val}`;
292295
const toBeReplaced = sameVariantAndValue
293296
.filter((c) => {
294297
const candidates = hasT ? ['tl', 'tr'] : hasR ? ['tr', 'br'] : hasB ? ['bl', 'br'] : ['tl', 'bl'];

tests/lib/rules/enforces-shorthand.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,5 +398,25 @@ ruleTester.run("shorthands", rule, {
398398
output: `classnames({'md:!rounded-tr block md:rounded-tl md:rounded-b': true})`,
399399
errors: [generateError(["md:rounded-br", "md:rounded-bl"], "md:rounded-b")],
400400
},
401+
{
402+
code: `classnames('sfc-border-l-0 sfc-border-r-0')`,
403+
output: `classnames('sfc-border-x-0')`,
404+
options: [
405+
{
406+
config: { prefix: "sfc-" },
407+
},
408+
],
409+
errors: [generateError(["sfc-border-l-0", "sfc-border-r-0"], "sfc-border-x-0")],
410+
},
411+
{
412+
code: `classnames('md_sfc-border-l-0 md_sfc-border-r-0')`,
413+
output: `classnames('md_sfc-border-x-0')`,
414+
options: [
415+
{
416+
config: { prefix: "sfc-", separator: "_" },
417+
},
418+
],
419+
errors: [generateError(["md_sfc-border-l-0", "md_sfc-border-r-0"], "md_sfc-border-x-0")],
420+
},
401421
],
402422
});

0 commit comments

Comments
 (0)