Skip to content

Commit 2b39c7d

Browse files
feat(rule): classnames-order (#417)
1 parent f8339d1 commit 2b39c7d

31 files changed

+2215
-434
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
name: Bug report
33
about: Create a report to help us improve
44
title: "[BUG] "
5-
labels: 'bug'
6-
assignees: ''
7-
5+
labels: "bug"
6+
assignees: ""
87
---
98

109
**Describe the bug**
1110
A clear and concise description of what the bug is.
1211

1312
**To Reproduce**
1413
Steps to reproduce the behavior:
15-
1. Go to '...'
16-
2. Click on '....'
17-
3. Scroll down to '....'
14+
15+
1. Go to '…'
16+
2. Click on '…'
17+
3. Scroll down to '…'
1818
4. See error
1919

2020
**Expected behavior**
@@ -24,10 +24,11 @@ A clear and concise description of what you expected to happen.
2424
If applicable, add screenshots to help explain your problem.
2525

2626
**Environment (please complete the following information):**
27-
- OS: [e.g. macOS, windows 10]
28-
- Softwares + version used:
29-
- [e.g. VSCode 1.54.3]
30-
- [... Terminal 2.9.5, npm 6.14.5, node v14.5.0]
27+
28+
- OS: [e.g. macOS, windows 10]
29+
- Softwares + version used:
30+
- [e.g. VSCode 1.54.3]
31+
- [… Terminal 2.9.5, npm 6.14.5, node v14.5.0]
3132

3233
**Additional context**
3334
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
name: Feature request
33
about: Suggest an idea for this project
44
title: "[Feature request] "
5-
labels: 'enhancement'
6-
assignees: ''
7-
5+
labels: "enhancement"
6+
assignees: ""
87
---
98

109
**Is your feature request related to a problem? Please describe.**
11-
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
10+
A clear and concise description of what the problem is. Ex. I'm always frustrated when []
1211

1312
**Describe the solution you'd like**
1413
A clear and concise description of what you want to happen.

.github/pull_request_template.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Please also list any relevant details for your test configuration
2727
**Test Configuration**:
2828

2929
- OS + version: e.g. macOS Mojave
30-
- NPM version: ...
31-
- Node version: ...
30+
- NPM version:
31+
- Node version:
3232

3333
## Checklist:
3434

CONTRIBUTING.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,70 @@ email, or any other method with the owners of this repository before making a ch
77

88
Please note we have a [code of conduct](CODE_OF_CONDUCT.md), please follow it in all your interactions with the project.
99

10-
## Development
10+
## Getting started with development
1111

12-
Latest version of the plugin uses `pnpm` instead of `npm` as package manager.
12+
I worked on this repo using `pnpm` but it should work with other package manager.
13+
14+
### Install
15+
16+
`pnpm i`
17+
18+
### Build
19+
20+
`pnpm build`
21+
22+
### Test
23+
24+
`pnpm test`
25+
26+
or
27+
28+
`pnpm test:jest`
29+
30+
#### `jest` or `vitest`
31+
32+
Tests were setup to work with `jest` and `vitest` both comes with pros and cons…
33+
34+
I would recommend Vitest but I also added Jest in case you want it.
35+
36+
| Jest | Vitest |
37+
| :----------------------- | :--------------------------------------------- |
38+
| Based on `commonjs` | Based on `ESM` |
39+
| ✅ Mocking | ✅ Mocking |
40+
| ✅ Snapshots | ✅ Snapshots |
41+
| ✅ Parallel testing | ✅ Parallel testing |
42+
| ✅ Fast | ✅ Often faster |
43+
| - | ✅ Support benches |
44+
| ❌ Require `ts-jest` lib | ❌ Requires `setupFile` and `vitest.config.ts` |
45+
46+
NB: In order to use, the [`RuleTester`](https://typescript-eslint.io/packages/rule-tester) from `@typescript-eslint/rule-tester`, we must:
47+
48+
- Have a `tsconfig.json` with:
49+
```
50+
{
51+
"compilerOptions": {
52+
"module": "nodenext",
53+
"moduleResolution": "nodenext"
54+
}
55+
}
56+
```
57+
More info can be found on [`v6`: Cannot find module `@typescript-eslint/*` or its corresponding type declarations](https://github.com/typescript-eslint/typescript-eslint/issues/7284).
58+
> You can use `bundler`, `node16`, or `nodenext` for `moduleResolution`.
59+
- Use `eslint` with `v8`, [`typescript-eslint` does not support `v9` yet](https://github.com/typescript-eslint/typescript-eslint/issues/8211)
60+
61+
### Docs
62+
63+
`pnpm docs:init` will create new files for each rule if necessary.
64+
65+
`pnpm docs:update` will update existing files and the rules list.
66+
67+
You can see an example of generated documentation in the next section.
68+
69+
## Additional resources
70+
71+
See [`eslint-plugin-example-typed-linting`](https://github.com/typescript-eslint/examples/tree/main/packages/eslint-plugin-example-typed-linting) for an example plugin that supports typed linting.
72+
73+
Another example of eslint-plugin using `typescript-eslint` is [`eslint-plugin-vitest`](https://github.com/vitest-dev/eslint-plugin-vitest)
1374

1475
## Pull Request Process
1576

README.md

Lines changed: 44 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,47 @@
22

33
![eslint-plugin-tailwindcss logo](.github/logo.png)
44

5+
## Rules
6+
7+
<!-- begin auto-generated rules list -->
8+
9+
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
10+
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
11+
12+
| Name             | Description | 🔧 | 💡 |
13+
| :------------------------------------------------- | :---------------------------------------------------------------------------------- | :- | :- |
14+
| [classnames-order](docs/rules/classnames-order.md) | Enforces a consistent order for the Tailwind CSS classnames, based on the compiler. | 🔧 | 💡 |
15+
16+
<!-- end auto-generated rules list -->
17+
18+
## Settings
19+
20+
You should specify settings that will be shared across all the plugin rules. ([More about eslint shared settings](https://eslint.org/docs/latest/use/configure/configuration-files#configuring-shared-settings))
21+
22+
```js
23+
// eslint.config.mjs
24+
{
25+
settings: {
26+
tailwindcss: {
27+
// Attributes/props that could contain Tailwind CSS classes...
28+
// Optional, default values: ["class", "className", "ngClass", "@apply"]
29+
attributes: ["class"],
30+
// The absolute path pointing to you main Tailwind CSS v4 config file.
31+
// It must be a `.css` file (v4), not a `.js` file (v3)
32+
// REQUIRED, default value will not help
33+
cssConfigPath: dirname(fileURLToPath(import.meta.url)) + "/styles/tailwind.css",
34+
// Functions/tagFunctions that will be parsed by the plugin.
35+
// Optional, default values: ["classnames", "clsx", "ctl", "cva", "tv", "tw"]
36+
functions: ["twClasses"]
37+
},
38+
}
39+
}
40+
```
41+
42+
The default settings are exported via the [`DEFAULT_SETTINGS`](src/utils/parse-plugin-settings.ts).
43+
44+
## Made fro Tailwind CSS v4
45+
546
Version 4 of the `eslint-plugin-tailwindcss` is:
647
748
- re-written from scratch
@@ -29,89 +70,16 @@ This version is far from finished, yet it is available and open for contribution
2970
3071
- restore the automated tests running on the merge requests of the repo
3172
- implement and test the usage of `tailwind-api-utils`
73+
- read the settings from eslint (shared settings & rules settings)
3274
3375
### Next steps
3476
35-
- read the settings from eslint (shared settings & rules settings)
3677
- create the config utility
3778
- implement the `classnames-order` rule and its tests
3879
39-
## Getting started
40-
41-
I worked on this repo using `pnpm` but it should work with other package manager.
42-
43-
### Install
44-
45-
`pnpm i`
46-
47-
### Build
48-
49-
`pnpm build`
50-
51-
### Test
52-
53-
`pnpm test`
54-
55-
or
56-
57-
`pnpm test:jest`
58-
59-
#### `jest` or `vitest`
60-
61-
Tests were setup to work with `jest` and `vitest` both comes with pros and cons...
62-
63-
I would recommend Vitest but I also added Jest in case you want it.
64-
65-
| Jest | Vitest |
66-
| :----------------------- | :--------------------------------------------- |
67-
| Based on `commonjs` | Based on `ESM` |
68-
| ✅ Mocking | ✅ Mocking |
69-
| ✅ Snapshots | ✅ Snapshots |
70-
| ✅ Parallel testing | ✅ Parallel testing |
71-
| ✅ Fast | ✅ Often faster |
72-
| - | ✅ Support benches |
73-
| ❌ Require `ts-jest` lib | ❌ Requires `setupFile` and `vitest.config.ts` |
74-
75-
NB: In order to use, the [`RuleTester`](https://typescript-eslint.io/packages/rule-tester) from `@typescript-eslint/rule-tester`, we must:
76-
77-
- Have a `tsconfig.json` with:
78-
```
79-
{
80-
"compilerOptions": {
81-
"module": "nodenext",
82-
"moduleResolution": "nodenext"
83-
}
84-
}
85-
```
86-
More info can be found on [`v6`: Cannot find module `@typescript-eslint/*` or its corresponding type declarations](https://github.com/typescript-eslint/typescript-eslint/issues/7284).
87-
> You can use `bundler`, `node16`, or `nodenext` for `moduleResolution`.
88-
- Use `eslint` with `v8`, [`typescript-eslint` does not support `v9` yet](https://github.com/typescript-eslint/typescript-eslint/issues/8211)
89-
90-
### Docs
91-
92-
`pnpm docs:init` will create new files for each rule if necessary.
93-
94-
`pnpm docs:update` will update existing files and the rules list.
95-
96-
You can see an example of generated documentation in the next section.
97-
98-
### Rules
99-
100-
<!-- begin auto-generated rules list -->
101-
102-
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
103-
104-
| Name | Description | 💡 |
105-
| :------------------------------- | :--------------------- | :- |
106-
| [my-rule](docs/rules/my-rule.md) | An example ESLint rule | 💡 |
107-
108-
<!-- end auto-generated rules list -->
109-
110-
## Additional resources
111-
112-
See [`eslint-plugin-example-typed-linting`](https://github.com/typescript-eslint/examples/tree/main/packages/eslint-plugin-example-typed-linting) for an example plugin that supports typed linting.
80+
## Contributing
11381
114-
Another example of eslint-plugin using `typescript-eslint` is [`eslint-plugin-vitest`](https://github.com/vitest-dev/eslint-plugin-vitest)...
82+
The project is open to all developers, you can [contribute the `eslint-plugin-tailwindcss`](CONTRIBUTING.md).
11583
11684
## 🤝 Support `eslint-plugin-tailwindcss`
11785

docs/rules/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Running `pnpm docs:update` will update the existing docs.
88

99
## Generated sections
1010

11-
The generated sections are surrounded by HTML comments mentioning "auto-generated".
11+
The generated sections are surrounded by HTML comments mentioning "auto-generated".

docs/rules/classnames-order.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Enforces a consistent order for the Tailwind CSS classnames, based on the compiler
2+
3+
🔧💡 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
4+
5+
<!-- end auto-generated rule header -->
6+
7+
## Options
8+
9+
<!-- begin auto-generated rule options list -->
10+
11+
12+
13+
<!-- end auto-generated rule options list -->

docs/rules/my-rule.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"scripts": {
3636
"lint": "eslint .",
3737
"lint:fix": "eslint . --fix",
38-
"build": "tsc --build",
38+
"build": "tsc --build && rsync src/utils/tailwindcss-api/worker/*.mjs lib/utils/tailwindcss-api/worker",
3939
"build:diagnostics": "tsc --build --diagnostics",
4040
"watch": "tsc --watch",
4141
"tsup": "tsup ./src/index.ts --outDir lib/",
@@ -52,7 +52,9 @@
5252
"tailwind-api-utils": "^1.0.3"
5353
},
5454
"devDependencies": {
55+
"@angular-eslint/template-parser": "^20.1.1",
5556
"@eslint/js": "^9.16.0",
57+
"@tailwindcss/typography": "^0.5.16",
5658
"@types/eslint": "^8.56.10",
5759
"@types/jest": "^29.5.12",
5860
"@typescript-eslint/parser": "^8.37.0",
@@ -69,7 +71,8 @@
6971
"tsup": "^8.1.0",
7072
"typescript": "^5.4.5",
7173
"typescript-eslint": "^8.18.0",
72-
"vitest": "^1.6.0"
74+
"vitest": "^1.6.0",
75+
"vue-eslint-parser": "^10.2.0"
7376
},
7477
"engines": {
7578
"node": ">=20.10.0"

0 commit comments

Comments
 (0)