Skip to content

Commit

Permalink
Change regexes to work with half classes (ex: mt-0.5) (heybourn#129)
Browse files Browse the repository at this point in the history
* Change regex to work with half classes (ex: `mt-0.5`)
* Add test for sorting half classes

Closes: heybourn#128
  • Loading branch information
praveenperera authored Jun 13, 2021
1 parent a0ca452 commit 9cb01ee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5022,25 +5022,25 @@
"separator": "\\.",
"replacement": "."
},
"\\bclass\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\']"
"\\bclass\\s*=\\s*[\\\"\\']([\\._a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\']"
],
"html": "\\bclass\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\']",
"css": "\\B@apply\\s+([_a-zA-Z0-9\\s\\-\\:\\/]+);",
"html": "\\bclass\\s*=\\s*[\\\"\\']([\\._a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\']",
"css": "\\B@apply\\s+([\\._a-zA-Z0-9\\s\\-\\:\\/]+);",
"javascript": [
"(?:\\b(?:class(?:Name)?|tw)\\s*=\\s*(?:(?:{([\\w\\d\\s!?_\\-:/${}()[\\]\"'`,]+)})|([\"'`][\\w\\d\\s_\\-:/]+[\"'`])))",
"(?:[\"'`]([\\w\\d\\s_\\-:/${}()[\\]]+)[\"'`])"
"(?:\\b(?:class(?:Name)?|tw)\\s*=\\s*(?:(?:{([\\w\\d\\s!?_\\-:/${}()[\\]\"'`,]+)})|([\"'`][\\.\\w\\d\\s_\\-:/]+[\"'`])))",
"(?:[\"'`]([\\.\\w\\d\\s_\\-:/${}()[\\]]+)[\"'`])"
],
"javascriptreact": [
"(?:\\b(?:class(?:Name)?|tw)\\s*=\\s*(?:(?:{([\\w\\d\\s!?_\\-:/${}()[\\]\"'`,]+)})|([\"'`][\\w\\d\\s_\\-:/]+[\"'`])))",
"(?:[\"'`]([\\w\\d\\s_\\-:/${}()[\\]]+)[\"'`])"
"(?:[\"'`]([\\.\\w\\d\\s_\\-:/${}()[\\]]+)[\"'`])"
],
"typescript": [
"(?:\\b(?:class(?:Name)?|tw)\\s*=\\s*(?:(?:{([\\w\\d\\s!?_\\-:/${}()[\\]\"'`,]+)})|([\"'`][\\w\\d\\s_\\-:/]+[\"'`])))",
"(?:[\"'`]([\\w\\d\\s_\\-:/${}()[\\]]+)[\"'`])"
"(?:[\"'`]([\\.\\w\\d\\s_\\-:/${}()[\\]]+)[\"'`])"
],
"typescriptreact": [
"(?:\\b(?:class(?:Name)?|tw)\\s*=\\s*(?:(?:{([\\w\\d\\s!?_\\-:/${}()[\\]\"'`,]+)})|([\"'`][\\w\\d\\s_\\-:/]+[\"'`])))",
"(?:[\"'`]([\\w\\d\\s_\\-:/${}()[\\]]+)[\"'`])"
"(?:[\"'`]([\\.\\w\\d\\s_\\-:/${}()[\\]]+)[\"'`])"
]
},
"description": "An object with language IDs as keys and their values determining the regex to search for Tailwind CSS classes.",
Expand Down
15 changes: 15 additions & 0 deletions tests/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ const randomizedClassStringWithCustom = _.shuffle([
]).join(' ');

describe('sortClassString', () => {
it('sorts half classes properly', () => {
const result = sortClassString(
'mt-4 mb-0.5 flex inline-block inline px-0.5 pt-10 random-class justify-items absolute relative another-random-class',
sortOrder,
{
shouldRemoveDuplicates: true,
shouldPrependCustomClasses: false,
customTailwindPrefix: '',
}
);
expect(result).toBe(
'inline-block inline flex absolute relative px-0.5 pt-10 mt-4 mb-0.5 random-class justify-items another-random-class'
);
});

it('should return a sorted class list string', () => {
const result = sortClassString(randomizedClassString, sortOrder, {
shouldRemoveDuplicates: true,
Expand Down

0 comments on commit 9cb01ee

Please sign in to comment.