From 0d2d29c4766627f6774af8435c25fc05482a2e1e Mon Sep 17 00:00:00 2001 From: Alexander Kachkaev Date: Mon, 15 Jan 2024 18:35:53 +0000 Subject: [PATCH 1/2] Add test cases (one is broken) --- tests/lib/rules/enforces-shorthand.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/lib/rules/enforces-shorthand.js b/tests/lib/rules/enforces-shorthand.js index d14368b8..8d143476 100644 --- a/tests/lib/rules/enforces-shorthand.js +++ b/tests/lib/rules/enforces-shorthand.js @@ -691,6 +691,26 @@ ruleTester.run("shorthands", rule, { `, errors: [generateError(["overflow-hidden", "text-ellipsis", "whitespace-nowrap"], "truncate")], }, + { + code: "
Leading space trim issue with fix
", + output: "
Leading space trim issue with fix
", + errors: [generateError(["px-10", "py-10"], "p-10")], + }, + { + code: "
Leading space trim issue with fix (2)
", + output: "
Leading space trim issue with fix (2)
", + errors: [generateError(["px-10", "py-10"], "p-10")], + }, + { + code: "
Trailing space trim issue with fix
", + output: "
Trailing space trim issue with fix
", + errors: [generateError(["px-10", "py-10"], "p-10")], + }, + { + code: "
Trailing space trim issue with fix (2)
", + output: "
Trailing space trim issue with fix (2)
", + errors: [generateError(["px-10", "py-10"], "p-10")], + }, { code: `
New size-* utilities
`, output: `
New size-* utilities
`, From aff977b86769ad7a6c22970c2d07a4a6eab47eaa Mon Sep 17 00:00:00 2001 From: Alexander Kachkaev Date: Mon, 15 Jan 2024 18:38:04 +0000 Subject: [PATCH 2/2] Fix --- lib/rules/enforces-shorthand.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/enforces-shorthand.js b/lib/rules/enforces-shorthand.js index 1fcc366d..e7703c32 100644 --- a/lib/rules/enforces-shorthand.js +++ b/lib/rules/enforces-shorthand.js @@ -434,7 +434,7 @@ module.exports = { const w = whitespaces[i] ?? ''; const cls = union[i]; validatedClassNamesValue += headSpace ? `${w}${cls}` : isLast ? `${cls}` : `${cls}${w}`; - if (headSpace && tailSpace && isLast) { + if (tailSpace && isLast) { validatedClassNamesValue += whitespaces[whitespaces.length - 1] ?? ''; } }