@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
package/README.md
CHANGED
|
@@ -1,3 +1,427 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@economic/taco-rules` — Taco's lint rules
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Taco's lint rules, for apps using Taco and for Taco itself:
|
|
4
|
+
|
|
5
|
+
- an oxlint JS plugin (`taco`) that lints TS/TSX source files, plus a `styles`
|
|
6
|
+
preset with its class rules;
|
|
7
|
+
- a Stylelint config with the matching `@economic/*` plugins for CSS files.
|
|
8
|
+
|
|
9
|
+
The class rules of both linters are thin adapters over one policy per family in
|
|
10
|
+
[`src/policies/`](https://github.com/e-conomic/taco/blob/main/packages/taco-rules/src/policies/). Allowed values come from Taco's Tailwind theme
|
|
11
|
+
and `@economic/taco-tokens`, never from hand-written lists, so both linters
|
|
12
|
+
accept exactly the same classes once a rule is on (enforced by
|
|
13
|
+
[`src/parity.test.ts`](https://github.com/e-conomic/taco/blob/main/packages/taco-rules/src/parity.test.ts)).
|
|
14
|
+
|
|
15
|
+
| Family | oxlint (TS/TSX) | Stylelint (CSS) | Policy |
|
|
16
|
+
| ------- | ------------------------------------------ | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| color | `taco/no-disallowed-color-classes` | `@economic/color-token`, `@economic/color-value` | [`color.ts`](https://github.com/e-conomic/taco/blob/main/packages/taco-rules/src/policies/color.ts) |
|
|
18
|
+
| radius | `taco/no-disallowed-radius-classes` | `@economic/radius` | [`radius.ts`](https://github.com/e-conomic/taco/blob/main/packages/taco-rules/src/policies/radius.ts) |
|
|
19
|
+
| shadow | `taco/no-disallowed-shadow-classes` | `@economic/shadow` | [`shadow.ts`](https://github.com/e-conomic/taco/blob/main/packages/taco-rules/src/policies/shadow.ts) |
|
|
20
|
+
| spacing | `taco/no-disallowed-spacing-classes` (off) | `@economic/spacing` (off) | [`spacing.ts`](https://github.com/e-conomic/taco/blob/main/packages/taco-rules/src/policies/spacing.ts) |
|
|
21
|
+
|
|
22
|
+
```mermaid
|
|
23
|
+
flowchart LR
|
|
24
|
+
subgraph values["Allowed values, never hand-written"]
|
|
25
|
+
theme["@economic/taco<br/>tailwind.theme.js"]
|
|
26
|
+
tokens["@economic/taco-tokens<br/>tokens.css, spacing"]
|
|
27
|
+
tailwind["tailwindcss defaults<br/>only to recognise a family"]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
subgraph package["@economic/taco-rules"]
|
|
31
|
+
policies["src/policies/<br/>color, radius, shadow, spacing"]
|
|
32
|
+
oxlintRules["src/oxlint/rules/<br/>taco/no-disallowed-*"]
|
|
33
|
+
stylelintRules["src/stylelint/rules/<br/>@economic/*"]
|
|
34
|
+
preset["src/oxlint/configs/styles.ts<br/>which rules are on"]
|
|
35
|
+
stylelintConfig["src/stylelint/index.ts<br/>which rules are on"]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
theme --> policies
|
|
39
|
+
tokens --> policies
|
|
40
|
+
tailwind --> policies
|
|
41
|
+
policies --> oxlintRules --> preset
|
|
42
|
+
policies --> stylelintRules --> stylelintConfig
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
Install the package and the linters you use. The linters are optional peer
|
|
48
|
+
dependencies, so npm doesn't install them for you:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
npm install --save-dev @economic/taco-rules
|
|
52
|
+
npm install --save-dev stylelint # for CSS files
|
|
53
|
+
npm install --save-dev oxlint # for TS/TSX files
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The rules read the allowed values from the `@economic/taco` installed in your
|
|
57
|
+
app, so they follow your Taco version. Your app needs `@economic/taco` and
|
|
58
|
+
`tailwindcss` v3 installed, which apps using Taco already have.
|
|
59
|
+
|
|
60
|
+
Supported versions: `stylelint` 17, `oxlint` 1.72 or later.
|
|
61
|
+
|
|
62
|
+
## Using the configs
|
|
63
|
+
|
|
64
|
+
Consumers extend the shipped configs and override single rules, to turn them
|
|
65
|
+
off or change their severity. Change a policy here, not a consumer's config, to
|
|
66
|
+
change what a rule allows.
|
|
67
|
+
|
|
68
|
+
Each linter is switched on individually, so a family of rules can be on for CSS and off for
|
|
69
|
+
TS/TSX (or the other way round), e.g. to clean up one file type first before turning on the ruleset.
|
|
70
|
+
Both linters also take `overrides` with `files` globs, to switch a rule for some
|
|
71
|
+
folders only.
|
|
72
|
+
|
|
73
|
+
### oxlint
|
|
74
|
+
|
|
75
|
+
The preset loads the plugin by package name. The other `taco/*` rules need it
|
|
76
|
+
in `jsPlugins` too.
|
|
77
|
+
|
|
78
|
+
In `oxlint.config.ts`, import the preset by package name:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { defineConfig } from 'oxlint';
|
|
82
|
+
import taco from '@economic/taco-rules';
|
|
83
|
+
|
|
84
|
+
export default defineConfig({
|
|
85
|
+
extends: [taco.configs.styles],
|
|
86
|
+
rules: {
|
|
87
|
+
'taco/no-disallowed-radius-classes': 'warn', // change severity
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`.oxlintrc.json` can only `extends` a file path, relative to the config file.
|
|
93
|
+
The package ships the preset as JSON at a fixed path for that:
|
|
94
|
+
|
|
95
|
+
```jsonc
|
|
96
|
+
{
|
|
97
|
+
"extends": ["./node_modules/@economic/taco-rules/oxlint/styles.json"],
|
|
98
|
+
"jsPlugins": ["@economic/taco-rules"],
|
|
99
|
+
"rules": {
|
|
100
|
+
"taco/no-disallowed-radius-classes": "warn", // change severity
|
|
101
|
+
"taco/no-disallowed-shadow-classes": "off", // turn off
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`packages/taco` extends the preset in two configs:
|
|
107
|
+
|
|
108
|
+
- [`packages/taco/.oxlintrc.classes.json`](https://github.com/e-conomic/taco/blob/main/packages/taco/.oxlintrc.classes.json) —
|
|
109
|
+
only the `taco/*` class rules, run by `npm run lint:classes` and the
|
|
110
|
+
`nano-staged` pre-commit hook with `--disable-*-plugin` flags, so only the
|
|
111
|
+
`taco/*` rules emit diagnostics.
|
|
112
|
+
- [`packages/taco/.oxlintrc.json`](https://github.com/e-conomic/taco/blob/main/packages/taco/.oxlintrc.json) — the main config,
|
|
113
|
+
run by `npm run lint` and the editor (oxc language server).
|
|
114
|
+
|
|
115
|
+
### Stylelint
|
|
116
|
+
|
|
117
|
+
Import the config and spread it:
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
import config from '@economic/taco-rules/stylelint';
|
|
121
|
+
|
|
122
|
+
export default {
|
|
123
|
+
...config,
|
|
124
|
+
rules: {
|
|
125
|
+
...config.rules,
|
|
126
|
+
'@economic/radius': [true, { severity: 'warning' }], // change severity
|
|
127
|
+
'@economic/shadow': null, // turn off
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
[`packages/taco/stylelint.config.mjs`](https://github.com/e-conomic/taco/blob/main/packages/taco/stylelint.config.mjs) does that
|
|
133
|
+
for `npm run lint:styles`, the `nano-staged` pre-commit hook and the editor
|
|
134
|
+
(Stylelint extension).
|
|
135
|
+
|
|
136
|
+
The plugins read classes from class selectors (escapes resolved, so
|
|
137
|
+
`.hover\:bg-blue-500` is `hover:bg-blue-500`) and `@apply` params; comments and
|
|
138
|
+
other declaration values are skipped. Unlike oxlint, which reports the first bad
|
|
139
|
+
class per string, Stylelint reports each one.
|
|
140
|
+
|
|
141
|
+
- `@economic/color-token` — classes, as `taco/no-disallowed-color-classes`.
|
|
142
|
+
- `@economic/color-value` — `var(--taco-*)` references in color properties,
|
|
143
|
+
incl. gradient stops and `var()` fallbacks, must be color variables from
|
|
144
|
+
`tokens.css`. Raw literals are left to Stylelint's `color-no-hex`,
|
|
145
|
+
`color-named` and `function-disallowed-list` (with the color functions from
|
|
146
|
+
`src/policies/color.ts`), which the config also turns on for every property.
|
|
147
|
+
- `@economic/radius` — classes, as `taco/no-disallowed-radius-classes`.
|
|
148
|
+
`border-radius` and its four physical corner properties must be exactly one
|
|
149
|
+
`var(--taco-radius-*)` from `tokens.css` or a CSS-wide keyword.
|
|
150
|
+
- `@economic/shadow` — classes, as `taco/no-disallowed-shadow-classes`.
|
|
151
|
+
- `@economic/spacing` — off. Classes, as `taco/no-disallowed-spacing-classes`.
|
|
152
|
+
`padding`, `margin` and `gap` values must use `var(--taco-spacing-*)` from
|
|
153
|
+
`tokens.css`; zero, percentages, `auto` and CSS-wide keywords pass.
|
|
154
|
+
|
|
155
|
+
## Rules
|
|
156
|
+
|
|
157
|
+
### `taco/consistent-clsx-import`
|
|
158
|
+
|
|
159
|
+
Part of the `recommended` config. Enforces the single canonical way of
|
|
160
|
+
importing clsx:
|
|
161
|
+
`import cn from 'clsx';`. Flags the default import under any other name, named
|
|
162
|
+
imports (`{ clsx }`), and namespace imports.
|
|
163
|
+
|
|
164
|
+
Auto-fixable (`fixable: 'code'`): rewrites the import to the canonical form and
|
|
165
|
+
renames every reference to `cn` — unless the import uses a namespace specifier
|
|
166
|
+
or another `cn` binding already exists in the file, where the rename could
|
|
167
|
+
shadow or collide; those cases are reported without a fix.
|
|
168
|
+
|
|
169
|
+
### `taco/data-taco-kebab-case`
|
|
170
|
+
|
|
171
|
+
Taco-internal rule: values of the `data-taco` component-marker attribute must
|
|
172
|
+
be lowercase kebab-case (`data-taco="column-header"`, not
|
|
173
|
+
`data-taco="Select2"`). Digits are allowed (`select2-value`). Statically
|
|
174
|
+
knowable values are validated wherever they appear — plain literals, expression
|
|
175
|
+
containers, both branches of ternaries, and static template literals —
|
|
176
|
+
while genuinely dynamic expressions and `undefined`/omitted branches are
|
|
177
|
+
skipped.
|
|
178
|
+
|
|
179
|
+
Deliberately not autofixable: `data-taco` values pair with `[data-taco="…"]`
|
|
180
|
+
selectors in Taco and in consumer apps, so renames must be coordinated by hand.
|
|
181
|
+
|
|
182
|
+
### `taco/no-data-taco-attribute`
|
|
183
|
+
|
|
184
|
+
Consumer-facing rule (part of the `recommended` config): `data-taco` is the
|
|
185
|
+
design system's reserved component-marker namespace, set by Taco's own
|
|
186
|
+
components to identify themselves in the DOM. Application code must not add it
|
|
187
|
+
in any form — use `data-testid` or an application-specific `data-*` attribute
|
|
188
|
+
instead. Not enabled inside Taco itself.
|
|
189
|
+
|
|
190
|
+
### `taco/no-component-margin`
|
|
191
|
+
|
|
192
|
+
Flags margin utilities (`m-*`, `mx-*`, `my-*`, `ms-*`, `me-*`, `mt-*`, `mr-*`,
|
|
193
|
+
`mb-*`, `ml-*` — including variant, negative, important, and arbitrary forms)
|
|
194
|
+
in the `className` of the **root element a component returns**:
|
|
195
|
+
|
|
196
|
+
```tsx
|
|
197
|
+
function Badge() {
|
|
198
|
+
return <span className="mt-4" />; // ✗ outer spacing belongs to the consumer
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
A component's external spacing is its consumer's decision (`gap-*`, `space-*`,
|
|
203
|
+
or padding on the parent); baking margins into the root makes the component
|
|
204
|
+
unusable in contexts with different spacing needs. Margins on nested elements
|
|
205
|
+
and padding anywhere are internal layout and allowed.
|
|
206
|
+
|
|
207
|
+
Root detection covers `return` statements, arrow implicit returns, ternary /
|
|
208
|
+
logical returns, and parenthesized returns. JSX assigned to variables or passed
|
|
209
|
+
as call arguments is not treated as a root, and children of a root fragment are
|
|
210
|
+
not checked.
|
|
211
|
+
|
|
212
|
+
### `taco/no-disallowed-color-classes`
|
|
213
|
+
|
|
214
|
+
Flags string literals and template elements that contain:
|
|
215
|
+
|
|
216
|
+
1. Color utilities whose color isn't in Taco's palette (`colors` in
|
|
217
|
+
[`tailwind.theme.js`](https://github.com/e-conomic/taco/blob/main/packages/taco/tailwind.theme.js), built in
|
|
218
|
+
[`tailwind.theme.colors.js`](https://github.com/e-conomic/taco/blob/main/packages/taco/tailwind.theme.colors.js)), which is the
|
|
219
|
+
allowlist — undefined shades (`text-blue-400`), families (`bg-orange-500`,
|
|
220
|
+
`bg-brand-dawn`), bare families without a `DEFAULT` (`bg-pink`), and keywords
|
|
221
|
+
the theme doesn't define (`text-inherit`). The theme replaces Tailwind's
|
|
222
|
+
palette, so these generate no CSS. Covers every color prefix
|
|
223
|
+
(`text|bg|border[-{x|y|t|r|b|l|s|e}]|ring|ring-offset|outline|shadow|divide|accent|caret|fill|stroke|decoration|placeholder|from|via|to`)
|
|
224
|
+
through variants, `!` and `/opacity`. A value only counts as a color when it
|
|
225
|
+
starts with a color family from the theme or Tailwind's default palette
|
|
226
|
+
(read from `tailwindcss/colors`), so `text-sm`, `border-2` etc. are ignored.
|
|
227
|
+
2. Arbitrary `text-[…]` / `bg-[…]` color literals: hex, color functions
|
|
228
|
+
(`rgb()`, `oklch()`…) and CSS named colors. Non-color values
|
|
229
|
+
(`text-[13px]`, `bg-[inherit]`) pass.
|
|
230
|
+
|
|
231
|
+
The class matching lives in [`src/policies/color.ts`](https://github.com/e-conomic/taco/blob/main/packages/taco-rules/src/policies/color.ts).
|
|
232
|
+
|
|
233
|
+
### `taco/no-disallowed-radius-classes`
|
|
234
|
+
|
|
235
|
+
Flags string literals and template elements that contain a `rounded[-{side}]-{size}`
|
|
236
|
+
utility (sides `t|r|b|l|s|e`, corners `tl|tr|br|bl|ss|se|es|ee`) whose size
|
|
237
|
+
isn't a key of `borderRadius` in [`tailwind.theme.js`](https://github.com/e-conomic/taco/blob/main/packages/taco/tailwind.theme.js),
|
|
238
|
+
through variants and `!`. It's an allowlist, so Tailwind's other sizes (`md`, `2xl`,
|
|
239
|
+
`3xl`…), sizes later Tailwind versions add, and arbitrary `rounded-[…]` values all
|
|
240
|
+
fail.
|
|
241
|
+
|
|
242
|
+
Use `rounded`, `rounded-none`, `rounded-sm`, `rounded-lg`, `rounded-xl` or
|
|
243
|
+
`rounded-full`. The class matching lives in [`src/policies/radius.ts`](https://github.com/e-conomic/taco/blob/main/packages/taco-rules/src/policies/radius.ts).
|
|
244
|
+
|
|
245
|
+
### `taco/no-disallowed-shadow-classes`
|
|
246
|
+
|
|
247
|
+
Flags string literals and template elements that contain a `shadow-{size}`
|
|
248
|
+
utility whose size isn't a key of `boxShadow` in
|
|
249
|
+
[`tailwind.theme.js`](https://github.com/e-conomic/taco/blob/main/packages/taco/tailwind.theme.js) (e.g. `shadow-2xl`,
|
|
250
|
+
`shadow-inner`, `shadow-xs`), through variants and `!`, and arbitrary
|
|
251
|
+
`shadow-[…]` values. Shadow colors (`shadow-blue-500`) are left to
|
|
252
|
+
`taco/no-disallowed-color-classes`, and `drop-shadow-*` isn't a box-shadow.
|
|
253
|
+
|
|
254
|
+
Use `shadow-none`, `shadow-sm`, `shadow`, `shadow-md`, `shadow-lg` or `shadow-xl`.
|
|
255
|
+
The class matching lives in [`src/policies/shadow.ts`](https://github.com/e-conomic/taco/blob/main/packages/taco-rules/src/policies/shadow.ts).
|
|
256
|
+
|
|
257
|
+
### `taco/no-disallowed-spacing-classes`
|
|
258
|
+
|
|
259
|
+
Taco-internal rule (not in `recommended`): consumers keep Tailwind's full
|
|
260
|
+
spacing scale. Flags string literals and template elements that contain padding
|
|
261
|
+
(`p`, `px`, `pt`, …), margin (`m`, `mx`, `mt`, …), `gap[-x|-y]` or
|
|
262
|
+
`space-{x|y}` utilities — including negative, important and variant forms —
|
|
263
|
+
with:
|
|
264
|
+
|
|
265
|
+
1. A value outside the `spacing` scale in `@economic/taco-tokens`: anything other
|
|
266
|
+
than `0`, `1`, `2`, `3`, `4`, `6`, `8`, `12` (e.g. `p-5`, `px-1.5`, `-my-0.5`,
|
|
267
|
+
`gap-px`).
|
|
268
|
+
2. Arbitrary values (`p-[3px]`, `mb-[var(--x)]`).
|
|
269
|
+
|
|
270
|
+
Margin `auto` is allowed. Look-alikes such as `scroll-mt-*` are ignored. The
|
|
271
|
+
class matching lives in [`src/policies/spacing.ts`](https://github.com/e-conomic/taco/blob/main/packages/taco-rules/src/policies/spacing.ts).
|
|
272
|
+
|
|
273
|
+
Its CSS counterpart is the `@economic/spacing` Stylelint plugin. Both are off
|
|
274
|
+
in the shipped configs until Taco's spacing migration starts; Taco turns them on
|
|
275
|
+
with an override then.
|
|
276
|
+
|
|
277
|
+
### `taco/no-display-value-key`
|
|
278
|
+
|
|
279
|
+
Flags React `key` props derived solely from display values — `label`, `name`,
|
|
280
|
+
`title`, `text`, `caption`, `heading`, `header`, `description`, `content`,
|
|
281
|
+
`dataKey`:
|
|
282
|
+
|
|
283
|
+
```tsx
|
|
284
|
+
shapes.map(shape => <Cell key={shape.dataKey} />); // ✗ two segments can share a label
|
|
285
|
+
shapes.map((shape, index) => <Cell key={`${index}-${shape.dataKey}`} />); // ✓
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Display values carry no uniqueness guarantee — two chart segments labelled
|
|
289
|
+
`Jan`, two rows named `Total` — so React reconciles the siblings as one
|
|
290
|
+
element. The failure is silent until something (a library upgrade, a reorder)
|
|
291
|
+
makes the collision matter, which is exactly how [#2544] happened.
|
|
292
|
+
|
|
293
|
+
The key's contributing names are collected through template literals,
|
|
294
|
+
concatenation, bracket access and calls (`String(item.label)` and
|
|
295
|
+
`item['label']` are both still a label). An identifier-ish name (`id`, `uuid`,
|
|
296
|
+
`key`, `slug`, `path`, `href`, `url`, `guid`, `uid`) or an index (`i`, `idx`,
|
|
297
|
+
`index`, `position`, `*Index`) clears the key — a whole-name match wins over a
|
|
298
|
+
trailing-word one, so `dataKey` is a display value while `rowKey` is an
|
|
299
|
+
identifier.
|
|
300
|
+
|
|
301
|
+
Because a key can evaluate to more than one string, names are collected **per
|
|
302
|
+
branch**: a ternary or a `??` fallback forks into separate branches, a template
|
|
303
|
+
literal or a concatenation combines within one, and every branch has to clear
|
|
304
|
+
itself.
|
|
305
|
+
|
|
306
|
+
```tsx
|
|
307
|
+
key={`${index}-${item.label}`} // ✓ one branch, carries the index
|
|
308
|
+
key={item.id ?? item.uuid} // ✓ both branches carry an identifier
|
|
309
|
+
key={item.label ?? item.id} // ✗ renders the bare label whenever there is one
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
The id in that last example vouches only for the branch it's on.
|
|
313
|
+
|
|
314
|
+
The check is attribute-level: it inspects every `key` prop regardless of the
|
|
315
|
+
element, library, or whether there's a surrounding `.map` — siblings can be
|
|
316
|
+
produced any number of ways. Fixtures cover tables, selects, menus, navigation,
|
|
317
|
+
forms and charts.
|
|
318
|
+
|
|
319
|
+
Names are classified by their last camelCase segment (`columnName` → `name`),
|
|
320
|
+
so the rule is a heuristic and deliberately not in `recommended`. `value` is
|
|
321
|
+
excluded from all three groups: it's an identifier by React convention (select
|
|
322
|
+
options, radio groups) often enough that flagging it was mostly noise, but it
|
|
323
|
+
can't vouch for uniqueness either, so it neither triggers nor clears the rule.
|
|
324
|
+
|
|
325
|
+
Not autofixable: whether the right fix is a stable id or an index prefix
|
|
326
|
+
depends on whether the list reorders.
|
|
327
|
+
|
|
328
|
+
`packages/taco` turns the rule off for stories and specs (see the overrides in
|
|
329
|
+
[`.oxlintrc.json`](https://github.com/e-conomic/taco/blob/main/packages/taco/.oxlintrc.json)). Those files author their own
|
|
330
|
+
fixture data, so their keys are unique by construction; component and primitive
|
|
331
|
+
source takes its data from props, where uniqueness can't be assumed. Every
|
|
332
|
+
violation the rule found in Taco fell cleanly on one side of that line — the
|
|
333
|
+
real ones in `charts/` and `Datepicker`, the noise in `*.stories.tsx`.
|
|
334
|
+
|
|
335
|
+
[#2544]: https://github.com/e-conomic/taco/pull/2544
|
|
336
|
+
|
|
337
|
+
### `taco/no-leaked-render`
|
|
338
|
+
|
|
339
|
+
Flags `&&` expressions inside JSX expression containers whose condition
|
|
340
|
+
operands are numeric _by construction_ and would therefore leak into the render
|
|
341
|
+
output when falsy (React renders `0`):
|
|
342
|
+
|
|
343
|
+
1. `.length` access: `{items.length && <span />}` renders `0` when empty. Also
|
|
344
|
+
matched through optional chaining (`items?.length`) and computed access
|
|
345
|
+
(`items['length']`).
|
|
346
|
+
2. Numeric literals and arithmetic/bitwise expressions (`total - used && …`).
|
|
347
|
+
|
|
348
|
+
Every operand of a `&&` chain except the final one is checked:
|
|
349
|
+
`{isReady && items.length && <span />}` is flagged.
|
|
350
|
+
|
|
351
|
+
Safe alternatives are left alone: comparisons (`items.length > 0 && …`),
|
|
352
|
+
boolean coercion (`!!x`, `Boolean(x)`), ternaries, and `||`.
|
|
353
|
+
|
|
354
|
+
Detection is syntactic — oxlint JS plugins expose no type information, so a
|
|
355
|
+
bare identifier that merely _has_ a number type (`{count && <span />}`) is not
|
|
356
|
+
detectable. Ported from eslint-plugin-oesterkilde's type-aware
|
|
357
|
+
`no-leaked-render`, narrowed to what syntax alone can prove.
|
|
358
|
+
|
|
359
|
+
### `taco/no-separate-size-classes`
|
|
360
|
+
|
|
361
|
+
Flags string literals and template elements that use separate `w-{value}` and
|
|
362
|
+
`h-{value}` utilities sharing the same value and modifiers (order and adjacency
|
|
363
|
+
don't matter):
|
|
364
|
+
|
|
365
|
+
1. `w-5 h-5` → `size-5`
|
|
366
|
+
2. `!w-10 !h-10` → `!size-10`
|
|
367
|
+
3. `hover:w-4 hover:h-4` → `hover:size-4`
|
|
368
|
+
|
|
369
|
+
Pairs split across string arguments of the class-combining callees `cn` /
|
|
370
|
+
`clsx` are also detected: `cn('foo w-5', 'bar h-5')` → `cn('foo size-5', 'bar')`.
|
|
371
|
+
Conditional arguments (`isActive && 'h-5'`) never pair with unconditional ones,
|
|
372
|
+
and a local binding (parameter, variable, function) that merely shadows a
|
|
373
|
+
combining callee's name is not analyzed — only imports and globals are trusted
|
|
374
|
+
to combine class strings.
|
|
375
|
+
|
|
376
|
+
Utilities with different values (`w-5 h-10`), mismatched modifiers
|
|
377
|
+
(`hover:w-6 h-6`, `!w-3 h-3`), or values without a `size-*` equivalent
|
|
378
|
+
(`w-screen h-screen`, viewport units) are left alone.
|
|
379
|
+
|
|
380
|
+
Auto-fixable (`fixable: 'code'`): `oxlint --fix`, the editor's Quick Fix, or
|
|
381
|
+
`source.fixAll` rewrites each pair to the combined `size-*` token in place.
|
|
382
|
+
|
|
383
|
+
See https://v3.tailwindcss.com/docs/size.
|
|
384
|
+
|
|
385
|
+
### `taco/no-unnecessary-template-literal`
|
|
386
|
+
|
|
387
|
+
Flags template literals with no `${…}` interpolations — plain strings dressed
|
|
388
|
+
in backticks:
|
|
389
|
+
|
|
390
|
+
```ts
|
|
391
|
+
const a = `hello`; // ✗ → const a = 'hello';
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Left alone: templates with expressions, tagged templates (the tag function
|
|
395
|
+
requires a template), multiline templates (backticks are the cleanest
|
|
396
|
+
multiline syntax), and content containing **both** quote styles — where any
|
|
397
|
+
quoted form would need escaping, so backticks stay the cleanest way to write
|
|
398
|
+
it.
|
|
399
|
+
|
|
400
|
+
Auto-fixable (`fixable: 'code'`): rebuilds the string from the cooked value so
|
|
401
|
+
escape sequences are regenerated for the new quote style. The chosen quote
|
|
402
|
+
never introduces an escape: double quotes when the content contains a single
|
|
403
|
+
quote, single quotes otherwise.
|
|
404
|
+
|
|
405
|
+
## Why string-literal-wide rather than className-only?
|
|
406
|
+
|
|
407
|
+
The rules visit every string literal and every template element in the file
|
|
408
|
+
rather than narrowing to `className` / `clsx` / `cva` callees. This catches
|
|
409
|
+
strings used in ternaries, helper variables, prop forwarding, etc., without
|
|
410
|
+
maintaining an opt-in callee allowlist. It also auto-excludes comments and
|
|
411
|
+
JSX text children since they are not `Literal` / `TemplateElement` nodes.
|
|
412
|
+
|
|
413
|
+
## Disabling a violation
|
|
414
|
+
|
|
415
|
+
Use each linter's native disable directives:
|
|
416
|
+
|
|
417
|
+
```tsx
|
|
418
|
+
// oxlint-disable-next-line taco/no-disallowed-color-classes
|
|
419
|
+
<div className="text-blue-400" />
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
```css
|
|
423
|
+
/* stylelint-disable-next-line @economic/radius */
|
|
424
|
+
.a {
|
|
425
|
+
@apply rounded-md;
|
|
426
|
+
}
|
|
427
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { rules } from "../rules/index.js";
|
|
2
|
+
// The subset of `rules` considered safe to enable by default — general code-hygiene
|
|
3
|
+
// rules with no false-positive risk, marked `docs.recommended: true` in their meta.
|
|
4
|
+
const RECOMMENDED_RULE_NAMES = Object.entries(rules)
|
|
5
|
+
.filter(([, rule]) => rule.meta?.docs?.recommended === true)
|
|
6
|
+
.map(([ruleName]) => ruleName);
|
|
7
|
+
export const recommendedConfig = {
|
|
8
|
+
plugins: ['taco'],
|
|
9
|
+
rules: Object.fromEntries(RECOMMENDED_RULE_NAMES.map(ruleName => [`taco/${ruleName}`, 'error'])),
|
|
10
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The oxlint preset for the class policies. Consumers extend it and override single rules.
|
|
2
|
+
// The build also writes it to `oxlint/styles.json`, for `.oxlintrc.json`, which can only `extends` a file.
|
|
3
|
+
export const stylesConfig = {
|
|
4
|
+
jsPlugins: ['@economic/taco-rules'],
|
|
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-internal, consumers keep the full Tailwind spacing scale; off until taco's spacing migration starts
|
|
10
|
+
'taco/no-disallowed-spacing-classes': 'off',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { rules } from './rules/index.ts';
|
|
2
|
+
declare const configs: {
|
|
3
|
+
all: {
|
|
4
|
+
plugins: string[];
|
|
5
|
+
rules: Record<string, string>;
|
|
6
|
+
};
|
|
7
|
+
recommended: {
|
|
8
|
+
plugins: string[];
|
|
9
|
+
rules: Record<string, string>;
|
|
10
|
+
};
|
|
11
|
+
styles: {
|
|
12
|
+
jsPlugins: string[];
|
|
13
|
+
rules: Record<string, string>;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export { rules, configs };
|
|
17
|
+
declare const _default: {
|
|
18
|
+
configs: {
|
|
19
|
+
all: {
|
|
20
|
+
plugins: string[];
|
|
21
|
+
rules: Record<string, string>;
|
|
22
|
+
};
|
|
23
|
+
recommended: {
|
|
24
|
+
plugins: string[];
|
|
25
|
+
rules: Record<string, string>;
|
|
26
|
+
};
|
|
27
|
+
styles: {
|
|
28
|
+
jsPlugins: string[];
|
|
29
|
+
rules: Record<string, string>;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
meta?: {
|
|
33
|
+
name?: string;
|
|
34
|
+
};
|
|
35
|
+
rules: Record<string, import("@oxlint/plugins").Rule>;
|
|
36
|
+
};
|
|
37
|
+
export default _default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { eslintCompatPlugin } from '@oxlint/plugins';
|
|
2
|
+
import { allConfig } from "./configs/all.js";
|
|
3
|
+
import { recommendedConfig } from "./configs/recommended.js";
|
|
4
|
+
import { stylesConfig } from "./configs/styles.js";
|
|
5
|
+
import { rules } from "./rules/index.js";
|
|
6
|
+
// Adds ESLint-compatible `create` methods (delegating to `createOnce`) to every rule,
|
|
7
|
+
// mutating them in place, so the plugin also works when loaded by real ESLint.
|
|
8
|
+
const plugin = eslintCompatPlugin({ meta: { name: 'taco' }, rules });
|
|
9
|
+
const configs = {
|
|
10
|
+
all: allConfig,
|
|
11
|
+
recommended: recommendedConfig,
|
|
12
|
+
styles: stylesConfig,
|
|
13
|
+
};
|
|
14
|
+
export { rules, configs };
|
|
15
|
+
export default {
|
|
16
|
+
...plugin,
|
|
17
|
+
configs,
|
|
18
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context } from '@oxlint/plugins';
|
|
2
|
+
import type { ClassCheck } from '../../policies/classes.ts';
|
|
3
|
+
import { createTailwindClassSourceVisitors } from './visit-tailwind-class-sources.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Connects a policy check to the linter: every piece of text that may hold classes is checked class
|
|
6
|
+
* by class. Only the first bad class per text is reported, so a long class list doesn't fill the
|
|
7
|
+
* editor with warnings.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createClassPolicyVisitors(context: Context, check: ClassCheck): ReturnType<typeof createTailwindClassSourceVisitors>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { findViolations } from "../../policies/classes.js";
|
|
2
|
+
import { createTailwindClassSourceVisitors } from "./visit-tailwind-class-sources.js";
|
|
3
|
+
/**
|
|
4
|
+
* Connects a policy check to the linter: every piece of text that may hold classes is checked class
|
|
5
|
+
* by class. Only the first bad class per text is reported, so a long class list doesn't fill the
|
|
6
|
+
* editor with warnings.
|
|
7
|
+
*/
|
|
8
|
+
export function createClassPolicyVisitors(context, check) {
|
|
9
|
+
return createTailwindClassSourceVisitors(context, (ctx, node, value) => {
|
|
10
|
+
if (typeof value !== 'string')
|
|
11
|
+
return;
|
|
12
|
+
const [violation] = findViolations(value, check);
|
|
13
|
+
if (violation !== undefined) {
|
|
14
|
+
ctx.report({ node, message: violation.message });
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Context, ESTree } from '@oxlint/plugins';
|
|
2
|
+
type LiteralNode = ESTree.BooleanLiteral | ESTree.NullLiteral | ESTree.NumericLiteral | ESTree.StringLiteral | ESTree.BigIntLiteral | ESTree.RegExpLiteral;
|
|
3
|
+
export type TailwindClassSourceNode = LiteralNode | ESTree.TemplateElement;
|
|
4
|
+
/**
|
|
5
|
+
* ESLint-compat visitors for fragments that may contain Tailwind class strings:
|
|
6
|
+
* - `Literal`: quoted string literals (`className="…"`, `clsx('…')`, etc.)
|
|
7
|
+
* - `TemplateElement`: static chunks inside template literals (between `${…}`)
|
|
8
|
+
*
|
|
9
|
+
* Pair with a `check(context, node, value)` that validates `value`; checks
|
|
10
|
+
* typically early-return when `value` is not a non-empty string.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createTailwindClassSourceVisitors(context: Context, check: (context: Context, node: TailwindClassSourceNode, value: unknown) => void): {
|
|
13
|
+
Literal(node: LiteralNode): void;
|
|
14
|
+
TemplateElement(node: ESTree.TemplateElement): void;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ESLint-compat visitors for fragments that may contain Tailwind class strings:
|
|
3
|
+
* - `Literal`: quoted string literals (`className="…"`, `clsx('…')`, etc.)
|
|
4
|
+
* - `TemplateElement`: static chunks inside template literals (between `${…}`)
|
|
5
|
+
*
|
|
6
|
+
* Pair with a `check(context, node, value)` that validates `value`; checks
|
|
7
|
+
* typically early-return when `value` is not a non-empty string.
|
|
8
|
+
*/
|
|
9
|
+
export function createTailwindClassSourceVisitors(context, check) {
|
|
10
|
+
return {
|
|
11
|
+
Literal(node) {
|
|
12
|
+
if (typeof node.value === 'string') {
|
|
13
|
+
check(context, node, node.value);
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
TemplateElement(node) {
|
|
17
|
+
const value = node.value?.cooked ?? node.value?.raw;
|
|
18
|
+
check(context, node, value);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|