diff --git a/lib/rules/enforces-shorthand.js b/lib/rules/enforces-shorthand.js index b1f1472..f83fc23 100644 --- a/lib/rules/enforces-shorthand.js +++ b/lib/rules/enforces-shorthand.js @@ -245,8 +245,10 @@ module.exports = { if (mode === 'value') { const bodyMatch = inputSet.some((inputClassPattern) => inputClassPattern === remainingClass.body); // w-screen + h-screen ≠ size-screen (Issue #307) - const validValue = - bodyMatch && !(['w-', 'h-'].includes(remainingClass.body) && ['screen'].includes(remainingClass.value)); + const spacingKeys = Object.keys(mergedConfig.theme.spacing); + const isSize = ['w-', 'h-'].includes(remainingClass.body); + const isValidSize = spacingKeys.includes(remainingClass.value); + const validValue = bodyMatch && !(isSize && !isValidSize); return validValue; } }); diff --git a/tests/lib/rules/enforces-shorthand.js b/tests/lib/rules/enforces-shorthand.js index 0d1ae73..ec58593 100644 --- a/tests/lib/rules/enforces-shorthand.js +++ b/tests/lib/rules/enforces-shorthand.js @@ -34,6 +34,33 @@ const skipClassAttributeOptions = [ }, ]; +const customWidthHeightOptions = [ + { + config: { + theme: { + extend: { + width: { custom: "100px" }, + height: { custom: "100px" }, + }, + }, + plugins: [], + }, + }, +]; + +const customSpacingOptions = [ + { + config: { + theme: { + extend: { + spacing: { custom: "100px" }, + }, + }, + plugins: [], + }, + }, +]; + var generateError = (classnames, shorthand) => { return { messageId: "shorthandCandidateDetected", @@ -132,6 +159,10 @@ ruleTester.run("shorthands", rule, { { code: "
issue #307
", }, + { + code: `
size-* is based on spacing
`, + options: customWidthHeightOptions, + }, ], invalid: [ @@ -727,5 +758,11 @@ ruleTester.run("shorthands", rule, { output: `
New size-* utilities
`, errors: [generateError(["md:h-5", "md:w-5"], "md:size-5")], }, + { + code: `
size-* is based on spacing
`, + output: `
size-* is based on spacing
`, + errors: [generateError(["h-custom", "w-custom"], "size-custom")], + options: customSpacingOptions, + }, ], });