Skip to content

Commit a035fa7

Browse files
authored
feat!: Remove Tailwind syntax in favor of external tailwind-csstree (#166)
* feat!: Remove Tailwind syntax in favor of external tailwind-csstree package * Update jsr.json * Fix tests * Fix types test
1 parent 211bf21 commit a035fa7

File tree

8 files changed

+21
-84
lines changed

8 files changed

+21
-84
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,19 @@ export default defineConfig([
218218

219219
#### Configuring Tailwind Syntax
220220

221-
[Tailwind](https://tailwindcss.com) specifies some extensions to CSS that will otherwise be flagged as invalid by the rules in this plugin. You can configure most of the custom syntax for Tailwind using the builtin `tailwindSyntax` object, like this:
221+
[Tailwind](https://tailwindcss.com) specifies some extensions to CSS that will otherwise be flagged as invalid by the rules in this plugin. To properly parse Tailwind-specific syntax, install the [`tailwind-csstree`](https://npmjs.com/package/tailwind-csstree) package:
222+
223+
```shell
224+
npm i tailwind-csstree --save-dev
225+
```
226+
227+
Then include it in your configuration using `languageOptions.customSyntax`:
222228

223229
```js
224230
// eslint.config.js
225231
import { defineConfig } from "eslint/config";
226232
import css from "@eslint/css";
227-
import { tailwindSyntax } from "@eslint/css/syntax";
233+
import { tailwind4 } from "tailwind-csstree";
228234

229235
export default defineConfig([
230236
{
@@ -234,7 +240,7 @@ export default defineConfig([
234240
},
235241
language: "css/css",
236242
languageOptions: {
237-
customSyntax: tailwindSyntax,
243+
customSyntax: tailwind4,
238244
},
239245
rules: {
240246
"css/no-empty-blocks": "error",
@@ -243,8 +249,6 @@ export default defineConfig([
243249
]);
244250
```
245251

246-
**Note:** The Tailwind syntax doesn't currently provide for the `theme()` function. This is a [limitation of CSSTree](https://github.com/csstree/csstree/issues/292) that we hope will be resolved soon.
247-
248252
## Editor and IDE Setup
249253

250254
### Visual Studio Code

jsr.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"name": "@eslint/css",
33
"version": "0.9.0",
44
"exports": {
5-
".": "./dist/esm/index.js",
6-
"./syntax": "./dist/esm/syntax/index.js"
5+
".": "./dist/esm/index.js"
76
},
87
"publish": {
98
"include": [

package.json

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@
1717
"default": "./dist/esm/index.js"
1818
}
1919
},
20-
"./syntax": {
21-
"require": {
22-
"types": "./dist/cjs/syntax/index.d.cts",
23-
"default": "./dist/cjs/syntax/index.cjs"
24-
},
25-
"import": {
26-
"types": "./dist/esm/syntax/index.d.ts",
27-
"default": "./dist/esm/syntax/index.js"
28-
}
29-
},
3020
"./types": {
3121
"require": {
3222
"types": "./dist/cjs/types.cts"
@@ -69,9 +59,8 @@
6959
"homepage": "https://github.com/eslint/css#readme",
7060
"scripts": {
7161
"build:dedupe-types": "node tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js",
72-
"build:cts": "node -e \"fs.copyFileSync('dist/esm/index.d.ts', 'dist/cjs/index.d.cts')\"",
73-
"build:syntax-cts": "node -e \"fs.copyFileSync('dist/esm/syntax/index.d.ts', 'dist/cjs/syntax/index.d.cts')\" && node tools/update-cts.js dist/cjs/types.cts dist/cjs/index.d.cts",
74-
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts && tsc -p tsconfig.syntax.json && npm run build:syntax-cts",
62+
"build:cts": "node -e \"fs.copyFileSync('dist/esm/index.d.ts', 'dist/cjs/index.d.cts')\" && node tools/update-cts.js dist/cjs/types.cts dist/cjs/index.d.cts",
63+
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts",
7564
"build:readme": "node tools/update-readme.js",
7665
"build:update-rules-docs": "node tools/update-rules-docs.js",
7766
"build:baseline": "node tools/generate-baseline.js",
@@ -114,6 +103,7 @@
114103
"rollup": "^4.16.2",
115104
"rollup-plugin-copy": "^3.5.0",
116105
"rollup-plugin-delete": "^3.0.1",
106+
"tailwind-csstree": "^0.1.0",
117107
"typescript": "^5.8.2",
118108
"web-features": "^2.35.1",
119109
"yorkie": "^2.0.0"

rollup.config.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,4 @@ export default [
2929
}),
3030
],
3131
},
32-
{
33-
input: "src/syntax/index.js",
34-
output: [
35-
{
36-
file: "dist/cjs/syntax/index.cjs",
37-
format: "cjs",
38-
},
39-
{
40-
file: "dist/esm/syntax/index.js",
41-
format: "esm",
42-
banner: '// @ts-self-types="./index.d.ts"',
43-
},
44-
],
45-
},
4632
];

src/syntax/index.js

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

src/syntax/tailwind-syntax.js

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

tests/rules/no-invalid-at-rules.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import rule from "../../src/rules/no-invalid-at-rules.js";
1111
import css from "../../src/index.js";
12-
import tailwindSyntax from "../../src/syntax/tailwind-syntax.js";
12+
import { tailwind3 } from "tailwind-csstree";
1313
import { RuleTester } from "eslint";
1414

1515
//------------------------------------------------------------------------------
@@ -46,25 +46,25 @@ ruleTester.run("no-invalid-at-rules", rule, {
4646
{
4747
code: "@tailwind base; @tailwind components; @tailwind utilities;",
4848
languageOptions: {
49-
customSyntax: tailwindSyntax,
49+
customSyntax: tailwind3,
5050
},
5151
},
5252
{
5353
code: "a { @apply text-red-500; }",
5454
languageOptions: {
55-
customSyntax: tailwindSyntax,
55+
customSyntax: tailwind3,
5656
},
5757
},
5858
{
5959
code: "a { @apply text-red-500 bg-blue-500; }",
6060
languageOptions: {
61-
customSyntax: tailwindSyntax,
61+
customSyntax: tailwind3,
6262
},
6363
},
6464
{
6565
code: "@config 'tailwind.config.js';",
6666
languageOptions: {
67-
customSyntax: tailwindSyntax,
67+
customSyntax: tailwind3,
6868
},
6969
},
7070
{
@@ -240,7 +240,7 @@ ruleTester.run("no-invalid-at-rules", rule, {
240240
{
241241
code: "a { @apply; }",
242242
languageOptions: {
243-
customSyntax: tailwindSyntax,
243+
customSyntax: tailwind3,
244244
},
245245
errors: [
246246
{
@@ -258,7 +258,7 @@ ruleTester.run("no-invalid-at-rules", rule, {
258258
{
259259
code: "@config;",
260260
languageOptions: {
261-
customSyntax: tailwindSyntax,
261+
customSyntax: tailwind3,
262262
},
263263
errors: [
264264
{
@@ -276,7 +276,7 @@ ruleTester.run("no-invalid-at-rules", rule, {
276276
{
277277
code: "@config foo;",
278278
languageOptions: {
279-
customSyntax: tailwindSyntax,
279+
customSyntax: tailwind3,
280280
},
281281
errors: [
282282
{

tsconfig.syntax.json

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

0 commit comments

Comments
 (0)