Skip to content

Commit

Permalink
wip: multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
schoero committed Dec 9, 2023
1 parent b593e92 commit 701be54
Show file tree
Hide file tree
Showing 15 changed files with 389 additions and 358 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<div align="center">
<img alt="eslint-plugin-readable-tailwind" src="https://raw.githubusercontent.com/schoero/eslint-plugin-readable-tailwind/main/assets/eslint-plugin-readable-tailwind-logo.svg">
<img alt="eslint-plugin-readable-tailwind" src="https://raw.githubusercontent.com/schoero/eslint-plugin-readable-tailwind/main/assets/eslint-plugin-readable-tailwind-logo.svg?token=AKCR54TFQSHIUXAOXY46JLTFOQ3CU">
</div>

---

<div align="center">

[![GitHub license](https://img.shields.io/github/license/schoero/eslint-plugin-readable-tailwind?style=flat-square&labelColor=454c5c&color=00AD51)](https://github.com/schoero/eslint-plugin-readable-tailwind/blob/main/LICENSE)
Expand All @@ -19,7 +20,8 @@
<br/>
<br/>

auto-wraps tailwind classes after a certain width using template literals.
ESLint plugin to automatically break up long tailwind class strings into multiple lines for better readability.
Also sorts the classes logically, removes unnecessary whitespaces and groups the classes by their prefix.

<br/>
<br/>
Expand All @@ -40,12 +42,12 @@ npm install eslint-plugin-readable-tailwind --save-dev

## Usage

Add `tailwind-multiline` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
Add `readable-tailwind` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:

```json
{
"plugins": [
"tailwind-multiline"
"readable-tailwind"
]
}
```
Expand All @@ -68,7 +70,7 @@ Then configure the rules you want to use under the rules section.

| Name | Description | 🔧 |
| :------------------------------------------------------------------- | :--------------------------------------------------- | :- |
| [jsx-attribute-expression](docs/rules/jsx-attribute-expression.md) | Enforce consistent jsx attribute expressions. | 🔧 |
| [jsx-attribute-expression](docs/rules/jsx-attribute-expression.md) | Enforce consistent jsx attribute expressions | 🔧 |
| [no-unnecessary-whitespace](docs/rules/no-unnecessary-whitespace.md) | Disallow unnecessary whitespace in tailwind classes. | 🔧 |
| [sort-classes](docs/rules/sort-classes.md) | Enforce a consistent order for tailwind classes. | 🔧 |

Expand Down
95 changes: 48 additions & 47 deletions assets/eslint-plugin-readable-tailwind-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/rules/jsx-attribute-expression.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

<!-- end auto-generated rule header -->

## Options

<!-- begin auto-generated rule options list -->



<!-- end auto-generated rule options list -->
9 changes: 5 additions & 4 deletions docs/rules/no-unnecessary-whitespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

<!-- begin auto-generated rule options list -->

| Name | Type |
| :---------------- | :------- |
| `allowMultiline` | Boolean |
| `classAttributes` | String[] |
| Name | Description | Type | Default |
| :---------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------- | :------- | :-------------------------------- |
| `allowMultiline` | Allow multi-line class declarations. If this option is disabled, template literal strings will be collapsed into a single line string wherever possible. | Boolean | `true` |
| `callees` | List of function names whose arguments should also be considered. | String[] | [`clsx`, `cva`, `ctl`, `twMerge`] |
| `classAttributes` | | String[] | |

<!-- end auto-generated rule options list -->
13 changes: 13 additions & 0 deletions docs/rules/sort-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

<!-- end auto-generated rule header -->

## Options

<!-- begin auto-generated rule options list -->

| Name | Description | Type | Choices | Default |
| :---------------- | :----------------------------------------------------------------------------------------------------------------------------------------------- | :------- | :------------------------ | :-------------------------------- |
| `callees` | List of function names whose arguments should also be considered. | String[] | | [`clsx`, `cva`, `ctl`, `twMerge`] |
| `classAttributes` | | String[] | | |
| `order` | The algorithm to use when sorting classes. | String | `asc`, `desc`, `official` | `official` |
| `tailwindConfig` | The path to the tailwind config file. If not specified, the plugin will try to find it automatically or falls back to the default configuration. | String | | |

<!-- end auto-generated rule options list -->
72 changes: 36 additions & 36 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"scripts": {
"build": "vite build",
"docs": "eslint-doc-generator",
"docs:lint": "npm run update:eslint-docs -- --check",
"eslint": "eslint --ext .ts,.tsx,.js,.jsx,.json,.jsonc,.yml,.md ./",
"eslint:ci": "npm run eslint -- --max-warnings 0",
"eslint:fix": "npm run eslint -- --fix",
"lint": "npm run eslint && npm run markdownlint",
"lint": "npm run eslint && npm run markdownlint && npm run docs:lint",
"lint:ci": "npm run eslint:ci && npm run markdownlint:ci",
"lint:fix": "npm run eslint:fix && npm run markdownlint:fix",
"markdownlint": "markdownlint-cli2 '**/*.md' '#node_modules'",
Expand Down Expand Up @@ -46,7 +47,7 @@
"vite": "^5.0.7",
"vite-plugin-dts": "^3.6.4",
"vite-plugin-no-bundle": "^3.0.0",
"vitest": "^1.0.2"
"vitest": "^1.0.3"
},
"keywords": [
"eslint",
Expand Down
19 changes: 19 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { jsxAttributeExpression } from "eptm:rules:jsx-attribute-expression.js";
import { tailwindNoUnnecessaryWhitespace } from "eptm:rules:tailwind-no-unnecessary-whitespace.js";
import { tailwindSortClasses } from "eptm:rules:tailwind-sort-classes.js";
Expand All @@ -6,6 +7,24 @@ import type { ESLint } from "eslint";


export default {
configs: {
"recommended/error": {
plugins: ["readable-tailwind"],
rules: {
[jsxAttributeExpression.name]: "error",
[tailwindNoUnnecessaryWhitespace.name]: "error",
[tailwindSortClasses.name]: "error"
}
},
"recommended/warn": {
plugins: ["readable-tailwind"],
rules: {
[jsxAttributeExpression.name]: "warn",
[tailwindNoUnnecessaryWhitespace.name]: "warn",
[tailwindSortClasses.name]: "warn"
}
}
},
rules: {
[jsxAttributeExpression.name]: jsxAttributeExpression.rule,
[tailwindNoUnnecessaryWhitespace.name]: tailwindNoUnnecessaryWhitespace.rule,
Expand Down
17 changes: 13 additions & 4 deletions src/rules/jsx-attribute-expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,22 @@ export const jsxAttributeExpression: ESLintRule<Options> = {
meta: {
docs: {
category: "Stylistic Issues",
description: "Enforce consistent jsx attribute expressions",
description: "Enforce consistent jsx attribute expressions.",
recommended: true
},
fixable: "code",
schema: [
{
enum: ["always", "as-needed"]
additionalItems: false,
items: [
{
default: getOptions().expression,
description: "Collapse jsx class attribute expressions to a literal string if possible.",
enum: ["always", "as-needed"],
type: "string"
}
],
type: "array"
}
],
type: "layout"
Expand All @@ -96,7 +105,7 @@ function getAllowedQuotes(ctx: Rule.RuleContext, preferredQuotes: QuoteParts): Q
return { leadingQuote: '"', trailingQuote: '"' };
}

function getOptions(ctx: Rule.RuleContext): { expression: Options[0]; } {
const expression = ctx.options[0] ?? "as-needed";
function getOptions(ctx?: Rule.RuleContext): { expression: Options[0]; } {
const expression = ctx?.options[0] ?? "as-needed";
return { expression };
}
Loading

0 comments on commit 701be54

Please sign in to comment.