@economic/taco-rules 0.0.0-stage → 2.0.0-EC-00123-table3-bundle.0
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 +426 -2
- package/dist/oxlint/configs/all.d.ts +4 -0
- package/dist/oxlint/configs/all.js +5 -0
- package/dist/oxlint/configs/recommended.d.ts +4 -0
- package/dist/oxlint/configs/recommended.js +10 -0
- package/dist/oxlint/configs/styles.d.ts +4 -0
- package/dist/oxlint/configs/styles.js +12 -0
- package/dist/oxlint/index.d.ts +37 -0
- package/dist/oxlint/index.js +18 -0
- package/dist/oxlint/lib/create-class-policy-visitors.d.ts +9 -0
- package/dist/oxlint/lib/create-class-policy-visitors.js +17 -0
- package/dist/oxlint/lib/visit-tailwind-class-sources.d.ts +16 -0
- package/dist/oxlint/lib/visit-tailwind-class-sources.js +21 -0
- package/dist/oxlint/rules/consistent-clsx-import/consistent-clsx-import.d.ts +2 -0
- package/dist/oxlint/rules/consistent-clsx-import/consistent-clsx-import.js +66 -0
- package/dist/oxlint/rules/data-taco-kebab-case/data-taco-kebab-case.d.ts +2 -0
- package/dist/oxlint/rules/data-taco-kebab-case/data-taco-kebab-case.js +73 -0
- package/dist/oxlint/rules/index.d.ts +2 -0
- package/dist/oxlint/rules/index.js +30 -0
- package/dist/oxlint/rules/no-component-margin/no-component-margin.d.ts +2 -0
- package/dist/oxlint/rules/no-component-margin/no-component-margin.js +93 -0
- package/dist/oxlint/rules/no-cross-boundary-relative-imports/no-cross-boundary-relative-imports.d.ts +2 -0
- package/dist/oxlint/rules/no-cross-boundary-relative-imports/no-cross-boundary-relative-imports.js +131 -0
- package/dist/oxlint/rules/no-data-taco-attribute/no-data-taco-attribute.d.ts +2 -0
- package/dist/oxlint/rules/no-data-taco-attribute/no-data-taco-attribute.js +28 -0
- package/dist/oxlint/rules/no-disallowed-color-classes/no-disallowed-color-classes.d.ts +2 -0
- package/dist/oxlint/rules/no-disallowed-color-classes/no-disallowed-color-classes.js +23 -0
- package/dist/oxlint/rules/no-disallowed-radius-classes/no-disallowed-radius-classes.d.ts +2 -0
- package/dist/oxlint/rules/no-disallowed-radius-classes/no-disallowed-radius-classes.js +19 -0
- package/dist/oxlint/rules/no-disallowed-shadow-classes/no-disallowed-shadow-classes.d.ts +2 -0
- package/dist/oxlint/rules/no-disallowed-shadow-classes/no-disallowed-shadow-classes.js +20 -0
- package/dist/oxlint/rules/no-disallowed-spacing-classes/no-disallowed-spacing-classes.d.ts +2 -0
- package/dist/oxlint/rules/no-disallowed-spacing-classes/no-disallowed-spacing-classes.js +21 -0
- package/dist/oxlint/rules/no-display-value-key/no-display-value-key.d.ts +2 -0
- package/dist/oxlint/rules/no-display-value-key/no-display-value-key.js +114 -0
- package/dist/oxlint/rules/no-leaked-render/no-leaked-render.d.ts +2 -0
- package/dist/oxlint/rules/no-leaked-render/no-leaked-render.js +72 -0
- package/dist/oxlint/rules/no-react-useid/no-react-useid.d.ts +2 -0
- package/dist/oxlint/rules/no-react-useid/no-react-useid.js +56 -0
- package/dist/oxlint/rules/no-separate-size-classes/no-separate-size-classes.d.ts +2 -0
- package/dist/oxlint/rules/no-separate-size-classes/no-separate-size-classes.js +218 -0
- package/dist/oxlint/rules/no-unnecessary-template-literal/no-unnecessary-template-literal.d.ts +2 -0
- package/dist/oxlint/rules/no-unnecessary-template-literal/no-unnecessary-template-literal.js +63 -0
- package/dist/policies/classes.d.ts +12 -0
- package/dist/policies/classes.js +36 -0
- package/dist/policies/color.d.ts +11 -0
- package/dist/policies/color.js +217 -0
- package/dist/policies/radius.d.ts +4 -0
- package/dist/policies/radius.js +30 -0
- package/dist/policies/shadow.d.ts +2 -0
- package/dist/policies/shadow.js +23 -0
- package/dist/policies/spacing.d.ts +4 -0
- package/dist/policies/spacing.js +32 -0
- package/dist/policies/theme.d.ts +6 -0
- package/dist/policies/theme.js +14 -0
- package/dist/stylelint/index.d.ts +3 -0
- package/dist/stylelint/index.js +36 -0
- package/dist/stylelint/lib/create-policy-plugin.d.ts +16 -0
- package/dist/stylelint/lib/create-policy-plugin.js +36 -0
- package/dist/stylelint/lib/walk-css-sources.d.ts +15 -0
- package/dist/stylelint/lib/walk-css-sources.js +28 -0
- package/dist/stylelint/rules/color-token/color-token.d.ts +2 -0
- package/dist/stylelint/rules/color-token/color-token.js +4 -0
- package/dist/stylelint/rules/color-value/color-value.d.ts +2 -0
- package/dist/stylelint/rules/color-value/color-value.js +19 -0
- package/dist/stylelint/rules/radius/radius.d.ts +2 -0
- package/dist/stylelint/rules/radius/radius.js +8 -0
- package/dist/stylelint/rules/shadow/shadow.d.ts +2 -0
- package/dist/stylelint/rules/shadow/shadow.js +4 -0
- package/dist/stylelint/rules/spacing/spacing.d.ts +2 -0
- package/dist/stylelint/rules/spacing/spacing.js +8 -0
- package/oxlint/styles.json +11 -0
- package/package.json +67 -5
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { stripVariants } from "./classes.js";
|
|
2
|
+
import { tacoColors, tacoCssVariables, tailwindDefaultColors } from "./theme.js";
|
|
3
|
+
// Finds classes that set a color and picks out the color: `bg-blue-500` → `blue-500`. Longer prefixes
|
|
4
|
+
// come first so `border-t-blue-500` reads as "top border, blue-500", not "border, t-blue-500".
|
|
5
|
+
const COLOR_UTILITY = /^(?:border-[xytrblse]|ring-offset|placeholder|text|bg|border|ring|outline|shadow|divide|accent|caret|fill|stroke|decoration|from|via|to)-(.+)$/u;
|
|
6
|
+
// Finds custom text/background values written in brackets and picks out what's inside:
|
|
7
|
+
// `bg-[#ff0000]` → `#ff0000`. An opacity suffix (`/50`) may follow.
|
|
8
|
+
const ARBITRARY_TEXT_BG = /^(?:text|bg)-\[([^\]]+)\](?:\/(?:\d+|\[[^\]]+\]))?$/u;
|
|
9
|
+
// CSS functions that write a color by hand. Also what raw CSS may not call (stylelint's `function-disallowed-list`).
|
|
10
|
+
export const COLOR_FUNCTIONS = ['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'lab', 'lch', 'oklab', 'oklch', 'color'];
|
|
11
|
+
// Recognizes hand-written colors (`#fff`, `rgb(…)`, `oklch(…)`…). Other bracket values, like sizes, aren't colors and pass.
|
|
12
|
+
const COLOR_VALUE = new RegExp(`^(?:#[0-9a-f]{3,8}|(?:${COLOR_FUNCTIONS.join('|')})\\()`, 'iu');
|
|
13
|
+
// CSS's built-in color names. Spelled out, because treating any word as a color would also catch non-colors like `text-[larger]`.
|
|
14
|
+
const NAMED_COLORS = new Set([
|
|
15
|
+
'aliceblue',
|
|
16
|
+
'antiquewhite',
|
|
17
|
+
'aqua',
|
|
18
|
+
'aquamarine',
|
|
19
|
+
'azure',
|
|
20
|
+
'beige',
|
|
21
|
+
'bisque',
|
|
22
|
+
'black',
|
|
23
|
+
'blanchedalmond',
|
|
24
|
+
'blue',
|
|
25
|
+
'blueviolet',
|
|
26
|
+
'brown',
|
|
27
|
+
'burlywood',
|
|
28
|
+
'cadetblue',
|
|
29
|
+
'chartreuse',
|
|
30
|
+
'chocolate',
|
|
31
|
+
'coral',
|
|
32
|
+
'cornflowerblue',
|
|
33
|
+
'cornsilk',
|
|
34
|
+
'crimson',
|
|
35
|
+
'cyan',
|
|
36
|
+
'darkblue',
|
|
37
|
+
'darkcyan',
|
|
38
|
+
'darkgoldenrod',
|
|
39
|
+
'darkgray',
|
|
40
|
+
'darkgreen',
|
|
41
|
+
'darkgrey',
|
|
42
|
+
'darkkhaki',
|
|
43
|
+
'darkmagenta',
|
|
44
|
+
'darkolivegreen',
|
|
45
|
+
'darkorange',
|
|
46
|
+
'darkorchid',
|
|
47
|
+
'darkred',
|
|
48
|
+
'darksalmon',
|
|
49
|
+
'darkseagreen',
|
|
50
|
+
'darkslateblue',
|
|
51
|
+
'darkslategray',
|
|
52
|
+
'darkslategrey',
|
|
53
|
+
'darkturquoise',
|
|
54
|
+
'darkviolet',
|
|
55
|
+
'deeppink',
|
|
56
|
+
'deepskyblue',
|
|
57
|
+
'dimgray',
|
|
58
|
+
'dimgrey',
|
|
59
|
+
'dodgerblue',
|
|
60
|
+
'firebrick',
|
|
61
|
+
'floralwhite',
|
|
62
|
+
'forestgreen',
|
|
63
|
+
'fuchsia',
|
|
64
|
+
'gainsboro',
|
|
65
|
+
'ghostwhite',
|
|
66
|
+
'gold',
|
|
67
|
+
'goldenrod',
|
|
68
|
+
'gray',
|
|
69
|
+
'green',
|
|
70
|
+
'greenyellow',
|
|
71
|
+
'grey',
|
|
72
|
+
'honeydew',
|
|
73
|
+
'hotpink',
|
|
74
|
+
'indianred',
|
|
75
|
+
'indigo',
|
|
76
|
+
'ivory',
|
|
77
|
+
'khaki',
|
|
78
|
+
'lavender',
|
|
79
|
+
'lavenderblush',
|
|
80
|
+
'lawngreen',
|
|
81
|
+
'lemonchiffon',
|
|
82
|
+
'lightblue',
|
|
83
|
+
'lightcoral',
|
|
84
|
+
'lightcyan',
|
|
85
|
+
'lightgoldenrodyellow',
|
|
86
|
+
'lightgray',
|
|
87
|
+
'lightgreen',
|
|
88
|
+
'lightgrey',
|
|
89
|
+
'lightpink',
|
|
90
|
+
'lightsalmon',
|
|
91
|
+
'lightseagreen',
|
|
92
|
+
'lightskyblue',
|
|
93
|
+
'lightslategray',
|
|
94
|
+
'lightslategrey',
|
|
95
|
+
'lightsteelblue',
|
|
96
|
+
'lightyellow',
|
|
97
|
+
'lime',
|
|
98
|
+
'limegreen',
|
|
99
|
+
'linen',
|
|
100
|
+
'magenta',
|
|
101
|
+
'maroon',
|
|
102
|
+
'mediumaquamarine',
|
|
103
|
+
'mediumblue',
|
|
104
|
+
'mediumorchid',
|
|
105
|
+
'mediumpurple',
|
|
106
|
+
'mediumseagreen',
|
|
107
|
+
'mediumslateblue',
|
|
108
|
+
'mediumspringgreen',
|
|
109
|
+
'mediumturquoise',
|
|
110
|
+
'mediumvioletred',
|
|
111
|
+
'midnightblue',
|
|
112
|
+
'mintcream',
|
|
113
|
+
'mistyrose',
|
|
114
|
+
'moccasin',
|
|
115
|
+
'navajowhite',
|
|
116
|
+
'navy',
|
|
117
|
+
'oldlace',
|
|
118
|
+
'olive',
|
|
119
|
+
'olivedrab',
|
|
120
|
+
'orange',
|
|
121
|
+
'orangered',
|
|
122
|
+
'orchid',
|
|
123
|
+
'palegoldenrod',
|
|
124
|
+
'palegreen',
|
|
125
|
+
'paleturquoise',
|
|
126
|
+
'palevioletred',
|
|
127
|
+
'papayawhip',
|
|
128
|
+
'peachpuff',
|
|
129
|
+
'peru',
|
|
130
|
+
'pink',
|
|
131
|
+
'plum',
|
|
132
|
+
'powderblue',
|
|
133
|
+
'purple',
|
|
134
|
+
'rebeccapurple',
|
|
135
|
+
'red',
|
|
136
|
+
'rosybrown',
|
|
137
|
+
'royalblue',
|
|
138
|
+
'saddlebrown',
|
|
139
|
+
'salmon',
|
|
140
|
+
'sandybrown',
|
|
141
|
+
'seagreen',
|
|
142
|
+
'seashell',
|
|
143
|
+
'sienna',
|
|
144
|
+
'silver',
|
|
145
|
+
'skyblue',
|
|
146
|
+
'slateblue',
|
|
147
|
+
'slategray',
|
|
148
|
+
'slategrey',
|
|
149
|
+
'snow',
|
|
150
|
+
'springgreen',
|
|
151
|
+
'steelblue',
|
|
152
|
+
'tan',
|
|
153
|
+
'teal',
|
|
154
|
+
'thistle',
|
|
155
|
+
'tomato',
|
|
156
|
+
'turquoise',
|
|
157
|
+
'violet',
|
|
158
|
+
'wheat',
|
|
159
|
+
'white',
|
|
160
|
+
'whitesmoke',
|
|
161
|
+
'yellow',
|
|
162
|
+
'yellowgreen',
|
|
163
|
+
]);
|
|
164
|
+
// Turns the nested palette (`blue: { 500: … }`) into class-style names (`blue-500`). `DEFAULT` is the
|
|
165
|
+
// shade used when none is written, so it becomes plain `blue`.
|
|
166
|
+
function flattenColorNames(colors) {
|
|
167
|
+
const names = new Set();
|
|
168
|
+
for (const [family, value] of Object.entries(colors)) {
|
|
169
|
+
if (typeof value === 'string') {
|
|
170
|
+
names.add(family);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
for (const shade of Object.keys(value)) {
|
|
174
|
+
names.add(shade === 'DEFAULT' ? family : `${family}-${shade}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return names;
|
|
178
|
+
}
|
|
179
|
+
const ALLOWED_COLORS = flattenColorNames(tacoColors);
|
|
180
|
+
// Color names we recognize (`blue`, `orange`…). Prefixes like `text-` also set sizes, so a class only
|
|
181
|
+
// counts as a color when it uses one of these names; `text-sm` and `border-2` are left alone.
|
|
182
|
+
// Tailwind's own names are included so colors taco doesn't offer (`orange`) are still caught.
|
|
183
|
+
const COLOR_FAMILIES = new Set([...[...ALLOWED_COLORS].map(name => name.split('-')[0]), ...Object.keys(tailwindDefaultColors)]);
|
|
184
|
+
/**
|
|
185
|
+
* Whether a single class is a color utility whose color isn't defined in taco's tailwind.theme.colors.js.
|
|
186
|
+
* The theme replaces Tailwind's palette, so such classes generate no CSS.
|
|
187
|
+
*/
|
|
188
|
+
export function isUndefinedThemeColor(className) {
|
|
189
|
+
// Opacity doesn't change the color (`bg-blue-500/50` is still blue-500), so it's cut off.
|
|
190
|
+
// Custom `[…]` values aren't judged here.
|
|
191
|
+
const color = COLOR_UTILITY.exec(stripVariants(className))?.[1]?.replace(/\/(?:\d+|\[[^\]]+\])$/u, '');
|
|
192
|
+
if (color === undefined || color.startsWith('['))
|
|
193
|
+
return false;
|
|
194
|
+
return COLOR_FAMILIES.has(color.split('-')[0] ?? '') && !ALLOWED_COLORS.has(color);
|
|
195
|
+
}
|
|
196
|
+
/** Whether a single class is an arbitrary `text-[…]` / `bg-[…]` color literal. */
|
|
197
|
+
export function isArbitraryColor(className) {
|
|
198
|
+
const inner = ARBITRARY_TEXT_BG.exec(stripVariants(className))?.[1]?.trim();
|
|
199
|
+
return inner !== undefined && (COLOR_VALUE.test(inner) || NAMED_COLORS.has(inner.toLowerCase()));
|
|
200
|
+
}
|
|
201
|
+
export function checkColorClass(className) {
|
|
202
|
+
if (isUndefinedThemeColor(className) || isArbitraryColor(className)) {
|
|
203
|
+
return `Unexpected class "${className}" - instead use a color defined by Taco.`;
|
|
204
|
+
}
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
// Only hex-valued variables are colors; spacing, radius etc. share the `--taco-` prefix.
|
|
208
|
+
export const COLOR_VARIABLES = new Set([...tacoCssVariables].filter(([, value]) => /^#[0-9a-f]{3,8}$/iu.test(value)).map(([name]) => name));
|
|
209
|
+
// `background` is included because its shorthand is the most common way a raw color slips in.
|
|
210
|
+
const COLOR_PROPERTY = /^(?:color|background(?:-color|-image)?|border(?:-(?:top|right|bottom|left|inline|block)(?:-(?:start|end))?)?-color|outline-color|fill|stroke|caret-color|accent-color|text-decoration-color|column-rule-color)$/iu;
|
|
211
|
+
// Checks a variable that a color property's value refers to (`color: var(--taco-blue-500)`). Variables
|
|
212
|
+
// outside taco are left alone: raw colors in their definitions are caught there.
|
|
213
|
+
export function checkColorVariable(property, name) {
|
|
214
|
+
if (!COLOR_PROPERTY.test(property) || !name.startsWith('--taco-') || COLOR_VARIABLES.has(name))
|
|
215
|
+
return undefined;
|
|
216
|
+
return `Unknown Taco color "${name}" - please use a color variable from tokens.css or a theme() token.`;
|
|
217
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const ALLOWED_RADIUS_CLASSES: string[];
|
|
2
|
+
export declare function checkRadiusClass(className: string): string | undefined;
|
|
3
|
+
export declare const ALLOWED_RADIUS_VARIABLES: string[];
|
|
4
|
+
export declare function checkRadiusDeclaration(property: string, value: string): string | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { orList, stripVariants } from "./classes.js";
|
|
2
|
+
import { CSS_WIDE_KEYWORDS, tacoCssVariables, tacoRadius } from "./theme.js";
|
|
3
|
+
// Reads `rounded`, an optional side or corner (`-t`, `-tl`…) and an optional size (`-lg`), and picks
|
|
4
|
+
// out the size. Two-letter corners are tried first so `rounded-se` reads as a corner, yet
|
|
5
|
+
// `rounded-sm` still reads as size `sm`.
|
|
6
|
+
const RADIUS_UTILITY = /^rounded(?:-(?:ss|se|es|ee|tl|tr|br|bl|t|r|b|l|s|e))?(?:-(.+))?$/u;
|
|
7
|
+
const SIZES = new Set(Object.keys(tacoRadius));
|
|
8
|
+
export const ALLOWED_RADIUS_CLASSES = [...SIZES].map(size => (size === 'DEFAULT' ? 'rounded' : `rounded-${size}`));
|
|
9
|
+
// Lists what's allowed rather than what's banned: every `rounded-*` class sets corner rounding, so
|
|
10
|
+
// any size taco doesn't define — including custom `rounded-[…]` — is rejected.
|
|
11
|
+
export function checkRadiusClass(className) {
|
|
12
|
+
const match = RADIUS_UTILITY.exec(stripVariants(className));
|
|
13
|
+
if (match === null)
|
|
14
|
+
return undefined;
|
|
15
|
+
const size = match[1];
|
|
16
|
+
// No size (`rounded`) means the default size. `DEFAULT` is only an internal name, so `rounded-DEFAULT` isn't valid.
|
|
17
|
+
if (size === undefined ? SIZES.has('DEFAULT') : SIZES.has(size) && size !== 'DEFAULT')
|
|
18
|
+
return undefined;
|
|
19
|
+
return `Unexpected class "${className}" - instead use ${orList(ALLOWED_RADIUS_CLASSES)}.`;
|
|
20
|
+
}
|
|
21
|
+
// Raw CSS is only checked on the shorthand and its four physical corners.
|
|
22
|
+
const RADIUS_PROPERTY = /^border(?:-top-left|-top-right|-bottom-right|-bottom-left)?-radius$/u;
|
|
23
|
+
export const ALLOWED_RADIUS_VARIABLES = [...tacoCssVariables.keys()].filter(name => name.startsWith('--taco-radius-'));
|
|
24
|
+
const ALLOWED_VALUES = new Set([...ALLOWED_RADIUS_VARIABLES.map(name => `var(${name})`), ...CSS_WIDE_KEYWORDS]);
|
|
25
|
+
// The whole value must be one taco radius variable, so lengths, several corners at once and theme() are rejected.
|
|
26
|
+
export function checkRadiusDeclaration(property, value) {
|
|
27
|
+
if (!RADIUS_PROPERTY.test(property) || value === '' || ALLOWED_VALUES.has(value))
|
|
28
|
+
return undefined;
|
|
29
|
+
return 'Unexpected custom value - please use a Taco CSS variable or theme() token.';
|
|
30
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { orList, stripVariants } from "./classes.js";
|
|
2
|
+
import { tacoShadow, tailwindDefaultTheme } from "./theme.js";
|
|
3
|
+
const SHADOW_UTILITY = /^shadow(?:-(.+))?$/u;
|
|
4
|
+
// `shadow-*` sets both shadow size and shadow color (`shadow-blue-500`); colors are the color rule's
|
|
5
|
+
// job. So only size-like values are judged: Tailwind's own sizes plus any t-shirt size (xs, sm, md,
|
|
6
|
+
// lg, xl, 2xl…).
|
|
7
|
+
const SIZE_WORD = /^(?:\d*x[sl]|sm|md|lg)$/u;
|
|
8
|
+
const SIZES = new Set(Object.keys(tacoShadow));
|
|
9
|
+
const KNOWN_SIZES = new Set([...Object.keys(tailwindDefaultTheme.boxShadow), ...SIZES]);
|
|
10
|
+
export const ALLOWED_SHADOW_CLASSES = [...SIZES].map(size => (size === 'DEFAULT' ? 'shadow' : `shadow-${size}`));
|
|
11
|
+
export function checkShadowClass(className) {
|
|
12
|
+
const match = SHADOW_UTILITY.exec(stripVariants(className));
|
|
13
|
+
if (match === null)
|
|
14
|
+
return undefined;
|
|
15
|
+
const size = match[1];
|
|
16
|
+
// No size (`shadow`) means the default size. `DEFAULT` is only an internal name, so `shadow-DEFAULT` isn't valid.
|
|
17
|
+
if (size === undefined ? SIZES.has('DEFAULT') : SIZES.has(size) && size !== 'DEFAULT')
|
|
18
|
+
return undefined;
|
|
19
|
+
// Not a size (e.g. a color), so not this rule's business.
|
|
20
|
+
if (size !== undefined && !size.startsWith('[') && !KNOWN_SIZES.has(size) && !SIZE_WORD.test(size))
|
|
21
|
+
return undefined;
|
|
22
|
+
return `Unexpected class "${className}" - instead use ${orList(ALLOWED_SHADOW_CLASSES)}.`;
|
|
23
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const ALLOWED_SPACING_VALUES: string[];
|
|
2
|
+
export declare function checkSpacingClass(className: string): string | undefined;
|
|
3
|
+
export declare const ALLOWED_SPACING_VARIABLES: string[];
|
|
4
|
+
export declare function checkSpacingDeclaration(property: string, value: string): string | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { orList, stripVariants } from "./classes.js";
|
|
2
|
+
import { CSS_WIDE_KEYWORDS, tacoCssVariables, tacoSpacing } from "./theme.js";
|
|
3
|
+
// Finds padding (`p-`), margin (`m-`), `gap-` and `space-` classes — incl. one side (`pt-`, `mx-`)
|
|
4
|
+
// and negative margins (`-mt-2`) — and picks out the size. Only numbers, `px` and custom `[…]`
|
|
5
|
+
// values are judged, so margin `auto` and the theme's named sizes (used by max-w etc.) pass.
|
|
6
|
+
const SPACING_UTILITY = /^-?(?:p[xytrblse]?|m[xytrblse]?|gap(?:-[xy])?|space-[xy])-(\d+(?:\.\d+)?|px|\[[^\]]+\])$/u;
|
|
7
|
+
// Token names match Tailwind's numbers (`tacoSpacing4` = 16px = Tailwind's `4`), so the number in
|
|
8
|
+
// each name is an allowed value. Sorted as numbers so the message reads 0, 1, 2 … 12.
|
|
9
|
+
export const ALLOWED_SPACING_VALUES = Object.keys(tacoSpacing)
|
|
10
|
+
.map(key => key.replace(/^tacoSpacing/u, ''))
|
|
11
|
+
.sort((a, b) => Number(a) - Number(b));
|
|
12
|
+
const ALLOWED = new Set(ALLOWED_SPACING_VALUES);
|
|
13
|
+
export function checkSpacingClass(className) {
|
|
14
|
+
const size = SPACING_UTILITY.exec(stripVariants(className))?.[1];
|
|
15
|
+
if (size === undefined || ALLOWED.has(size))
|
|
16
|
+
return undefined;
|
|
17
|
+
return `Unexpected class "${className}" - instead use a Taco spacing token: ${orList(ALLOWED_SPACING_VALUES)}.`;
|
|
18
|
+
}
|
|
19
|
+
// Raw CSS (`padding: 6px`) is the declaration-level equivalent of an off-token class.
|
|
20
|
+
const SPACING_PROPERTY = /^(?:padding|margin)(?:-(?:top|right|bottom|left|inline|block)(?:-(?:start|end))?)?$|^(?:gap|row-gap|column-gap)$/u;
|
|
21
|
+
export const ALLOWED_SPACING_VARIABLES = [...tacoCssVariables.keys()].filter(name => name.startsWith('--taco-spacing-'));
|
|
22
|
+
const ALLOWED_PARTS = new Set([...ALLOWED_SPACING_VARIABLES.map(name => `var(${name})`), 'auto', ...CSS_WIDE_KEYWORDS]);
|
|
23
|
+
// Zero and percentages aren't choices on the spacing scale, so they stay allowed.
|
|
24
|
+
const ZERO_OR_PERCENT = /^(?:0[a-z%]*|-?\d*\.?\d+%)$/u;
|
|
25
|
+
export function checkSpacingDeclaration(property, value) {
|
|
26
|
+
if (!SPACING_PROPERTY.test(property))
|
|
27
|
+
return undefined;
|
|
28
|
+
const parts = value.trim().split(/\s+/u);
|
|
29
|
+
if (parts.every(part => ALLOWED_PARTS.has(part) || ZERO_OR_PERCENT.test(part)))
|
|
30
|
+
return undefined;
|
|
31
|
+
return `Unexpected value "${value}" for "${property}" - please use a Taco spacing variable (var(--taco-spacing-*)).`;
|
|
32
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { borderRadius as tacoRadius, boxShadow as tacoShadow, colors as tacoColors } from '@economic/taco/tailwind.theme.js';
|
|
2
|
+
export { spacing as tacoSpacing } from '@economic/taco-tokens/tokens';
|
|
3
|
+
export declare const tacoCssVariables: ReadonlyMap<string, string>;
|
|
4
|
+
export { default as tailwindDefaultColors } from 'tailwindcss/colors.js';
|
|
5
|
+
export { default as tailwindDefaultTheme } from 'tailwindcss/defaultTheme.js';
|
|
6
|
+
export declare const CSS_WIDE_KEYWORDS: readonly string[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
// Every value the policies use comes from here, so no family hand-writes a list.
|
|
3
|
+
// Taco: what each family allows. Read from the installed `@economic/taco`, so the rules follow that version.
|
|
4
|
+
export { borderRadius as tacoRadius, boxShadow as tacoShadow, colors as tacoColors } from '@economic/taco/tailwind.theme.js';
|
|
5
|
+
export { spacing as tacoSpacing } from '@economic/taco-tokens/tokens';
|
|
6
|
+
// Raw CSS references tokens by variable name (`var(--taco-radius-4)`), so CSS values are checked against
|
|
7
|
+
// the variables in tokens.css (name → value).
|
|
8
|
+
export const tacoCssVariables = new Map(Array.from(readFileSync(new URL(import.meta.resolve('@economic/taco-tokens/tokens.css')), 'utf8').matchAll(/(--taco-[a-z0-9-]+)\s*:\s*([^;]+);/giu), match => [match[1] ?? '', match[2]?.trim() ?? '']));
|
|
9
|
+
// Tailwind: never allowed. Only tells which classes belong to a family (`bg-orange-500` is a color,
|
|
10
|
+
// `shadow-2xl` a shadow), so they're flagged rather than ignored.
|
|
11
|
+
export { default as tailwindDefaultColors } from 'tailwindcss/colors.js';
|
|
12
|
+
export { default as tailwindDefaultTheme } from 'tailwindcss/defaultTheme.js';
|
|
13
|
+
// CSS: keywords that hand the value to the cascade instead of choosing one, so every CSS value check allows them.
|
|
14
|
+
export const CSS_WIDE_KEYWORDS = ['inherit', 'initial', 'unset', 'revert', 'revert-layer'];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { COLOR_FUNCTIONS } from "../policies/color.js";
|
|
2
|
+
import colorToken from "./rules/color-token/color-token.js";
|
|
3
|
+
import colorValue from "./rules/color-value/color-value.js";
|
|
4
|
+
import radius from "./rules/radius/radius.js";
|
|
5
|
+
import shadow from "./rules/shadow/shadow.js";
|
|
6
|
+
import spacing from "./rules/spacing/spacing.js";
|
|
7
|
+
// The Stylelint config for the policies. Consumers import it and override single rules: `null` turns a
|
|
8
|
+
// rule off, `[true, { severity: 'warning' }]` changes its severity.
|
|
9
|
+
const config = {
|
|
10
|
+
plugins: [colorToken, colorValue, radius, shadow, spacing],
|
|
11
|
+
rules: {
|
|
12
|
+
'@economic/color-token': true,
|
|
13
|
+
'@economic/color-value': true,
|
|
14
|
+
'@economic/radius': true,
|
|
15
|
+
'@economic/shadow': true,
|
|
16
|
+
// taco-internal, consumers keep the full Tailwind spacing scale; off until taco's spacing migration starts
|
|
17
|
+
'@economic/spacing': null,
|
|
18
|
+
// Raw color literals on every property, incl. shorthands and custom property definitions.
|
|
19
|
+
// @economic/color-value only checks that taco color variables exist.
|
|
20
|
+
'color-no-hex': [
|
|
21
|
+
true,
|
|
22
|
+
{ message: (hex) => `Unexpected hex color "${hex}" - please use a Taco CSS variable or theme() token.` },
|
|
23
|
+
],
|
|
24
|
+
'color-named': [
|
|
25
|
+
'never',
|
|
26
|
+
{ message: (name) => `Unexpected named color "${name}" - please use a Taco CSS variable or theme() token.` },
|
|
27
|
+
],
|
|
28
|
+
'function-disallowed-list': [
|
|
29
|
+
COLOR_FUNCTIONS,
|
|
30
|
+
{
|
|
31
|
+
message: (name) => `Unexpected color function "${name}" - please use a Taco CSS variable or theme() token.`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
export default config;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Node, Root } from 'postcss';
|
|
2
|
+
import type { Plugin } from 'stylelint';
|
|
3
|
+
import type { ClassCheck } from '../../policies/classes.ts';
|
|
4
|
+
export type DeclarationCheck = (property: string, value: string) => string | undefined;
|
|
5
|
+
type Report = (message: string, node: Node, index: number, endIndex: number) => void;
|
|
6
|
+
/** What every taco Stylelint rule shares: option handling, the `(ruleName)` message suffix and reporting. */
|
|
7
|
+
export declare function createPlugin(ruleName: string, lint: (root: Root, report: Report) => void): Plugin;
|
|
8
|
+
/**
|
|
9
|
+
* Connects policy checks to Stylelint: classes in selectors and `@apply` go to `checkClass`, and
|
|
10
|
+
* declarations to `checkDeclaration`. Unlike oxlint, every violation is reported at its own position.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createPolicyPlugin(ruleName: string, { checkClass, checkDeclaration }: {
|
|
13
|
+
checkClass?: ClassCheck;
|
|
14
|
+
checkDeclaration?: DeclarationCheck;
|
|
15
|
+
}): Plugin;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import stylelint from 'stylelint';
|
|
2
|
+
import { walkClasses, walkDeclarations } from "./walk-css-sources.js";
|
|
3
|
+
/** What every taco Stylelint rule shares: option handling, the `(ruleName)` message suffix and reporting. */
|
|
4
|
+
export function createPlugin(ruleName, lint) {
|
|
5
|
+
const messages = stylelint.utils.ruleMessages(ruleName, { rejected: (message) => message });
|
|
6
|
+
const rule = Object.assign((primaryOption) => (root, result) => {
|
|
7
|
+
if (!stylelint.utils.validateOptions(result, ruleName, { actual: primaryOption }) || !primaryOption)
|
|
8
|
+
return;
|
|
9
|
+
lint(root, (message, node, index, endIndex) => {
|
|
10
|
+
stylelint.utils.report({ result, ruleName, message: messages.rejected(message), node, index, endIndex });
|
|
11
|
+
});
|
|
12
|
+
}, { ruleName, messages });
|
|
13
|
+
return stylelint.createPlugin(ruleName, rule);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Connects policy checks to Stylelint: classes in selectors and `@apply` go to `checkClass`, and
|
|
17
|
+
* declarations to `checkDeclaration`. Unlike oxlint, every violation is reported at its own position.
|
|
18
|
+
*/
|
|
19
|
+
export function createPolicyPlugin(ruleName, { checkClass, checkDeclaration }) {
|
|
20
|
+
return createPlugin(ruleName, (root, report) => {
|
|
21
|
+
if (checkClass !== undefined) {
|
|
22
|
+
walkClasses(root, ({ className, node, index, endIndex }) => {
|
|
23
|
+
const message = checkClass(className);
|
|
24
|
+
if (message !== undefined)
|
|
25
|
+
report(message, node, index, endIndex);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (checkDeclaration !== undefined) {
|
|
29
|
+
walkDeclarations(root, (node, valueIndex) => {
|
|
30
|
+
const message = checkDeclaration(node.prop, node.value);
|
|
31
|
+
if (message !== undefined)
|
|
32
|
+
report(message, node, valueIndex, valueIndex + node.value.length);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AtRule, Declaration, Root, Rule } from 'postcss';
|
|
2
|
+
export interface CssClass {
|
|
3
|
+
className: string;
|
|
4
|
+
node: AtRule | Rule;
|
|
5
|
+
index: number;
|
|
6
|
+
endIndex: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Visits every class CSS can hold, with its position in `node`: class selectors (escapes resolved)
|
|
10
|
+
* and Tailwind `@apply` params. Comments and declaration values are skipped, so class-like text in
|
|
11
|
+
* them isn't flagged.
|
|
12
|
+
*/
|
|
13
|
+
export declare function walkClasses(root: Root, visit: (found: CssClass) => void): void;
|
|
14
|
+
/** Visits every declaration with the position its value starts at in `node`. */
|
|
15
|
+
export declare function walkDeclarations(root: Root, visit: (node: Declaration, valueIndex: number) => void): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { splitClasses } from "../../policies/classes.js";
|
|
2
|
+
// Selector class names escape Tailwind syntax (`.hover\:bg-blue-500`), so capture escapes too.
|
|
3
|
+
const SELECTOR_CLASS = /\.((?:\\.|[\w-])+)/gu;
|
|
4
|
+
/**
|
|
5
|
+
* Visits every class CSS can hold, with its position in `node`: class selectors (escapes resolved)
|
|
6
|
+
* and Tailwind `@apply` params. Comments and declaration values are skipped, so class-like text in
|
|
7
|
+
* them isn't flagged.
|
|
8
|
+
*/
|
|
9
|
+
export function walkClasses(root, visit) {
|
|
10
|
+
root.walkRules(node => {
|
|
11
|
+
for (const match of node.selector.matchAll(SELECTOR_CLASS)) {
|
|
12
|
+
const className = (match[1] ?? '').replaceAll(/\\(.)/gu, '$1');
|
|
13
|
+
visit({ className, node, index: match.index, endIndex: match.index + match[0].length });
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
root.walkAtRules('apply', node => {
|
|
17
|
+
const paramsIndex = Math.max(node.toString().indexOf(node.params), 0);
|
|
18
|
+
for (const { className, index } of splitClasses(node.params)) {
|
|
19
|
+
visit({ className, node, index: paramsIndex + index, endIndex: paramsIndex + index + className.length });
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** Visits every declaration with the position its value starts at in `node`. */
|
|
24
|
+
export function walkDeclarations(root, visit) {
|
|
25
|
+
root.walkDecls(node => {
|
|
26
|
+
visit(node, node.prop.length + (node.raws.between ?? ':').length);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { checkColorClass } from "../../../policies/color.js";
|
|
2
|
+
import { createPolicyPlugin } from "../../lib/create-policy-plugin.js";
|
|
3
|
+
// CSS counterpart of `taco/no-disallowed-color-classes`. Matching lives in `src/policies/color.ts`.
|
|
4
|
+
export default createPolicyPlugin('@economic/color-token', { checkClass: checkColorClass });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import valueParser from 'postcss-value-parser';
|
|
2
|
+
import { checkColorVariable } from "../../../policies/color.js";
|
|
3
|
+
import { createPlugin } from "../../lib/create-policy-plugin.js";
|
|
4
|
+
import { walkDeclarations } from "../../lib/walk-css-sources.js";
|
|
5
|
+
// Checks the `var(--taco-*)` references in color values, including nested ones (gradient stops,
|
|
6
|
+
// `var()` fallbacks). Raw literals are left to color-no-hex, color-named and function-disallowed-list,
|
|
7
|
+
// which cover every property. Matching lives in `src/policies/color.ts`.
|
|
8
|
+
export default createPlugin('@economic/color-value', (root, report) => {
|
|
9
|
+
walkDeclarations(root, (node, valueIndex) => {
|
|
10
|
+
valueParser(node.value).walk(valueNode => {
|
|
11
|
+
if (valueNode.type !== 'function' || valueNode.value.toLowerCase() !== 'var')
|
|
12
|
+
return;
|
|
13
|
+
const message = checkColorVariable(node.prop, valueNode.nodes[0]?.value ?? '');
|
|
14
|
+
if (message !== undefined) {
|
|
15
|
+
report(message, node, valueIndex + valueNode.sourceIndex, valueIndex + valueNode.sourceEndIndex);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { checkRadiusClass, checkRadiusDeclaration } from "../../../policies/radius.js";
|
|
2
|
+
import { createPolicyPlugin } from "../../lib/create-policy-plugin.js";
|
|
3
|
+
// CSS counterpart of `taco/no-disallowed-radius-classes`, plus raw `border-radius` values. Matching
|
|
4
|
+
// lives in `src/policies/radius.ts`.
|
|
5
|
+
export default createPolicyPlugin('@economic/radius', {
|
|
6
|
+
checkClass: checkRadiusClass,
|
|
7
|
+
checkDeclaration: checkRadiusDeclaration,
|
|
8
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { checkShadowClass } from "../../../policies/shadow.js";
|
|
2
|
+
import { createPolicyPlugin } from "../../lib/create-policy-plugin.js";
|
|
3
|
+
// CSS counterpart of `taco/no-disallowed-shadow-classes`. Matching lives in `src/policies/shadow.ts`.
|
|
4
|
+
export default createPolicyPlugin('@economic/shadow', { checkClass: checkShadowClass });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { checkSpacingClass, checkSpacingDeclaration } from "../../../policies/spacing.js";
|
|
2
|
+
import { createPolicyPlugin } from "../../lib/create-policy-plugin.js";
|
|
3
|
+
// CSS counterpart of `taco/no-disallowed-spacing-classes`, plus raw padding/margin/gap values.
|
|
4
|
+
// Matching lives in `src/policies/spacing.ts`.
|
|
5
|
+
export default createPolicyPlugin('@economic/spacing', {
|
|
6
|
+
checkClass: checkSpacingClass,
|
|
7
|
+
checkDeclaration: checkSpacingDeclaration,
|
|
8
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jsPlugins": [
|
|
3
|
+
"@economic/taco-rules"
|
|
4
|
+
],
|
|
5
|
+
"rules": {
|
|
6
|
+
"taco/no-disallowed-color-classes": "error",
|
|
7
|
+
"taco/no-disallowed-radius-classes": "error",
|
|
8
|
+
"taco/no-disallowed-shadow-classes": "error",
|
|
9
|
+
"taco/no-disallowed-spacing-classes": "off"
|
|
10
|
+
}
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@economic/taco-rules",
|
|
3
|
+
"version": "2.0.0-EC-00123-table3-bundle.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"description": "Linting rules for the Taco design system: oxlint/ESLint rules and the policies they share",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/oxlint/index.js",
|
|
11
|
+
"types": "./dist/oxlint/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/oxlint/index.d.ts",
|
|
15
|
+
"default": "./dist/oxlint/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./stylelint": {
|
|
18
|
+
"types": "./dist/stylelint/index.d.ts",
|
|
19
|
+
"default": "./dist/stylelint/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./oxlint/styles.json": "./oxlint/styles.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"oxlint",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.build.json && node scripts/build-oxlint-preset.ts",
|
|
30
|
+
"prebuild": "rm -rf dist oxlint",
|
|
31
|
+
"prepare": "npm run build",
|
|
32
|
+
"test": "vitest run --passWithNoTests",
|
|
33
|
+
"test:watch": "vitest --watch --passWithNoTests",
|
|
34
|
+
"typecheck": "npx tsc --noEmit"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@economic/taco-tokens": "4.0.0-EC-00123-table3-bundle.0",
|
|
38
|
+
"@oxlint/plugins": "^1.72.0",
|
|
39
|
+
"postcss-value-parser": "^4.2.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@economic/taco": "*",
|
|
43
|
+
"eslint": "^9.0.0 || ^10.0.0",
|
|
44
|
+
"oxlint": "^1.72.0",
|
|
45
|
+
"stylelint": "^17.0.0",
|
|
46
|
+
"tailwindcss": ">=3.4.19"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"eslint": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"oxlint": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"stylelint": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/node": "^22.20.5",
|
|
61
|
+
"eslint": "^9.39.5",
|
|
62
|
+
"postcss": "^8.5.26",
|
|
63
|
+
"stylelint": "^17.16.0",
|
|
64
|
+
"typescript": "^5.9.3",
|
|
65
|
+
"vitest": "^4.1.12"
|
|
66
|
+
},
|
|
67
|
+
"gitHead": "8d442daeb5931282894ca564268bb3f066b60202"
|
|
68
|
+
}
|