Skip to content

Commit

Permalink
fix: handle bracketed classes like [--trigger-over]
Browse files Browse the repository at this point in the history
  • Loading branch information
abdul-alhasany committed Sep 5, 2023
1 parent 6d41f71 commit 24f3a83
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@kalimahapps/eslint-plugin-tailwind",
"description": "Provide eslint rules for tailwindcss",
"author": "khr2003",
"version": "1.0.8",
"version": "1.0.9",
"repository": {
"type": "git",
"url": "https://github.com/kalimahapps/eslint-plugin-tailwind.git"
Expand Down
12 changes: 12 additions & 0 deletions rules/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@ class Tailwind {

const classListClone = [...this.classesList];

/**
* Get bracketed classes.
* Library like https://preline.co/ uses this syntax `[--trigger:hover]`
* which causes the regex to break.
*/
const bracketedClasses = classListClone.filter((className) => {
return className.startsWith('[') && className.endsWith(']');
});

// remove bracketed classes from the list
this.removeFromArray(this.classesList, bracketedClasses);

// Loop through the classes and get classnames without any prefixes
this.classesList.forEach((className) => {
const canProceed = this.shouldSortClass(className);
Expand Down
14 changes: 11 additions & 3 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ ruleTester.run('multiline', multlineRule, {
text-yellow-500"
></div>
`,
errors: [{message: 'Classes should be in multiple lines'}],
errors: [{ message: 'Classes should be in multiple lines' }],
},
{
code: `<template>
Expand All @@ -163,8 +163,8 @@ ruleTester.run('multiline', multlineRule, {
"
></div>
`,
options: [{quotesOnNewLine: true}],
errors: [{message: 'Classes should be in multiple lines'}],
options: [{ quotesOnNewLine: true }],
errors: [{ message: 'Classes should be in multiple lines' }],
},
],
});
Expand All @@ -177,6 +177,9 @@ ruleTester.run('sort', sortRule, {
{
code: '<template><div class="grid grid-cols-2"></div></template>',
},
{
code: '<template><div class="grid grid-cols-2 [--strategy:static] [--trigger:hover]"></div></template>',
},
],
invalid: [
{
Expand All @@ -189,6 +192,11 @@ ruleTester.run('sort', sortRule, {
output: '<template><div class="grid grid-cols-2"></div></template>',
errors: [{ message: 'Classes are not sorted' }],
},
{
code: '<template><div class=" [--strategy:static] grid-cols-2 [--trigger:hover] grid "></div></template>',
output: '<template><div class="grid grid-cols-2 [--strategy:static] [--trigger:hover]"></div></template>',
errors: [{ message: 'Classes are not sorted' }],
},
{
code: '<template><div class="grid-cols-2 md:grid-cols-3 sm:grid-cols-1"></div></template>',
output: '<template><div class="grid-cols-2 sm:grid-cols-1 md:grid-cols-3"></div></template>',
Expand Down

0 comments on commit 24f3a83

Please sign in to comment.