tailwind-canonical 0.1.3 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -24
- package/dist/cli/index.js +134 -21
- package/dist/cli/index.js.map +1 -1
- package/dist/core/analyzer.d.ts.map +1 -1
- package/dist/core/analyzer.js +4 -8
- package/dist/core/analyzer.js.map +1 -1
- package/dist/core/class-strings.d.ts +13 -0
- package/dist/core/class-strings.d.ts.map +1 -0
- package/dist/core/class-strings.js +116 -0
- package/dist/core/class-strings.js.map +1 -0
- package/dist/core/deduplicator.d.ts +2 -1
- package/dist/core/deduplicator.d.ts.map +1 -1
- package/dist/core/deduplicator.js +290 -74
- package/dist/core/deduplicator.js.map +1 -1
- package/dist/core/fixer.d.ts.map +1 -1
- package/dist/core/fixer.js +13 -18
- package/dist/core/fixer.js.map +1 -1
- package/dist/core/merger.d.ts +2 -1
- package/dist/core/merger.d.ts.map +1 -1
- package/dist/core/merger.js +5 -14
- package/dist/core/merger.js.map +1 -1
- package/dist/core/rules.d.ts +1 -0
- package/dist/core/rules.d.ts.map +1 -1
- package/dist/core/rules.js +43 -55
- package/dist/core/rules.js.map +1 -1
- package/dist/core/scanner.d.ts +1 -1
- package/dist/core/scanner.d.ts.map +1 -1
- package/dist/core/scanner.js +74 -5
- package/dist/core/scanner.js.map +1 -1
- package/dist/core/sorter.d.ts +4 -0
- package/dist/core/sorter.d.ts.map +1 -0
- package/dist/core/sorter.js +137 -0
- package/dist/core/sorter.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +15 -10
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# tailwind-canonical
|
|
2
2
|
|
|
3
|
-
Lint and auto-fix Tailwind CSS arbitrary values
|
|
3
|
+
Lint and auto-fix Tailwind CSS classes: arbitrary values → canonical, deduplication, shorthand collapsing, and class sorting.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -13,24 +13,137 @@ yarn add -D tailwind-canonical
|
|
|
13
13
|
## CLI
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
# Check
|
|
16
|
+
# Check for non-canonical arbitrary values
|
|
17
17
|
npx tailwind-canonical ./src
|
|
18
18
|
|
|
19
|
-
#
|
|
19
|
+
# Glob patterns (quote to prevent shell expansion)
|
|
20
|
+
npx tailwind-canonical 'src/**/*.tsx'
|
|
21
|
+
npx tailwind-canonical 'src/**/*.{tsx,ts}'
|
|
22
|
+
|
|
23
|
+
# Auto-fix: arbitrary → canonical
|
|
20
24
|
npx tailwind-canonical --fix ./src
|
|
25
|
+
|
|
26
|
+
# Deduplicate and collapse shorthands
|
|
27
|
+
npx tailwind-canonical --dedup ./src
|
|
28
|
+
|
|
29
|
+
# Sort classes into canonical order
|
|
30
|
+
npx tailwind-canonical --sort ./src
|
|
31
|
+
|
|
32
|
+
# Resolve conflicts with tailwind-merge (requires: pnpm add -D tailwind-merge)
|
|
33
|
+
npx tailwind-canonical --merge ./src
|
|
34
|
+
|
|
35
|
+
# Combine: fix → dedup → merge → sort
|
|
36
|
+
npx tailwind-canonical --fix --dedup --merge --sort ./src
|
|
37
|
+
|
|
38
|
+
# Structured output for CI (check mode only)
|
|
39
|
+
npx tailwind-canonical --reporter json ./src
|
|
40
|
+
npx tailwind-canonical --reporter sarif ./src
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## What each flag does
|
|
44
|
+
|
|
45
|
+
| Flag | What it fixes | Example |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| `--fix` | Arbitrary values → canonical tokens | `text-[12px]` → `text-xs` |
|
|
48
|
+
| `--dedup` | Redundant or conflicting classes | `flex block` → `block`, `px-4 py-4` → `p-4` |
|
|
49
|
+
| `--dedup` | Directional shorthand collapse | `border-t-2 border-b-2` → `border-y-2`, `top-4 bottom-4` → `inset-y-4` |
|
|
50
|
+
| `--sort` | Canonical class order | `text-sm flex p-4` → `flex p-4 text-sm` |
|
|
51
|
+
| `--merge` | tailwind-merge conflict resolution | `bg-red-500 bg-blue-500` → `bg-blue-500` |
|
|
52
|
+
| `--reporter json` | JSON output (check mode) or fix summary | machine-readable for CI pipelines |
|
|
53
|
+
| `--reporter sarif` | SARIF 2.1.0 output (check mode) | GitHub Code Scanning / VS Code |
|
|
54
|
+
|
|
55
|
+
## Structured output (`--reporter`)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# JSON — check mode: outputs findings, exits 1 if any found
|
|
59
|
+
npx tailwind-canonical --reporter json ./src
|
|
60
|
+
```
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"files": 3,
|
|
64
|
+
"total": 2,
|
|
65
|
+
"findings": [
|
|
66
|
+
{ "file": "src/Button.tsx", "line": 12, "col": 17, "original": "text-[14px]", "canonical": "text-sm", "isCustomToken": false }
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# JSON — fix mode: outputs summary of changes
|
|
73
|
+
npx tailwind-canonical --fix --reporter json ./src
|
|
74
|
+
```
|
|
75
|
+
```json
|
|
76
|
+
{ "files": 3, "changedFiles": ["src/Button.tsx"], "fixed": 1, "deduped": 0, "merged": 0, "sorted": 0 }
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# SARIF — compatible with GitHub Code Scanning and VS Code Problem Matcher
|
|
81
|
+
npx tailwind-canonical --reporter sarif ./src > results.sarif
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Canonical class order (`--sort`)
|
|
85
|
+
|
|
86
|
+
`layout → position → display → flex/grid → sizing → border → spacing → typography → colors → effects → transitions → transforms → interactivity → a11y → variants`
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
// before
|
|
90
|
+
className="text-sm bg-red-500 flex h-10 w-full p-4 rounded"
|
|
91
|
+
|
|
92
|
+
// after
|
|
93
|
+
className="flex h-10 w-full rounded p-4 text-sm bg-red-500"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Variants (`hover:`, `sm:`, `focus:`) are sorted after base classes, with responsive breakpoints before state variants.
|
|
97
|
+
|
|
98
|
+
## Deduplication (`--dedup`)
|
|
99
|
+
|
|
100
|
+
### Exact duplicates and conflicts
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
flex flex flex → flex
|
|
104
|
+
flex block → block (last wins)
|
|
105
|
+
relative absolute → absolute
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Padding / margin shorthand collapse
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
px-4 py-4 → p-4
|
|
112
|
+
p-4 px-2 → py-4 px-2
|
|
113
|
+
pt-2 pb-2 → py-2
|
|
114
|
+
pl-4 pr-4 → px-4
|
|
115
|
+
mx-4 my-4 → m-4
|
|
21
116
|
```
|
|
22
117
|
|
|
23
|
-
|
|
118
|
+
### Border shorthand collapse
|
|
24
119
|
|
|
25
120
|
```
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
121
|
+
border-t-2 border-b-2 border-l-2 border-r-2 → border-2
|
|
122
|
+
border-t-2 border-b-2 → border-y-2
|
|
123
|
+
border-l-4 border-r-4 → border-x-4
|
|
124
|
+
```
|
|
29
125
|
|
|
30
|
-
|
|
31
|
-
|
|
126
|
+
### Inset shorthand collapse
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
top-4 right-4 bottom-4 left-4 → inset-4
|
|
130
|
+
top-4 bottom-4 → inset-y-4
|
|
131
|
+
left-2 right-2 → inset-x-2
|
|
32
132
|
```
|
|
33
133
|
|
|
134
|
+
## Arbitrary value detection (`--fix`)
|
|
135
|
+
|
|
136
|
+
| Arbitrary | Canonical | Notes |
|
|
137
|
+
|---|---|---|
|
|
138
|
+
| `text-[12px]` | `text-xs` | Built-in |
|
|
139
|
+
| `text-[0.75rem]` | `text-xs` | rem values |
|
|
140
|
+
| `h-[64px]` | `h-16` | Spacing scale ÷4 |
|
|
141
|
+
| `w-[50%]` | `w-1/2` | Percentage fractions |
|
|
142
|
+
| `opacity-[0.5]` | `opacity-50` | Opacity scale |
|
|
143
|
+
| `text-[11px]` | `text-2xs` | Custom token |
|
|
144
|
+
|
|
145
|
+
Non-divisible values (`h-[22px]`, `px-[7px]`) are left untouched.
|
|
146
|
+
|
|
34
147
|
## Config
|
|
35
148
|
|
|
36
149
|
Create `tailwind-canonical.config.js` at the root:
|
|
@@ -42,9 +155,14 @@ export default {
|
|
|
42
155
|
11: '2xs',
|
|
43
156
|
13: 'xxs',
|
|
44
157
|
},
|
|
158
|
+
customSpacingTokens: {
|
|
159
|
+
14: '3.5',
|
|
160
|
+
},
|
|
45
161
|
}
|
|
46
162
|
```
|
|
47
163
|
|
|
164
|
+
`customTextTokens` merges with the built-in text size map. `customSpacingTokens` supplements the default ÷4 spacing logic.
|
|
165
|
+
|
|
48
166
|
## ESLint plugin
|
|
49
167
|
|
|
50
168
|
```js
|
|
@@ -56,28 +174,42 @@ export default [
|
|
|
56
174
|
plugins: { 'tailwind-canonical': tailwindCanonical },
|
|
57
175
|
rules: {
|
|
58
176
|
'tailwind-canonical/no-arbitrary-canonical': 'warn',
|
|
177
|
+
// Optional: flag tailwind-merge conflicts (requires tailwind-merge peer dep)
|
|
178
|
+
'tailwind-canonical/no-conflicting-classes': 'warn',
|
|
59
179
|
},
|
|
60
180
|
},
|
|
61
181
|
]
|
|
62
182
|
```
|
|
63
183
|
|
|
64
|
-
## Pre-commit hook (Husky)
|
|
184
|
+
## Pre-commit hook (Husky / Lefthook)
|
|
65
185
|
|
|
66
186
|
```bash
|
|
67
|
-
# .
|
|
68
|
-
|
|
187
|
+
# Lefthook: lefthook.yml
|
|
188
|
+
pre-commit:
|
|
189
|
+
commands:
|
|
190
|
+
tailwind:
|
|
191
|
+
glob: "src/**/*.{tsx,jsx}"
|
|
192
|
+
run: npx tailwind-canonical --fix --dedup --sort {staged_files}
|
|
193
|
+
stage_fixed: true
|
|
69
194
|
```
|
|
70
195
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
| `text-[12px]` | `text-xs` | Built-in |
|
|
76
|
-
| `text-[14px]` | `text-sm` | Built-in |
|
|
77
|
-
| `text-[11px]` | `text-2xs` | Custom token |
|
|
78
|
-
| `h-[64px]` | `h-16` | Spacing scale ÷4 |
|
|
79
|
-
| `w-[32px]` | `w-8` | Spacing scale ÷4 |
|
|
80
|
-
| `min-h-[56px]` | `min-h-14` | Spacing scale ÷4 |
|
|
81
|
-
| `max-w-[280px]` | `max-w-70` | Spacing scale ÷4 |
|
|
196
|
+
```bash
|
|
197
|
+
# Husky: .husky/pre-commit
|
|
198
|
+
npx tailwind-canonical --fix --dedup --sort ./src ./app
|
|
199
|
+
```
|
|
82
200
|
|
|
83
|
-
|
|
201
|
+
## Programmatic API
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import {
|
|
205
|
+
suggestCanonical, // pure: class string → suggestion or null
|
|
206
|
+
analyzeFile, // find non-canonical classes in a file
|
|
207
|
+
fixFile, // apply --fix in-place
|
|
208
|
+
deduplicateClasses, // pure: deduplicate a class string
|
|
209
|
+
dedupeFile, // apply --dedup in-place
|
|
210
|
+
sortClasses, // pure: sort a class string
|
|
211
|
+
sortFile, // apply --sort in-place
|
|
212
|
+
mergeFile, // apply --merge in-place (requires tailwind-merge)
|
|
213
|
+
scanFiles, // recursive file scanner
|
|
214
|
+
} from 'tailwind-canonical'
|
|
215
|
+
```
|
package/dist/cli/index.js
CHANGED
|
@@ -4,13 +4,24 @@ import { dedupeFile } from '../core/deduplicator.js';
|
|
|
4
4
|
import { fixFile } from '../core/fixer.js';
|
|
5
5
|
import { mergeFile } from '../core/merger.js';
|
|
6
6
|
import { scanFiles } from '../core/scanner.js';
|
|
7
|
+
import { sortFile } from '../core/sorter.js';
|
|
8
|
+
function pluralize(n, word) {
|
|
9
|
+
return `${n} ${word}${n !== 1 ? 's' : ''}`;
|
|
10
|
+
}
|
|
11
|
+
const SARIF_SCHEMA = 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json';
|
|
7
12
|
const args = process.argv.slice(2);
|
|
8
13
|
const fix = args.includes('--fix');
|
|
9
14
|
const merge = args.includes('--merge');
|
|
10
15
|
const dedup = args.includes('--dedup');
|
|
11
|
-
const
|
|
16
|
+
const sort = args.includes('--sort');
|
|
17
|
+
const reporterIdx = args.indexOf('--reporter');
|
|
18
|
+
const reporter = reporterIdx !== -1 &&
|
|
19
|
+
(args[reporterIdx + 1] === 'json' || args[reporterIdx + 1] === 'sarif')
|
|
20
|
+
? args[reporterIdx + 1]
|
|
21
|
+
: 'text';
|
|
22
|
+
const targets = args.filter((a, i) => !a.startsWith('--') && args[i - 1] !== '--reporter');
|
|
12
23
|
if (targets.length === 0) {
|
|
13
|
-
console.error('Usage: tailwind-canonical [--fix] [--merge] [--dedup] <dir|file> [dir|file...]');
|
|
24
|
+
console.error('Usage: tailwind-canonical [--fix] [--merge] [--dedup] [--sort] [--reporter json|sarif] <dir|file> [dir|file...]');
|
|
14
25
|
process.exit(1);
|
|
15
26
|
}
|
|
16
27
|
if (merge) {
|
|
@@ -33,46 +44,148 @@ let totalFindings = 0;
|
|
|
33
44
|
let totalFixed = 0;
|
|
34
45
|
let totalMerged = 0;
|
|
35
46
|
let totalDeduped = 0;
|
|
47
|
+
let totalSorted = 0;
|
|
48
|
+
const allFindings = [];
|
|
49
|
+
const changedFiles = [];
|
|
36
50
|
for (const file of files) {
|
|
37
51
|
if (fix) {
|
|
38
52
|
const count = fixFile(file, config);
|
|
39
53
|
if (count > 0) {
|
|
40
|
-
console.log(` fixed ${file} (${count} replacement${count > 1 ? 's' : ''})`);
|
|
41
54
|
totalFixed += count;
|
|
55
|
+
changedFiles.push(file);
|
|
56
|
+
if (reporter === 'text') {
|
|
57
|
+
console.log(` fixed ${file} (${pluralize(count, 'replacement')})`);
|
|
58
|
+
}
|
|
42
59
|
}
|
|
43
60
|
}
|
|
44
61
|
if (dedup) {
|
|
45
|
-
const count = dedupeFile(file);
|
|
62
|
+
const count = dedupeFile(file, { functionNames: config.functionNames });
|
|
46
63
|
if (count > 0) {
|
|
47
|
-
console.log(` deduped ${file} (${count} class string${count > 1 ? 's' : ''})`);
|
|
48
64
|
totalDeduped += count;
|
|
65
|
+
if (!changedFiles.includes(file))
|
|
66
|
+
changedFiles.push(file);
|
|
67
|
+
if (reporter === 'text') {
|
|
68
|
+
console.log(` deduped ${file} (${pluralize(count, 'class string')})`);
|
|
69
|
+
}
|
|
49
70
|
}
|
|
50
71
|
}
|
|
51
72
|
if (merge) {
|
|
52
|
-
const count = await mergeFile(file
|
|
73
|
+
const count = await mergeFile(file, {
|
|
74
|
+
functionNames: config.functionNames,
|
|
75
|
+
});
|
|
53
76
|
if (count > 0) {
|
|
54
|
-
console.log(` merged ${file} (${count} conflict${count > 1 ? 's' : ''})`);
|
|
55
77
|
totalMerged += count;
|
|
78
|
+
if (!changedFiles.includes(file))
|
|
79
|
+
changedFiles.push(file);
|
|
80
|
+
if (reporter === 'text') {
|
|
81
|
+
console.log(` merged ${file} (${pluralize(count, 'conflict')})`);
|
|
82
|
+
}
|
|
56
83
|
}
|
|
57
84
|
}
|
|
58
|
-
if (
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
85
|
+
if (sort) {
|
|
86
|
+
const count = sortFile(file, { functionNames: config.functionNames });
|
|
87
|
+
if (count > 0) {
|
|
88
|
+
totalSorted += count;
|
|
89
|
+
if (!changedFiles.includes(file))
|
|
90
|
+
changedFiles.push(file);
|
|
91
|
+
if (reporter === 'text') {
|
|
92
|
+
console.log(` sorted ${file} (${pluralize(count, 'class string')})`);
|
|
93
|
+
}
|
|
63
94
|
}
|
|
95
|
+
}
|
|
96
|
+
if (!fix && !dedup && !merge && !sort) {
|
|
97
|
+
const findings = analyzeFile(file, config);
|
|
98
|
+
allFindings.push(...findings);
|
|
64
99
|
totalFindings += findings.length;
|
|
100
|
+
if (reporter === 'text') {
|
|
101
|
+
for (const f of findings) {
|
|
102
|
+
const tag = f.suggestion.isCustomToken ? ' [custom token]' : '';
|
|
103
|
+
console.log(` ${f.file}:${f.line}:${f.col} ${f.suggestion.original} → ${f.suggestion.canonical}${tag}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
65
106
|
}
|
|
66
107
|
}
|
|
67
|
-
if (fix || dedup || merge) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
108
|
+
if (fix || dedup || merge || sort) {
|
|
109
|
+
if (reporter === 'json') {
|
|
110
|
+
process.stdout.write(`${JSON.stringify({
|
|
111
|
+
files: files.length,
|
|
112
|
+
changedFiles,
|
|
113
|
+
fixed: totalFixed,
|
|
114
|
+
deduped: totalDeduped,
|
|
115
|
+
merged: totalMerged,
|
|
116
|
+
sorted: totalSorted,
|
|
117
|
+
}, null, 2)}\n`);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const parts = [];
|
|
121
|
+
if (fix)
|
|
122
|
+
parts.push(pluralize(totalFixed, 'replacement'));
|
|
123
|
+
if (dedup)
|
|
124
|
+
parts.push(pluralize(totalDeduped, 'dedup'));
|
|
125
|
+
if (merge)
|
|
126
|
+
parts.push(`${pluralize(totalMerged, 'conflict')} merged`);
|
|
127
|
+
if (sort)
|
|
128
|
+
parts.push(`${totalSorted} sorted`);
|
|
129
|
+
console.log(`\n✓ Fixed ${parts.join(', ')} across ${files.length} file${files.length !== 1 ? 's' : ''}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (reporter === 'json') {
|
|
133
|
+
process.stdout.write(`${JSON.stringify({
|
|
134
|
+
files: files.length,
|
|
135
|
+
total: totalFindings,
|
|
136
|
+
findings: allFindings.map((f) => ({
|
|
137
|
+
file: f.file,
|
|
138
|
+
line: f.line,
|
|
139
|
+
col: f.col,
|
|
140
|
+
original: f.suggestion.original,
|
|
141
|
+
canonical: f.suggestion.canonical,
|
|
142
|
+
isCustomToken: f.suggestion.isCustomToken,
|
|
143
|
+
})),
|
|
144
|
+
}, null, 2)}\n`);
|
|
145
|
+
if (totalFindings > 0)
|
|
146
|
+
process.exit(1);
|
|
147
|
+
}
|
|
148
|
+
else if (reporter === 'sarif') {
|
|
149
|
+
const sarifOutput = {
|
|
150
|
+
$schema: SARIF_SCHEMA,
|
|
151
|
+
version: '2.1.0',
|
|
152
|
+
runs: [
|
|
153
|
+
{
|
|
154
|
+
tool: {
|
|
155
|
+
driver: {
|
|
156
|
+
name: 'tailwind-canonical',
|
|
157
|
+
informationUri: 'https://github.com/peak-lab/tailwind-canonical',
|
|
158
|
+
rules: [
|
|
159
|
+
{
|
|
160
|
+
id: 'no-arbitrary-canonical',
|
|
161
|
+
name: 'NoArbitraryCanonical',
|
|
162
|
+
shortDescription: {
|
|
163
|
+
text: 'Arbitrary value has a canonical Tailwind equivalent',
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
results: allFindings.map((f) => ({
|
|
170
|
+
ruleId: 'no-arbitrary-canonical',
|
|
171
|
+
message: {
|
|
172
|
+
text: `${f.suggestion.original} → ${f.suggestion.canonical}`,
|
|
173
|
+
},
|
|
174
|
+
locations: [
|
|
175
|
+
{
|
|
176
|
+
physicalLocation: {
|
|
177
|
+
artifactLocation: { uri: f.file },
|
|
178
|
+
region: { startLine: f.line, startColumn: f.col },
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
})),
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
};
|
|
186
|
+
process.stdout.write(`${JSON.stringify(sarifOutput, null, 2)}\n`);
|
|
187
|
+
if (totalFindings > 0)
|
|
188
|
+
process.exit(1);
|
|
76
189
|
}
|
|
77
190
|
else if (totalFindings > 0) {
|
|
78
191
|
console.log(`\n✖ Found ${totalFindings} non-canonical class${totalFindings !== 1 ? 'es' : ''}`);
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAgB,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,SAAS,SAAS,CAAC,CAAS,EAAE,IAAY;IACxC,OAAO,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAC7C,CAAC;AAED,MAAM,YAAY,GAChB,gGAAgG,CAAC;AAEnG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACnC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACvC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACvC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAErC,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO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"","sources":["../../src/core/analyzer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAoB,MAAM,YAAY,CAAC;AAE5E,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;
|
|
1
|
+
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../../src/core/analyzer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAoB,MAAM,YAAY,CAAC;AAE5E,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAgCF,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,MAAW,GAAG,OAAO,EAAE,CAY5E"}
|
package/dist/core/analyzer.js
CHANGED
|
@@ -4,15 +4,11 @@ const CLASS_REGEX = /className(?:Name)?\s*=\s*(?:"([^"]+)"|'([^']+)'|`([^`]+)`|\
|
|
|
4
4
|
const SINGLE_CLASS_REGEX = /[^\s"'`{}]+/g;
|
|
5
5
|
function extractClasses(content) {
|
|
6
6
|
const found = [];
|
|
7
|
-
CLASS_REGEX
|
|
8
|
-
for (let match = CLASS_REGEX.exec(content); match !== null; match = CLASS_REGEX.exec(content)) {
|
|
7
|
+
for (const match of content.matchAll(CLASS_REGEX)) {
|
|
9
8
|
const raw = match[1] ?? match[2] ?? match[3] ?? match[4] ?? '';
|
|
10
|
-
|
|
11
|
-
for (
|
|
12
|
-
found.push({
|
|
13
|
-
cls: clsMatch[0],
|
|
14
|
-
index: match.index + match[0].indexOf(raw) + clsMatch.index,
|
|
15
|
-
});
|
|
9
|
+
const rawStart = (match.index ?? 0) + match[0].indexOf(raw);
|
|
10
|
+
for (const clsMatch of raw.matchAll(SINGLE_CLASS_REGEX)) {
|
|
11
|
+
found.push({ cls: clsMatch[0], index: rawStart + (clsMatch.index ?? 0) });
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
14
|
return found;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../../src/core/analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAgC,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAS5E,MAAM,WAAW,GACf,yEAAyE,CAAC;AAC5E,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAE1C,SAAS,cAAc,CACrB,OAAe;IAEf,MAAM,KAAK,GAA0C,EAAE,CAAC;IAExD,
|
|
1
|
+
{"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../../src/core/analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAgC,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAS5E,MAAM,WAAW,GACf,yEAAyE,CAAC;AAC5E,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAE1C,SAAS,cAAc,CACrB,OAAe;IAEf,MAAM,KAAK,GAA0C,EAAE,CAAC;IAExD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QAClD,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC/D,MAAM,QAAQ,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC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AAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ClassStringOpts = {
|
|
2
|
+
functionNames?: string[];
|
|
3
|
+
};
|
|
4
|
+
export declare function replaceClassStrings(content: string, transform: (s: string) => string, opts?: ClassStringOpts): {
|
|
5
|
+
result: string;
|
|
6
|
+
count: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function extractClassStrings(content: string, opts?: ClassStringOpts): Array<{
|
|
9
|
+
value: string;
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
}>;
|
|
13
|
+
//# sourceMappingURL=class-strings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-strings.d.ts","sourceRoot":"","sources":["../../src/core/class-strings.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AA+CF,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EAChC,IAAI,GAAE,eAAoB,GACzB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CA0CnC;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,eAAoB,GACzB,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CA8CtD"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
function escapeRegex(s) {
|
|
2
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3
|
+
}
|
|
4
|
+
function transformCallContent(content, start, transform) {
|
|
5
|
+
const parts = [];
|
|
6
|
+
let i = start;
|
|
7
|
+
let depth = 1;
|
|
8
|
+
let count = 0;
|
|
9
|
+
while (i < content.length && depth > 0) {
|
|
10
|
+
const ch = content[i];
|
|
11
|
+
if (ch === '(' || ch === '[' || ch === '{') {
|
|
12
|
+
depth++;
|
|
13
|
+
parts.push(ch);
|
|
14
|
+
i++;
|
|
15
|
+
}
|
|
16
|
+
else if (ch === ')' || ch === ']' || ch === '}') {
|
|
17
|
+
depth--;
|
|
18
|
+
parts.push(ch);
|
|
19
|
+
i++;
|
|
20
|
+
}
|
|
21
|
+
else if (ch === '"' || ch === "'") {
|
|
22
|
+
const q = ch;
|
|
23
|
+
let j = i + 1;
|
|
24
|
+
while (j < content.length && content[j] !== q) {
|
|
25
|
+
if (content[j] === '\\')
|
|
26
|
+
j++;
|
|
27
|
+
j++;
|
|
28
|
+
}
|
|
29
|
+
const raw = content.slice(i + 1, j);
|
|
30
|
+
const out = transform(raw);
|
|
31
|
+
if (out !== raw)
|
|
32
|
+
count++;
|
|
33
|
+
parts.push(`${q}${out}${q}`);
|
|
34
|
+
i = j + 1;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
parts.push(ch);
|
|
38
|
+
i++;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { processed: parts.join(''), consumed: i - start, count };
|
|
42
|
+
}
|
|
43
|
+
export function replaceClassStrings(content, transform, opts = {}) {
|
|
44
|
+
let result = content;
|
|
45
|
+
let count = 0;
|
|
46
|
+
result = result.replace(/className\s*=\s*(?:"([^"]+)"|'([^']+)'|`([^`]+)`)/g, (_full, dq, sq, bt) => {
|
|
47
|
+
const raw = dq ?? sq ?? bt ?? '';
|
|
48
|
+
const q = dq !== undefined ? '"' : sq !== undefined ? "'" : '`';
|
|
49
|
+
const out = transform(raw);
|
|
50
|
+
if (out !== raw)
|
|
51
|
+
count++;
|
|
52
|
+
return `className=${q}${out}${q}`;
|
|
53
|
+
});
|
|
54
|
+
const funcNames = opts.functionNames;
|
|
55
|
+
if (!funcNames?.length)
|
|
56
|
+
return { result, count };
|
|
57
|
+
const funcRe = new RegExp(`\\b(?:${funcNames.map(escapeRegex).join('|')})\\s*\\(`, 'g');
|
|
58
|
+
const buf = [];
|
|
59
|
+
let pos = 0;
|
|
60
|
+
for (const m of result.matchAll(funcRe)) {
|
|
61
|
+
const callStart = (m.index ?? 0) + m[0].length;
|
|
62
|
+
if (callStart < pos)
|
|
63
|
+
continue;
|
|
64
|
+
buf.push(result.slice(pos, callStart));
|
|
65
|
+
const { processed, consumed, count: c, } = transformCallContent(result, callStart, transform);
|
|
66
|
+
buf.push(processed);
|
|
67
|
+
pos = callStart + consumed;
|
|
68
|
+
count += c;
|
|
69
|
+
funcRe.lastIndex = pos;
|
|
70
|
+
}
|
|
71
|
+
buf.push(result.slice(pos));
|
|
72
|
+
return { result: buf.join(''), count };
|
|
73
|
+
}
|
|
74
|
+
export function extractClassStrings(content, opts = {}) {
|
|
75
|
+
const results = [];
|
|
76
|
+
for (const m of content.matchAll(/className\s*=\s*(?:"([^"]+)"|'([^']+)'|`([^`]+)`)/g)) {
|
|
77
|
+
const raw = m[1] ?? m[2] ?? m[3] ?? '';
|
|
78
|
+
const start = (m.index ?? 0) + m[0].length - raw.length - 1;
|
|
79
|
+
results.push({ value: raw, start, end: start + raw.length });
|
|
80
|
+
}
|
|
81
|
+
const funcNames = opts.functionNames;
|
|
82
|
+
if (!funcNames?.length)
|
|
83
|
+
return results;
|
|
84
|
+
const funcRe = new RegExp(`\\b(?:${funcNames.map(escapeRegex).join('|')})\\s*\\(`, 'g');
|
|
85
|
+
for (const m of content.matchAll(funcRe)) {
|
|
86
|
+
let i = (m.index ?? 0) + m[0].length;
|
|
87
|
+
let depth = 1;
|
|
88
|
+
while (i < content.length && depth > 0) {
|
|
89
|
+
const ch = content[i];
|
|
90
|
+
if (ch === '(' || ch === '[' || ch === '{') {
|
|
91
|
+
depth++;
|
|
92
|
+
i++;
|
|
93
|
+
}
|
|
94
|
+
else if (ch === ')' || ch === ']' || ch === '}') {
|
|
95
|
+
depth--;
|
|
96
|
+
i++;
|
|
97
|
+
}
|
|
98
|
+
else if (ch === '"' || ch === "'") {
|
|
99
|
+
const q = ch;
|
|
100
|
+
let j = i + 1;
|
|
101
|
+
while (j < content.length && content[j] !== q) {
|
|
102
|
+
if (content[j] === '\\')
|
|
103
|
+
j++;
|
|
104
|
+
j++;
|
|
105
|
+
}
|
|
106
|
+
results.push({ value: content.slice(i + 1, j), start: i + 1, end: j });
|
|
107
|
+
i = j + 1;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
i++;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return results;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=class-strings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-strings.js","sourceRoot":"","sources":["../../src/core/class-strings.ts"],"names":[],"mappings":"AAIA,SAAS,WAAW,CAAC,CAAS;IAC5B,OAAO,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,oBAAoB,CAC3B,OAAe,EACf,KAAa,EACb,SAAgC;IAEhC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,CAAC,GAAG,KAAK,CAAC;IACd,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACvC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YAC3C,KAAK,EAAE,CAAC;YACR,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACf,CAAC,EAAE,CAAC;QACN,CAAC;aAAM,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE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KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;gBACvE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACZ,CAAC;iBAAM,CAAC;gBACN,CAAC,EAAE,CAAC;YACN,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ClassStringOpts } from './class-strings.js';
|
|
1
2
|
export declare function deduplicateClasses(classStr: string): string;
|
|
2
|
-
export declare function dedupeFile(filePath: string): number;
|
|
3
|
+
export declare function dedupeFile(filePath: string, opts?: ClassStringOpts): number;
|
|
3
4
|
//# sourceMappingURL=deduplicator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deduplicator.d.ts","sourceRoot":"","sources":["../../src/core/deduplicator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deduplicator.d.ts","sourceRoot":"","sources":["../../src/core/deduplicator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAuB,MAAM,oBAAoB,CAAC;AA4U/E,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAyE3D;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,eAAoB,GACzB,MAAM,CASR"}
|