{"id":49903136,"url":"https://github.com/agolosnichenko/eslint-plugin-tailwind-grouping","last_synced_at":"2026-05-16T09:32:26.811Z","repository":{"id":324171977,"uuid":"1096234680","full_name":"agolosnichenko/eslint-plugin-tailwind-grouping","owner":"agolosnichenko","description":"ESLint plugin to group and organize Tailwind CSS classes","archived":false,"fork":false,"pushed_at":"2025-11-14T17:49:17.000Z","size":51,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-30T14:09:37.317Z","etag":null,"topics":["code-style","eslint","eslint-plugin","formatting","tailwind","tailwindcss"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/eslint-plugin-tailwind-grouping","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/agolosnichenko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"buy_me_a_coffee":"agolosnichenko"}},"created_at":"2025-11-14T06:00:30.000Z","updated_at":"2025-11-17T10:25:15.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/agolosnichenko/eslint-plugin-tailwind-grouping","commit_stats":null,"previous_names":["agolosnichenko/eslint-plugin-tailwind-grouping"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/agolosnichenko/eslint-plugin-tailwind-grouping","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agolosnichenko%2Feslint-plugin-tailwind-grouping","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agolosnichenko%2Feslint-plugin-tailwind-grouping/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agolosnichenko%2Feslint-plugin-tailwind-grouping/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agolosnichenko%2Feslint-plugin-tailwind-grouping/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agolosnichenko","download_url":"https://codeload.github.com/agolosnichenko/eslint-plugin-tailwind-grouping/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agolosnichenko%2Feslint-plugin-tailwind-grouping/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33096867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-style","eslint","eslint-plugin","formatting","tailwind","tailwindcss"],"created_at":"2026-05-16T09:32:24.911Z","updated_at":"2026-05-16T09:32:26.803Z","avatar_url":"https://github.com/agolosnichenko.png","language":"TypeScript","funding_links":["https://buymeacoffee.com/agolosnichenko"],"categories":[],"sub_categories":[],"readme":"# ESLint Plugin: Tailwind Grouping\n\nAn ESLint plugin that automatically groups and organizes Tailwind CSS classes into semantic categories, improving\nreadability and maintainability of your React/JSX code.\n\n## 📋 Table of Contents\n\n- [Problem](#problem)\n- [Solution](#solution)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Configuration](#configuration)\n- [Examples](#examples)\n- [Development](#development)\n\n## Problem\n\nLarge Tailwind className strings are difficult to read and maintain:\n\n```jsx\n\u003cselect\n    className=\"border-input placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 dark:hover:bg-input/50 h-9 w-full min-w-0 appearance-none rounded-md border bg-transparent px-3 py-2 pr-9 text-sm shadow-xs transition-[color,box-shadow] outline-none disabled:pointer-events-none disabled:cursor-not-allowed\"/\u003e\n```\n\n## Solution\n\nThe plugin automatically transforms long className strings into organized, commented groups using `clsx`:\n\n```jsx\n\u003cselect\n    className={clsx(\n        // Size\n        \"h-9 w-full min-w-0\",\n        // Spacing\n        \"px-3 py-2 pr-9\",\n        // Border\n        \"border border-input outline-none rounded-md\",\n        // Background\n        \"bg-transparent dark:bg-input/30 dark:hover:bg-input/50 selection:bg-primary\",\n        // Text\n        \"text-sm selection:text-primary-foreground placeholder:text-muted-foreground\",\n        // Effects\n        \"appearance-none shadow-xs transition-[color,box-shadow]\",\n        // Others\n        \"disabled:pointer-events-none disabled:cursor-not-allowed\"\n    )}\n/\u003e\n```\n\n## Installation\n\n```bash\nnpm install --save-dev eslint-plugin-tailwind-grouping\n# or\nyarn add -D eslint-plugin-tailwind-grouping\n# or\npnpm add -D eslint-plugin-tailwind-grouping\n```\n\n## Usage\n\n### ESLint Configuration (Flat Config - ESLint 9+)\n\n```javascript\n// eslint.config.js\nimport tailwindGrouping from 'eslint-plugin-tailwind-grouping';\n\nexport default [\n    {\n        plugins: {\n            'tailwind-grouping': tailwindGrouping\n        },\n        rules: {\n            'tailwind-grouping/group-classes': ['warn', {\n                threshold: 5,\n                include: ['**/*.tsx', '**/*.jsx'],\n                exclude: ['**/*.test.tsx']\n            }]\n        }\n    }\n];\n```\n\n### ESLint Configuration (Legacy)\n\n```json\n{\n  \"plugins\": [\n    \"tailwind-grouping\"\n  ],\n  \"rules\": {\n    \"tailwind-grouping/group-classes\": [\n      \"warn\",\n      {\n        \"threshold\": 5\n      }\n    ]\n  }\n}\n```\n\n### Using with Prettier\n\nThis plugin is compatible with Prettier. Make sure to run ESLint with `--fix` flag:\n\n```bash\neslint --fix .\n```\n\n## Configuration\n\n### Options\n\n```typescript\n{\n    // Minimum number of classes required to trigger transformation\n    // Default: 0\n    threshold?: number;\n\n    // Glob patterns for files to include\n    // Default: [] (all files)\n    include?: string[];\n\n    // Glob patterns for files to exclude\n    // Default: [] (no exclusions)\n    exclude?: string[];\n\n    // Custom mapping of groups to class patterns\n    // Default: DEFAULT_GROUP_MAPPING\n    mapping?: {\n        [groupName: string]: string[];\n    };\n\n    // Custom order of groups\n    // Default: ['Size', 'Layout', 'Spacing', 'Border', 'Background', 'Text', 'Effects', 'Others']\n    groupOrder?: string[];\n\n    // Name of the utility function to use\n    // Default: 'clsx'\n    utilityFunction?: string;\n\n    // Whether to include group name comments in the output\n    // Default: true\n    showGroupNames?: boolean;\n\n    // Comment template for group names\n    // Can be a preset name or a custom template string with variables\n    // Default: \"// {groupName}\"\n    // Presets: 'line', 'block', 'jsdoc', 'bracket', 'numbered', 'verbose'\n    // Variables: {groupName}, {index}, {count}\n    commentTemplate?: string;\n\n    // Sorting order for classes within each group\n    // Default: \"no-sort\"\n    // Options: 'no-sort' | 'asc' | 'desc' | 'official'\n    order?: 'no-sort' | 'asc' | 'desc' | 'official';\n}\n```\n\n### Example: Custom Mapping\n\n```javascript\n{\n    \"tailwind-grouping/group-classes\":\n    [\"warn\", {\n        \"threshold\": 3,\n        \"mapping\": {\n            \"Size\": [\"w-*\", \"h-*\", \"min-w-*\", \"max-w-*\"],\n            \"Colors\": [\"bg-*\", \"text-*\", \"border-*\"],\n            \"Spacing\": [\"p-*\", \"m-*\", \"gap-*\"],\n            \"Others\": []\n        },\n        \"groupOrder\": [\"Size\", \"Colors\", \"Spacing\", \"Others\"]\n    }]\n}\n```\n\n### Example: Custom Utility Function\n\n```javascript\n{\n    \"tailwind-grouping/group-classes\":\n    [\"warn\", {\n        \"utilityFunction\": \"cn\" // Use shadcn/ui's cn function\n    }]\n}\n```\n\n### Example: Without Group Name Comments\n\nIf you prefer cleaner output without the group name comments, you can disable them:\n\n```javascript\n{\n    \"tailwind-grouping/group-classes\":\n    [\"warn\", {\n        \"showGroupNames\": false\n    }]\n}\n```\n\n**Output with `showGroupNames: false`:**\n\n```jsx\n\u003cdiv\n    className={clsx(\n        \"h-9 w-full\",\n        \"px-3 py-2\",\n        \"border rounded-md\",\n        \"bg-white\"\n    )}\n\u003e\n    Content\n\u003c/div\u003e\n```\n\n**Output with `showGroupNames: true` (default):**\n\n```jsx\n\u003cdiv\n    className={clsx(\n        // Size\n        \"h-9 w-full\",\n        // Spacing\n        \"px-3 py-2\",\n        // Border\n        \"border rounded-md\",\n        // Background\n        \"bg-white\"\n    )}\n\u003e\n    Content\n\u003c/div\u003e\n```\n\n### Example: Custom Comment Templates\n\nCustomize how group comments appear using templates with variables or presets:\n\n#### Using Preset Templates\n\n```javascript\n{\n    \"tailwind-grouping/group-classes\": [\"warn\", {\n        \"commentTemplate\": \"block\"  // Use block comment style\n    }]\n}\n```\n\n**Available Presets:**\n- `line`: `// {groupName}` (default)\n- `block`: `/* {groupName} */`\n- `jsdoc`: `/** {groupName} **/`\n- `bracket`: `// [{groupName}]`\n- `numbered`: `// {index}. {groupName}`\n- `verbose`: `// {groupName} ({count} classes)`\n\n#### Using Custom Templates\n\nCreate your own templates with these variables:\n- `{groupName}`: Name of the group (e.g., \"Size\", \"Spacing\")\n- `{index}`: 1-based position of the group\n- `{count}`: Number of classes in the group\n\n```javascript\n{\n    \"tailwind-grouping/group-classes\": [\"warn\", {\n        \"commentTemplate\": \"// {index}. {groupName} ({count})\"\n    }]\n}\n```\n\n**Example outputs:**\n\n```jsx\n// With commentTemplate: \"/* {groupName} */\"\n\u003cdiv\n    className={clsx(\n        /* Size */\n        \"h-9 w-full\",\n        /* Spacing */\n        \"px-3 py-2\"\n    )}\n/\u003e\n\n// With commentTemplate: \"// {index}. {groupName}\"\n\u003cdiv\n    className={clsx(\n        // 1. Size\n        \"h-9 w-full\",\n        // 2. Spacing\n        \"px-3 py-2\"\n    )}\n/\u003e\n\n// With commentTemplate: \"// {groupName} ({count})\"\n\u003cdiv\n    className={clsx(\n        // Size (2)\n        \"h-9 w-full\",\n        // Spacing (2)\n        \"px-3 py-2\"\n    )}\n/\u003e\n\n// With commentTemplate: \"// [{index}] {groupName} - {count} classes\"\n\u003cdiv\n    className={clsx(\n        // [1] Size - 2 classes\n        \"h-9 w-full\",\n        // [2] Spacing - 2 classes\n        \"px-3 py-2\"\n    )}\n/\u003e\n```\n\n### Example: Class Sorting\n\nYou can control how classes are sorted within each group:\n\n```javascript\n{\n    \"tailwind-grouping/group-classes\": [\"warn\", {\n        \"order\": \"asc\"  // Sort alphabetically A-Z\n    }]\n}\n```\n\n**Options:**\n- `\"no-sort\"` (default): Preserve original order\n- `\"asc\"`: Sort alphabetically A-Z\n- `\"desc\"`: Sort alphabetically Z-A\n- `\"official\"`: Use Tailwind's official class ordering (same as prettier-plugin-tailwindcss)\n\n**Example output with `order: \"asc\"`:**\n\n```jsx\n\u003cdiv\n    className={clsx(\n        // Size\n        \"h-9 min-w-0 w-full\",  // Sorted alphabetically\n        // Spacing\n        \"px-3 py-2\"\n    )}\n/\u003e\n```\n\n**Note:** The plugin automatically removes duplicate classes, keeping only the first occurrence.\n\n## Examples\n\n### Before\n\n```jsx\n\u003cdiv\n    className=\"flex items-center justify-between p-4 bg-white border rounded-lg shadow-md hover:shadow-lg transition-shadow\"\u003e\n    Content\n\u003c/div\u003e\n```\n\n### After (with threshold: 3)\n\n```jsx\n\u003cdiv\n    className={clsx(\n        // Layout\n        \"flex items-center justify-between\",\n        // Spacing\n        \"p-4\",\n        // Border\n        \"border rounded-lg\",\n        // Background\n        \"bg-white\",\n        // Effects\n        \"shadow-md hover:shadow-lg transition-shadow\"\n    )}\n\u003e\n    Content\n\u003c/div\u003e\n```\n\n### Handling Modifiers\n\nThe plugin preserves all Tailwind modifiers (responsive, state, dark mode, etc.):\n\n```jsx\n// Input\nclassName = \"md:flex lg:grid hover:bg-blue-500 dark:bg-gray-900\"\n\n// Output\nclassName = {\n    clsx(\n    // Layout\n    \"md:flex lg:grid\",\n    // Background\n    \"hover:bg-blue-500 dark:bg-gray-900\"\n)\n}\n```\n\n### Handling Arbitrary Values\n\nArbitrary values are properly grouped:\n\n```jsx\n// Input\nclassName = \"w-[500px] h-[calc(100vh-80px)] bg-[#ff0000]\"\n\n// Output\nclassName = {\n    clsx(\n    // Size\n    \"w-[500px] h-[calc(100vh-80px)]\",\n    // Background\n    \"bg-[#ff0000]\"\n)\n}\n```\n\n## Development\n\n### Setup\n\n```bash\n# Install dependencies\nnpm install\n\n# Build the plugin\nnpm run build\n\n# Run tests\nnpm test\n\n# Run tests in watch mode\nnpm run test:watch\n\n# Lint the code\nnpm run lint\n```\n\n### Running Tests\n\n```bash\nnpm test\n```\n\n### Testing Locally\n\nTo test the plugin in a project before publishing:\n\n```bash\n# In the plugin directory\nnpm link\n\n# In your project directory\nnpm link eslint-plugin-tailwind-grouping\n```\n\n### Design Principles\n\n- **Immutability**: All domain objects are immutable\n- **Single Responsibility**: Each class has one clear purpose\n- **Dependency Injection**: Services receive dependencies via constructor\n- **Testability**: Pure business logic separated from infrastructure\n- **Type Safety**: Full TypeScript coverage with strict mode\n\n## Contributing\n\nContributions are welcome! Please ensure:\n\n1. All tests pass (`npm test`)\n2. Code follows the existing architecture\n3. New features include tests\n4. TypeScript types are properly defined\n\n## License\n\nMIT\n\n## Links\n\n- [GitHub Repository](https://github.com/agolosnichenko/eslint-plugin-tailwind-grouping)\n- [Issue Tracker](https://github.com/agolosnichenko/eslint-plugin-tailwind-grouping/issues)\n- [Tailwind CSS Documentation](https://tailwindcss.com)\n- [ESLint Documentation](https://eslint.org)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagolosnichenko%2Feslint-plugin-tailwind-grouping","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagolosnichenko%2Feslint-plugin-tailwind-grouping","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagolosnichenko%2Feslint-plugin-tailwind-grouping/lists"}