Skip to content

Commit eaf95fe

Browse files
committed
feat: improve it for tailwind v1
1 parent 77b5486 commit eaf95fe

File tree

3 files changed

+60
-66
lines changed

3 files changed

+60
-66
lines changed

README.md

Lines changed: 19 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
11
# Tailwind CSS Linter (CLI)
22

3-
A command-line tool that uses the Tailwind CSS IntelliSense engine to lint your Tailwind classes.
3+
[![](https://img.shields.io/badge/Tailwind%20CSS%20Linter-v1.0.0-blue)](https://www.npmjs.com/package/tailwind-lint) ![](https://github.com/ph1p/tailwind-lint/actions/workflows/ci.yml/badge.svg) ![](https://github.com/ph1p/tailwind-lint/actions/workflows/release.yml/badge.svg)
44

5+
It just lints your Tailwind project as the IDE will do, just on the command line.
56
Supports **Tailwind CSS v4** (CSS-based config) and **v3** (JavaScript config, legacy).
67

7-
## Features
8-
9-
**Core (v3 & v4):**
10-
- CSS Conflicts - Detects when multiple classes apply the same CSS properties
11-
- Invalid @apply Usage - Validates if a class can be used with `@apply`
12-
- Invalid @screen References - Detects references to non-existent breakpoints
13-
- Invalid Config Paths - Validates references in `config()` and `theme()` functions
14-
- Invalid @tailwind Directives - Validates `@tailwind` layer values
15-
- Recommended Variant Order - Suggests preferred ordering of variants
16-
- Blocklisted Classes - Detects usage of blocklisted classes
17-
- Autofix - Automatically fix issues with `--fix` flag
18-
19-
**v4-Specific:**
20-
- Canonical Class Suggestions - Suggests shorthand equivalents for arbitrary values (e.g., `top-[60px]``top-15`)
21-
- Invalid @source Directives - Validates `@source` directive paths
22-
- Full theme loading - Automatically loads Tailwind's default theme
23-
24-
## Requirements
25-
26-
- Node.js >= 22.0.0
27-
- Tailwind CSS v4 or v3 (installed in your project)
28-
298
## Installation
309

3110
```bash
@@ -45,6 +24,9 @@ pnpm dlx tailwind-lint "src/**/*.html"
4524
## Usage
4625

4726
```bash
27+
# fastest way to lint and fix issues
28+
npx tailwind-lint --auto --fix
29+
4830
tailwind-lint [options] [files...]
4931
```
5032

@@ -141,50 +123,22 @@ Use `--fix` to automatically resolve issues:
141123

142124
Files are written atomically with multiple iterations to ensure all fixes are applied. The autofix process has a safety limit of 100 iterations per file to prevent infinite loops.
143125

144-
## Output Examples
145-
146-
**Issues found:**
147-
```
148-
src/example.html
149-
10:8 warning 'p-4' applies the same CSS properties as 'px-8' (cssConflict)
150-
13:8 warning 'text-red-500' applies the same CSS properties as 'text-blue-500' (cssConflict)
151-
152-
Found 2 warnings in 1 file
153-
```
154-
155-
**With --fix:**
156-
```
157-
src/components.html
158-
✔ Fixed 2 issues
126+
## Features
159127

160-
✔ Fixed 2 issues
161-
```
128+
**Core (v3 & v4):**
129+
- CSS Conflicts - Detects when multiple classes apply the same CSS properties
130+
- Invalid @apply Usage - Validates if a class can be used with `@apply`
131+
- Invalid @screen References - Detects references to non-existent breakpoints
132+
- Invalid Config Paths - Validates references in `config()` and `theme()` functions
133+
- Invalid @tailwind Directives - Validates `@tailwind` layer values
134+
- Recommended Variant Order - Suggests preferred ordering of variants
135+
- Blocklisted Classes - Detects usage of blocklisted classes
136+
- Autofix - Automatically fix issues with `--fix` flag
162137

163-
**With --verbose:**
164-
```
165-
→ Running in verbose mode
166-
Working directory: /path/to/project
167-
Config path: auto-discover
168-
Fix mode: false
169-
Patterns: src/**/*.tsx
170-
171-
→ Initializing Tailwind CSS language service...
172-
Tailwind version: 4.1.18
173-
Config type: CSS (v4)
174-
Config path: /path/to/project/app.css
175-
✓ Loaded v4 design system
176-
✓ State initialized successfully
177-
178-
→ Discovered 15 files to lint
179-
[1/15] Linting src/components/Button.tsx
180-
[2/15] Linting src/components/Card.tsx
181-
...
182-
183-
src/components/Button.tsx
184-
10:8 warning 'p-4' applies the same CSS properties as 'px-8' (cssConflict)
185-
186-
Found 1 warning in 1 file
187-
```
138+
**v4-Specific:**
139+
- Canonical Class Suggestions - Suggests shorthand equivalents for arbitrary values (e.g., `top-[60px]` → `top-15`)
140+
- Invalid @source Directives - Validates `@source` directive paths
141+
- Full theme loading - Automatically loads Tailwind's default theme
188142

189143
## Development
190144

src/adapters/v4-adapter.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export async function loadV4DesignSystem(
3838
css: string,
3939
options: {
4040
base: string;
41+
loadModule?: (
42+
id: string,
43+
base: string,
44+
type: "config" | "plugin",
45+
) => Promise<{ base: string; module: unknown }>;
4146
loadStylesheet: (
4247
id: string,
4348
base: string,
@@ -51,6 +56,24 @@ export async function loadV4DesignSystem(
5156

5257
const designSystem = await loadDesignSystem(cssContent, {
5358
base: basePath,
59+
async loadModule(
60+
id: string,
61+
base: string,
62+
_type: "config" | "plugin",
63+
): Promise<{ base: string; module: unknown }> {
64+
try {
65+
const modulePath = require.resolve(id, { paths: [base, cwd] });
66+
const module = require(modulePath);
67+
return {
68+
base: path.dirname(modulePath),
69+
module,
70+
};
71+
} catch (error) {
72+
throw new Error(
73+
`Failed to load module "${id}": ${error instanceof Error ? error.message : String(error)}`,
74+
);
75+
}
76+
},
5477
async loadStylesheet(
5578
_id: string,
5679
base: string,

src/constants.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,26 @@ export const V4_CSS_NAMES = [
2626
"index.css",
2727
"tailwind.css",
2828
"globals.css",
29+
"global.css",
30+
"styles.css",
31+
"style.css",
32+
"main.css",
2933
];
3034

31-
export const V4_CSS_FOLDERS = ["./", "./src/", "./app/", "./styles/"];
35+
export const V4_CSS_FOLDERS = [
36+
"./",
37+
"./src/",
38+
"./src/css/",
39+
"./src/style/",
40+
"./src/styles/",
41+
"./app/",
42+
"./app/css/",
43+
"./app/style/",
44+
"./app/styles/",
45+
"./css/",
46+
"./style/",
47+
"./styles/",
48+
];
3249

3350
export const LANGUAGE_MAP: Record<string, string> = {
3451
".astro": "astro",

0 commit comments

Comments
 (0)