Skip to content

Commit

Permalink
fix: do not handle non-ASCII whitespace as separator (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
uhyo committed May 30, 2023
1 parent ceddc54 commit 594c75d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/util/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function extractClassnamesFromValue(classStr) {
if (typeof classStr !== 'string') {
return { classNames: [], whitespaces: [], headSpace: false, tailSpace: false };
}
const separatorRegEx = /(\s+)/;
const separatorRegEx = /([\t\n\f\r ]+)/;
let parts = classStr.split(separatorRegEx);
if (parts[0] === '') {
parts.shift();
Expand Down
2 changes: 1 addition & 1 deletion lib/util/prettier/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function sortClasses(classStr, { env, ignoreFirst = false, ignoreLast = false })
}

let result = '';
let parts = classStr.split(/(\s+)/);
let parts = classStr.split(/([\t\n\f\r ]+)/);
let classes = parts.filter((_, i) => i % 2 === 0);
let whitespace = parts.filter((_, i) => i % 2 !== 0);

Expand Down
7 changes: 5 additions & 2 deletions tests/lib/rules/classnames-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ ruleTester.run("classnames-order", rule, {
`,
options: skipClassAttributeOptions,
},
{
code: `<div class="py-1\u3000px-2 block">Do not treat full width space as class separator</div>`,
},
],
invalid: [
{
Expand Down Expand Up @@ -913,7 +916,7 @@ ruleTester.run("classnames-order", rule, {
code: `
<template>
<div v-bind="data" :class="[
'py-1.5 font-semibold transition',
'py-1.5 font-semibold transition',
{
'text-white': variant === 'white',
'text-blue-500 hover:text-blue-400 border-blue-500': variant === 'primary',
Expand All @@ -924,7 +927,7 @@ ruleTester.run("classnames-order", rule, {
output: `
<template>
<div v-bind="data" :class="[
'py-1.5 font-semibold transition',
'py-1.5 font-semibold transition',
{
'text-white': variant === 'white',
'border-blue-500 text-blue-500 hover:text-blue-400': variant === 'primary',
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/no-custom-classname.js
Original file line number Diff line number Diff line change
Expand Up @@ -1398,5 +1398,13 @@ ruleTester.run("no-custom-classname", rule, {
],
errors: generateErrors("yolo custom"),
},
{
code: `<div className="px-1\u3000py-2">Full-width space between classes</div>`,
errors: generateErrors("px-1\u3000py-2"),
},
{
code: `<div className="\u3000px-1 py-2\u3000">Full-width space before and after classes</div>`,
errors: generateErrors("\u3000px-1 py-2\u3000"),
},
],
});

0 comments on commit 594c75d

Please sign in to comment.