Skip to content

Commit

Permalink
fix: edge cases with whitespace in enforces-shorthand (#308)
Browse files Browse the repository at this point in the history
* Add test cases (one is broken)
* Fix
  • Loading branch information
kachkaev committed Jan 17, 2024
1 parent 01bd10c commit 7687ecf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/enforces-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] ?? '';
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/rules/enforces-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,26 @@ ruleTester.run("shorthands", rule, {
`,
errors: [generateError(["overflow-hidden", "text-ellipsis", "whitespace-nowrap"], "truncate")],
},
{
code: "<div className={ctl(`${live && 'bg-white'} w-full px-10 py-10`)}>Leading space trim issue with fix</div>",
output: "<div className={ctl(`${live && 'bg-white'} w-full p-10`)}>Leading space trim issue with fix</div>",
errors: [generateError(["px-10", "py-10"], "p-10")],
},
{
code: "<div className={ctl(`${live && 'bg-white'} w-full px-10 py-10 `)}>Leading space trim issue with fix (2)</div>",
output: "<div className={ctl(`${live && 'bg-white'} w-full p-10 `)}>Leading space trim issue with fix (2)</div>",
errors: [generateError(["px-10", "py-10"], "p-10")],
},
{
code: "<div className={ctl(`w-full px-10 py-10 ${live && 'bg-white'}`)}>Trailing space trim issue with fix</div>",
output: "<div className={ctl(`w-full p-10 ${live && 'bg-white'}`)}>Trailing space trim issue with fix</div>",
errors: [generateError(["px-10", "py-10"], "p-10")],
},
{
code: "<div className={ctl(` w-full px-10 py-10 ${live && 'bg-white'}`)}>Trailing space trim issue with fix (2)</div>",
output: "<div className={ctl(` w-full p-10 ${live && 'bg-white'}`)}>Trailing space trim issue with fix (2)</div>",
errors: [generateError(["px-10", "py-10"], "p-10")],
},
{
code: `<div class="h-10 w-10">New size-* utilities</div>`,
output: `<div class="size-10">New size-* utilities</div>`,
Expand Down

0 comments on commit 7687ecf

Please sign in to comment.