Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix #127: Don't ignore removeDuplicates option when using officialSor…
…ting

The check for removing duplicates is completely separate from the
sorting, even when {officialSorting: false}. Therefore, it shouldn't
harm to also execute this check when {officialSorting: true}.
  • Loading branch information
mpsijm committed Jun 13, 2022
commit e0bd09a2462a3917164c63e69091ac620b777202
2 changes: 1 addition & 1 deletion docs/rules/classnames-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const customGroups = require('custom-groups').groups;

### `officialSorting` (default: `false`)

Set `officialSorting` to `true` if you want to use the same ordering rules as the official plugin `prettier-plugin-tailwindcss`. Enabling this settings will cause `groupByResponsive`, `groups`, `prependCustom` and `removeDuplicates` options to be ignored.
Set `officialSorting` to `true` if you want to use the same ordering rules as the official plugin `prettier-plugin-tailwindcss`. Enabling this setting will cause `groupByResponsive`, `groups`, and `prependCustom` options to be ignored.

### `prependCustom` (default: `false`)

Expand Down
8 changes: 4 additions & 4 deletions lib/rules/classnames-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ module.exports = {
return;
}

if (removeDuplicates) {
removeDuplicatesFromClassnamesAndWhitespaces(classNames, whitespaces, headSpace, tailSpace);
}

let orderedClassNames;
let validatedClassNamesValue = '';

Expand All @@ -323,10 +327,6 @@ module.exports = {
}
}
} else {
if (removeDuplicates) {
removeDuplicatesFromClassnamesAndWhitespaces(classNames, whitespaces, headSpace, tailSpace);
}

// Sorting
const mergedSorted = [];
const mergedExtras = [];
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/classnames-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,16 @@ ruleTester.run("classnames-order", rule, {
},
],
},
{
code: `<div class="h-4 h-4 w-4">Using official sorting, with duplicates</div>`,
output: `<div class="h-4 w-4">Using official sorting, with duplicates</div>`,
errors: errors,
options: [
{
officialSorting: true,
},
],
},
{
code: `ctl(\`\${some} container animate-spin first:flex \${bool ? "flex-col flex" : ""}\`)`,
output: `ctl(\`\${some} container animate-spin first:flex \${bool ? "flex flex-col" : ""}\`)`,
Expand Down