@teacss/linter 0.0.0-stage → 0.10.16

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2021-PRESENT Anthony Fu <https://github.com/antfu>
4
+ Copyright (c) 2026-PRESENT Billgo <hi@billgo.me>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,458 @@
1
- # Temporary Holding Version
1
+ # @teacss/linter
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An [oxlint](https://oxc.rs/docs/guide/usage/linter.html) plugin that limits which TeaCSS classes a project may write. It reads class strings from `.js`, `.jsx`, `.ts` and `.tsx` files, asks the Rust engine (`@teacss/engine`) what each class is, and reports the ones your policy does not allow. The policy lives in `.oxlintrc.json`; component code does not change.
4
+
5
+ Install it with oxlint as development dependencies: `npm install --save-dev @teacss/linter oxlint@1.95`. It needs Node.js 26 or later and oxlint 1.95.x. The oxlint API for JavaScript plugins is in alpha, so the supported oxlint range is exactly the tested one, and this package is a preview: its rule names and options are not covered by TeaCSS's stability promise and may change in any release. ESLint is not supported. Its tests pass on macOS and on Linux (glibc and musl); it has not been run on Windows.
6
+
7
+ ## Setup
8
+
9
+ Add the plugin and turn on the rules in `.oxlintrc.json`:
10
+
11
+ ```json
12
+ {
13
+ "jsPlugins": ["@teacss/linter"],
14
+ "rules": {
15
+ "teacss/no-unknown-classes": "error",
16
+ "teacss/no-arbitrary-values": "error",
17
+ "teacss/no-raw-colors": "error",
18
+ "teacss/no-inline-styles": "error",
19
+ "teacss/require-static-classes": "error"
20
+ }
21
+ }
22
+ ```
23
+
24
+ Then run `npx oxlint`. No rule is on by default. `teacss/no-restricted-classes` and `teacss/no-restyle` need options of their own.
25
+
26
+ The plugin finds the TeaCSS project of each file by itself. From the file's directory upward, the first directory in which the engine finds a CSS entry is the project root. The entry is found as in every TeaCSS integration: `package.json#teacss.entry`, then `index.css`, then `src/index.css` (the last two must hold `@teacss;`). In a monorepo each file is checked against its nearest project. A file with no project above it is not checked and gets no report.
27
+
28
+ The plugin reads only the CSS entry. Options that an integration passes inline (for example in `vite.config`) are not visible to it.
29
+
30
+ ### Settings
31
+
32
+ ```json
33
+ {
34
+ "settings": {
35
+ "teacss": {
36
+ "root": "apps/web",
37
+ "entry": "styles/tea.css",
38
+ "functions": ["cx"],
39
+ "note": "See docs/classes.md."
40
+ }
41
+ }
42
+ }
43
+ ```
44
+
45
+ | Setting | Meaning |
46
+ | --- | --- |
47
+ | `root` | The project root for every linted file, relative to the directory oxlint runs in. Turns the upward search off. |
48
+ | `entry` | The CSS entry, relative to `root`. Without `root`, the root is the directory oxlint runs in. |
49
+ | `functions` | More function names whose arguments are class lists, read like `cn`. |
50
+ | `note` | Text added after every diagnostic of the plugin, after one space. Line breaks in it become spaces and the space around it is removed. A note that is empty after that adds nothing. Use it to point to your own class guide. |
51
+
52
+ To leave files out, use oxlint's own `ignorePatterns` or `overrides`. `@source` in the CSS entry does not affect linting.
53
+
54
+ ## Where classes are read
55
+
56
+ - The JSX attributes `className` and `class`.
57
+ - The arguments of `cn(...)`, of every function named in `settings.teacss.functions`, and of the tagged template ``cn`...` ``: strings, arrays, both branches of `a ? b : c`, the right side of `a && b`, both sides of `a || b`, and the keys of an object argument.
58
+ - The definition passed to `recipe(...)`: `defaults`, every choice in `variants`, and `className` in `compoundVariants`.
59
+ - The `className` property of the object passed to a recipe call: `button({ size: "sm", className: "p:4" })` and `slots.root({ className: "p:4" })`.
60
+ - An identifier in one of these places, when the same file binds it with `const` to a value the plugin can read. Only one step is followed.
61
+ - The default of a parameter or of a destructured name used in one of these places: `function A({ className = "p:4" })`.
62
+
63
+ In a template literal with `${...}`, a static token that is separated from every interpolation by whitespace is checked. An interpolation that stands alone between whitespace is read as a class value of its own.
64
+
65
+ Variant groups such as `{p:4;m:2}@hover` are expanded and each member is checked at its own position, but only where TeaCSS expands them: in the arguments of `cn`, `recipe` and the configured functions, and in a string that holds the `:css:` marker.
66
+
67
+ A project shortcut (`@shortcut` in the CSS entry) is checked by its members and reported where it is used. Shortcuts from the presets are not expanded.
68
+
69
+ ## Rules
70
+
71
+ Every message is one line and names the class, the reason and what to write instead. Among `no-unknown-classes`, `no-raw-colors` and `no-arbitrary-values`, each class is reported by at most one rule: an unknown class by `no-unknown-classes`, a raw color by `no-raw-colors`, any other literal or arbitrary value or condition by `no-arbitrary-values`. One case gets two reports: a role or dictionary color with a step outside `steps` and an arbitrary condition is reported by `no-raw-colors` for the step and by `no-arbitrary-values` for the condition. A project shortcut is the exception: it is reported once for each member that breaks a rule, so two rules can report the same shortcut for two different members. `no-restricted-classes` and `no-restyle` are policies of their own and can report a class that one of the other rules also reports.
72
+
73
+ A pattern is an exact name, a name with `*`, or a regular expression written as `/source/flags` with a source that is not empty. The flags `g` and `y` are ignored. Every `allow` list takes patterns, and so do the selectors of `no-restricted-classes` and `no-restyle`. A regular expression that does not compile switches its rule off for the project and is reported once, on the first line of one file.
74
+
75
+ A name or a name with `*` that starts with `@`, or a regular expression whose source starts with `^@`, is a condition pattern. It is matched against each condition of a class, written with its `@`: `"@aria-[*]"` matches the condition of `font-weight:5x@aria-[current=page]`. What a match means depends on the rule:
76
+
77
+ | Where | A condition pattern |
78
+ | --- | --- |
79
+ | `allow` of `no-unknown-classes` and `no-raw-colors` | Allows a class that has a matching condition. This accepts every class under that condition, whatever its value: with `"@print"`, `text-color:#333@print` and `bg-color:red-500@print` both pass. |
80
+ | `allow` of `no-arbitrary-values` | Allows the matching arbitrary conditions. The value of the class is still checked, and so is every other arbitrary condition on it. |
81
+ | A string selector of `no-restricted-classes` and `no-restyle` | Selects a class that has a matching condition. In an `allow` list it accepts every class under that condition. |
82
+
83
+ `no-arbitrary-values`, `no-raw-colors` and `no-restyle` also take `preset: "official"`. See [Preset `official`](#preset-official).
84
+
85
+ In `no-arbitrary-values` and `no-raw-colors`, an `allow` pattern is also matched against the class without `!` and without its conditions, so `"rd:9999px"` allows `rd:9999px!` and `rd:9999px@md`.
86
+
87
+ Every rule also takes `messages`, which replaces its texts. See [Custom messages](#custom-messages).
88
+
89
+ ### `teacss/no-unknown-classes`
90
+
91
+ Reports a class the engine does not match, and a variant group written where nothing expands it.
92
+
93
+ | Option | Meaning |
94
+ | --- | --- |
95
+ | `allow` | Classes that are not TeaCSS classes but are allowed, such as a third-party library's names. Matched against the whole class. |
96
+
97
+ ```json
98
+ { "teacss/no-unknown-classes": ["error", { "allow": ["swiper", "js-*", "/^legacy-[a-z]+$/"] }] }
99
+ ```
100
+
101
+ ```text
102
+ "bgcolor:red" is not a TeaCSS class and is not in the allow list.
103
+ "{p:4;m:2}@hover" is a variant group outside cn(), recipe() or a :css: string, so it generates no CSS.
104
+ ```
105
+
106
+ ### `teacss/no-arbitrary-values`
107
+
108
+ Reports a matched class whose value is not a color and is written in brackets (`p:[13px]`) or as a literal with a unit or a function (`p:13px`), and a class with a condition written in brackets or parentheses (`p:4@[&>li]`).
109
+
110
+ | Option | Meaning |
111
+ | --- | --- |
112
+ | `allow` | A pattern that matches the whole class or its property name allows the class, conditions included: `"max-w:*"`, `"line-height"`. A pattern that matches only the class without `!` and conditions allows its value; an arbitrary condition on it is still reported. A condition pattern allows a condition: `"@aria-[*]"`. |
113
+ | `conditions` | `false` stops the check of conditions. Default `true`. |
114
+ | `preset` | `"official"` adds the bracket values and conditions that the TeaCSS references write to `allow`. |
115
+ | `without` | Entries of the preset's `allow` to leave out, written exactly as the preset writes them. |
116
+
117
+ ```json
118
+ { "teacss/no-arbitrary-values": ["error", { "allow": ["max-w:*", "line-height"], "conditions": false }] }
119
+ ```
120
+
121
+ ```text
122
+ "p:13px" uses a literal value. Use a theme step or number such as p:1x, or allow "p:*" in teacss/no-arbitrary-values.
123
+ "p:4@[&>li]" uses an arbitrary condition.
124
+ "card-x" expands to "p:[13px]", which uses an arbitrary value.
125
+ ```
126
+
127
+ The example after "such as" is a class the engine suggests for the same property. It shows the form, not the value nearest to yours. For a color property the message asks for a role or dictionary name with a step instead.
128
+
129
+ ### `teacss/no-raw-colors`
130
+
131
+ Reports a color literal (`text-color:#333`, `text-color:red`) and a palette family name (`bg-color:red-500`). With `steps`, it also reports a role or dictionary name used with a step outside the list.
132
+
133
+ | Option | Meaning |
134
+ | --- | --- |
135
+ | `allow` | Matched against the whole class, the class without `!` and conditions, and its property name. A condition pattern allows every class with that condition. |
136
+ | `steps` | The steps each role or dictionary name may use. The key `*` applies to every name without its own key. |
137
+ | `preset` | `"official"` sets `steps` for the signal and state roles. |
138
+ | `without` | Patterns of the preset's `steps` keys to leave out. |
139
+
140
+ ```json
141
+ { "teacss/no-raw-colors": ["error", { "steps": { "primary": ["800", "900", "950"], "*": ["200", "950"] } }] }
142
+ ```
143
+
144
+ ```text
145
+ "bg-color:red-500" names the palette family "red". Use a role or dictionary name: failure.
146
+ "text-color:#333" uses a literal color. Use a role or dictionary name with a step.
147
+ "bg-color:primary-500" uses step 500 of "primary". Allowed steps: 800, 900, 950.
148
+ "card-x" expands to "bg-color:red-500", which names the palette family "red".
149
+ ```
150
+
151
+ The names after the colon are the roles and dictionary names that the project binds to that family.
152
+
153
+ A class with a raw color and an arbitrary condition is reported here; when the color is fixed, `no-arbitrary-values` reports the condition. The step of a role or dictionary color is checked whatever its conditions: `bg-color:primary-500@[&>li]` is reported here for the step and by `no-arbitrary-values` for the condition.
154
+
155
+ ### `teacss/no-restricted-classes`
156
+
157
+ Reports a matched class that the `deny` list selects, and, when there is an `allow` list, a matched class that the list does not accept. `deny` is checked first. The rule needs an `allow` list or a `deny` list that is not empty; without one it is not checked, and that is reported once, on the first line of one file. A class the engine does not match is left to `no-unknown-classes`.
158
+
159
+ | Option | Meaning |
160
+ | --- | --- |
161
+ | `allow` | Selectors of the classes that may be written. `[]` accepts nothing. |
162
+ | `deny` | Selectors of the classes that may not be written. An object selector here can carry `message`. |
163
+
164
+ A list cannot hold the same selector twice, and a pattern cannot be an empty string.
165
+
166
+ ```json
167
+ {
168
+ "teacss/no-restricted-classes": ["error", {
169
+ "allow": ["layout", "spacing", { "property": "rd", "kind": "step" }, "btn*"],
170
+ "deny": [{ "property": "float", "message": "Use flex or grid instead of {{class}}." }, { "category": "motion" }]
171
+ }]
172
+ }
173
+ ```
174
+
175
+ A selector is a string or an object.
176
+
177
+ - **A string** that is a category name selects that category: `layout`, `spacing`, `color`, `typography`, `shape`, `effects`, `motion` or `unclassified`. Category names are lower-case and must be written exactly. A string that differs from one only in case or in space around it, such as `"Layout"`, is reported as a configuration error and the rule is not checked. Any other string is a pattern, matched against the class and against its property name. A condition pattern such as `"@hover"` selects every class with that condition. To select a property that has the name of a category, write `{ "property": "color" }`.
178
+ - **An object** selects a class that fits every field it gives. It needs at least one field. `shortcut` cannot be combined with another field, because a shortcut has no property, value, color or category.
179
+
180
+ | Field | Fits when |
181
+ | --- | --- |
182
+ | `category` | The class has this category. |
183
+ | `property` | The pattern matches the property name as written (`p` in `p:4`). |
184
+ | `value` | The pattern matches the value as written (`4` in `p:4@hover`). |
185
+ | `kind` | The value is of this kind: `step`, `number`, `percent`, `variable`, `literal`, `arbitrary` or `keyword`. |
186
+ | `color` | The color is of this kind: `role`, `alias`, `family`, `literal` or `keyword`. |
187
+ | `declares` | The class is not a shortcut and the pattern matches a CSS property it declares: `"padding*"` fits `p:4` (`padding`) and `p-x:4` (`padding-left`). Custom properties are not declared properties. |
188
+ | `shortcut` | The class is a shortcut and the pattern matches its name. |
189
+
190
+ Patterns are matched against the class without `!` and without its conditions, so `"m:auto"` also selects `m:auto!@hover`. A `value` pattern sees the whole value as written, with the `/alpha` suffix of a color: `"primary-500"` does not match `bg-color:primary-500/50`, and `"primary-500*"` matches both.
191
+
192
+ A category comes from the CSS properties a class sets, so one class can have several: `line-clamp:2` is `typography` and `layout`. In `deny`, a category selector selects every class that has the category. In `allow`, a class with several categories needs either one selector without `category` that fits it, or one selector for each of its categories. A class with no category is never selected by a category: these are the shortcuts and the classes that set only custom properties, such as `g-angle:0deg`. `{ "shortcut": "*" }` accepts shortcuts only. A class that sets only custom properties needs a pattern, such as `"g-angle"`.
193
+
194
+ A shortcut is judged by its name first. When `deny` selects the name of a project shortcut, the shortcut is reported and its members are not looked at. Otherwise `deny` is checked against every member, and each member it selects is reported where the shortcut is used. `allow` is checked against the members only when it does not accept the name. So a name that `allow` accepts does not hide a member that `deny` selects. A preset shortcut is judged by its name only.
195
+
196
+ The engine expands a project shortcut inside another project shortcut down to its classes. A `deny` on the name of a project shortcut therefore does not reach a second project shortcut that wraps it: with `@shortcut outer "inner"`, denying `inner` does not report `outer`. Deny the classes themselves if that matters.
197
+
198
+ ```text
199
+ "float:left" is denied by teacss/no-restricted-classes (property float).
200
+ "transition-property:all" is denied by teacss/no-restricted-classes (category motion).
201
+ "shadow:2x" is outside the allowed classes (category effects). Allowed: layout, spacing, rd with step values, btn*.
202
+ "card-x" expands to "shadow:2x", which is outside the allowed classes (category effects).
203
+ "sr-only" is outside the allowed classes (a shortcut). Allowed: layout, spacing.
204
+ ```
205
+
206
+ The parentheses hold the selector that denied the class, or the categories of the class that `allow` does not accept. For a `declares` field they name the property that matched, not the pattern. A class with no category gets `a shortcut` or `sets only custom properties` there. After "Allowed:" the message lists the `allow` selectors, the first eight followed by "and N more" when there are more.
207
+
208
+ A `message` on a `deny` object replaces the whole text for the classes that object selects, and comes before `messages`. It is a template with the placeholders of [Custom messages](#custom-messages). It cannot be an empty string. When the object selects a member of a project shortcut, `{{class}}` is the member, `{{default}}` is the default text for the member alone (`"float:left" is denied by …`), and the text follows `"card-x" expands to "float:left": `.
209
+
210
+ ### `teacss/no-restyle`
211
+
212
+ Reports a class that restyles a component: a class written beside a shortcut that a contract protects, two shortcuts that exclude each other, a class on a JSX component that the component's contract denies, and a preset modifier written without its base. The rule needs `contracts`, `components`, `requireBase: true` or `preset`; without one it is not checked, and that is reported once, on the first line of one file.
213
+
214
+ ```json
215
+ {
216
+ "teacss/no-restyle": ["error", {
217
+ "preset": "official",
218
+ "contracts": [
219
+ {
220
+ "pattern": "btn",
221
+ "deny": [{ "declares": "padding*" }, "color"],
222
+ "allow": ["layout", { "declares": "margin*" }],
223
+ "exclusive": [["btn--primary", "btn--outline"]],
224
+ "message": "{{class}} restyles {{owner}}. Use a btn variant."
225
+ }
226
+ ],
227
+ "components": [{ "name": "Card", "deny": ["shape"] }],
228
+ "requireBase": true,
229
+ "standalone": [{ "name": "toast--shown", "beside": "toast-motion" }]
230
+ }]
231
+ }
232
+ ```
233
+
234
+ | Option | Meaning |
235
+ | --- | --- |
236
+ | `contracts` | Contracts for shortcuts. Each needs `pattern` and at least one of `deny`, `allow` and `exclusive`. |
237
+ | `components` | Contracts for JSX elements. Each needs `name` and at least one of `deny` and `allow`. |
238
+ | `requireBase` | `true` reports a preset shortcut named `block--modifier` in a complete class list that does not hold `block`. Default `false`. A modifier whose `block` is not a shortcut, such as `table-cell--pinned`, is not reported. A class that a contract already reports is not reported again for its base. |
239
+ | `standalone` | Modifiers that `requireBase` does not report. An entry is a pattern, or `{ "name", "beside" }`: the modifier passes only in a list that holds a class matching `beside`. |
240
+ | `preset` | `"official"` adds the contracts of the TeaCSS references. |
241
+ | `without` | Patterns for parts of the preset to leave out: a contract whose `pattern` matches, and an exclusive group that holds a matching name. |
242
+
243
+ | Contract field | Meaning |
244
+ | --- | --- |
245
+ | `pattern` | A pattern for shortcut names. A shortcut in the class list that it matches is the subject of the contract. |
246
+ | `name` | A pattern for JSX element names, such as `Card` or `Ui.*`. The contract applies to the `className` or `class` attribute of a matching element. |
247
+ | `deny`, `allow` | Selectors, written and judged as in [`no-restricted-classes`](#teacssno-restricted-classes): `deny` first, then `allow` when it is given. They judge the other classes of the list. |
248
+ | `exclusive` | Groups of at least two class names. Two different names of one group in the same list are a conflict, and the later one is reported. A group is an array of names, or `{ "names": [...], "conditions": "any" }`. |
249
+ | `message` | A template for the classes this contract reports through `deny` and `allow`. A `message` on a `deny` object comes before it, and `messages` after it. |
250
+
251
+ **Class lists.** The rule judges one class list at a time: the value of one `className` or `class` attribute, the arguments of one outermost `cn(...)` call (a `cn` call inside another, or inside an attribute, belongs to the outer list), and each string of a `recipe` definition (one variant option, the `defaults`, or one `className` of `compoundVariants`; with slots, each slot on its own). `class` and `className` on one element are two lists.
252
+
253
+ A list is complete only when it is the class attribute of an HTML element, such as `<button>`, and all of it can be read. Every other list is incomplete: the attribute of a component (`<Button>`, `<Ui.Button>`), because the plugin does not follow a component to what it renders; a `cn(...)` call that is not inside a class attribute, such as `const tone = cn("btn--primary")` or a returned `cn(...)`, because it is a fragment of a list built elsewhere; a list with a forwarded `className`, a recipe call or a value the plugin cannot read; and every list of a `recipe` definition, because the recipe joins it with others when it runs.
254
+
255
+ **Subject and owner.** With a subject in the list, every other class of the list is judged, except the shortcuts of the subject's block: for `btn` these are `btn--*` and `btn-*`, so `btn btn--primary btn-spinner` reports nothing. The block test compares name prefixes, so a contract on `input` never judges `input-shell` or `input-affix`; give those their own contract. A project shortcut is judged by its members, and a member can be the subject. A project shortcut whose own name matches `pattern` is the subject as a whole, and its members are not judged. A class in the other branch of the same `a ? b : c`, `a || b` or `a ?? b` as the subject is not judged against it, also in a chain such as `a || "toggle" || "p:4"`.
256
+
257
+ **Exclusive names.** A group is checked whether or not the list holds a subject. Two names conflict when one can be present whenever the other is: both unconditional, both in the same string, or one unconditional and the other under a JavaScript condition, as in `cn("btn btn--primary", danger && "btn--failure")`. Names in sibling branches do not conflict: `cn("btn", primary ? "btn--primary" : "btn--outline")` and `cn("btn", primary && "btn--primary", ghost && "btn--outline")` report nothing. A group written as an array compares names that carry the same TeaCSS conditions, so `ring@focus-visible ring-inset@hover` is not a conflict. With `"conditions": "any"` the names conflict whatever their conditions: `btn--primary btn--outline@md`.
258
+
259
+ **Components.** Every class of the attribute is judged; there is no subject. The plugin does not follow the component to the element it renders. A namespaced name such as `<svg:rect>` matches no component.
260
+
261
+ **Base classes.** `requireBase` looks only at complete lists, so `<button className={cn("btn--primary", className)}>`, `<Button className="btn--primary">`, `const tone = cn("btn--primary")` and a `recipe` option are not reported.
262
+
263
+ ```text
264
+ "p:4" restyles btn (declares padding). Allowed with btn: layout, margin*.
265
+ "btn--outline" conflicts with "btn--primary": write one of btn--primary, btn--outline.
266
+ "btn--primary" needs its base class "btn" in the same class list.
267
+ "rd:0" restyles <Card> (category shape).
268
+ "card-x" expands to "p:4", which restyles btn (declares padding).
269
+ ```
270
+
271
+ The parentheses hold what [`no-restricted-classes`](#teacssno-restricted-classes) puts there. "Allowed with" follows when the contract has an `allow` list.
272
+
273
+ The rule does not see a class that is added in another file, such as a `className` passed to a component that renders `btn`. Use `components` for those.
274
+
275
+ ### `teacss/no-inline-styles`
276
+
277
+ Reports each property that a JSX `style` attribute sets, and a `style` value the plugin cannot read. A `style` passed through from a function parameter is not reported.
278
+
279
+ | Option | Meaning |
280
+ | --- | --- |
281
+ | `allow` | CSS property names that may be set inline. Default `["--*"]`. |
282
+
283
+ ```json
284
+ { "teacss/no-inline-styles": ["error", { "allow": ["--*", "view-transition-name"] }] }
285
+ ```
286
+
287
+ ```text
288
+ Inline style sets "color". Use classes; only custom properties (--*) are allowed here.
289
+ ```
290
+
291
+ ### `teacss/require-static-classes`
292
+
293
+ Reports a class value the plugin cannot read: a `let` or imported binding, a call of an unknown function, a lookup such as `STYLES[state]`, or an interpolation glued to static text (`` `p:${n}` ``). Its only option is `messages`.
294
+
295
+ ```text
296
+ This class value cannot be read statically. Use string literals, cn() or recipe().
297
+ ```
298
+
299
+ Not reported:
300
+
301
+ - A function parameter and values taken from one (a forwarded `className`, `props.className`, `this.props.className`).
302
+ - `undefined`, `null` and `void 0`.
303
+ - Calls of `cn`, `recipe` and the configured functions.
304
+ - A recipe call: `recipe(...)()`, `x()` or `x.slot()`, where the same file binds `x` to a recipe or to a recipe's result, with no argument or one object literal.
305
+ - A call of an imported function with no argument or one object literal. The plugin treats it as a recipe call. What the function returns is not checked here; its definition is linted in its own file.
306
+
307
+ A method call on the result of a call, such as `rec().concat("...")`, is reported.
308
+
309
+ ## Custom messages
310
+
311
+ Every rule takes a `messages` option. A key is one of the rule's message names and its value is the template that replaces the default text. oxlint rejects a key that the rule does not have, and an empty template.
312
+
313
+ ```json
314
+ {
315
+ "teacss/no-arbitrary-values": ["error", { "messages": { "arbitrary": "{{property}} takes theme steps, not {{value}}. {{default}}" } }]
316
+ }
317
+ ```
318
+
319
+ | Rule | Message name | Default text |
320
+ | --- | --- | --- |
321
+ | `no-unknown-classes` | `unknown` | `"…" is not a TeaCSS class and is not in the allow list.` |
322
+ | | `group` | `"…" is a variant group outside cn(), recipe() or a :css: string, so it generates no CSS.` |
323
+ | `no-arbitrary-values` | `arbitrary` | `"…" uses an arbitrary value. Use …` |
324
+ | | `literal` | `"…" uses a literal value. Use …` |
325
+ | | `condition` | `"…" uses an arbitrary condition.` |
326
+ | | `member` | `"…" expands to "…", which uses ….` |
327
+ | `no-raw-colors` | `literal` | `"…" uses a literal color. Use …` |
328
+ | | `family` | `"…" names the palette family "…". Use …` |
329
+ | | `step` | `"…" uses step … of "…". Allowed steps: ….` |
330
+ | | `member` | `"…" expands to "…", which ….` |
331
+ | `no-restricted-classes` | `denied` | `"…" is denied by teacss/no-restricted-classes (…).` |
332
+ | | `outside` | `"…" is outside the allowed classes (…). Allowed: ….` |
333
+ | | `member` | `"…" expands to "…", which ….` |
334
+ | `no-restyle` | `restyle` | `"…" restyles … (…).` |
335
+ | | `conflict` | `"…" conflicts with "…": write one of ….` |
336
+ | | `base` | `"…" needs its base class "…" in the same class list.` |
337
+ | | `member` | `"…" expands to "…", which ….` |
338
+ | `no-inline-styles` | `property` | `Inline style sets "…". Use classes; ….` |
339
+ | | `unreadable` | `This style value cannot be read statically. …` |
340
+ | `require-static-classes` | `unreadable` | `This class value cannot be read statically. …` |
341
+
342
+ | Placeholder | Replaced by |
343
+ | --- | --- |
344
+ | `{{class}}` | The class as written. Empty in `no-inline-styles` and `require-static-classes`. |
345
+ | `{{property}}` | The property name as written; in `no-inline-styles`, the CSS property. In a `member` message, the member's. |
346
+ | `{{value}}` | The value as written, without `!` and conditions. In a `member` message, the member's. |
347
+ | `{{member}}` | The member of the project shortcut that broke the rule. Empty when the class is not reported through a shortcut. |
348
+ | `{{owner}}` | In `no-restyle`: the subject of the contract (`btn`), the element (`<Card>`), or the base class in a `base` message. Empty in a `conflict` message and in every other rule. |
349
+ | `{{default}}` | The default text. |
350
+
351
+ A placeholder with no value is replaced by nothing. Any other `{{name}}` stays as written. Line breaks in the result become spaces.
352
+
353
+ `messages` does not change the reports about the configuration itself: a project that fails to load, a regular expression that does not compile, `no-restricted-classes` without a list, and `no-restyle` with nothing to check. `settings.teacss.note` is added to those too.
354
+
355
+ ## Preset `official`
356
+
357
+ `preset: "official"` on `no-raw-colors`, `no-arbitrary-values` and `no-restyle` adds a policy for projects that use the Standard and Official presets as the TeaCSS references describe them. It is off unless you write it. The data is a hand-written table inside the package. Each entry comes from one sentence of `skills/teacss/references/presets.md`, `design.md` or `standard.md`, and a test fails when the sentence is gone.
358
+
359
+ ```json
360
+ {
361
+ "teacss/no-raw-colors": ["error", { "preset": "official" }],
362
+ "teacss/no-arbitrary-values": ["error", { "preset": "official" }],
363
+ "teacss/no-restyle": ["error", { "preset": "official" }]
364
+ }
365
+ ```
366
+
367
+ Your own options join the preset:
368
+
369
+ - Lists (`allow`, `contracts`, `components`, `standalone`) are joined, the preset's entries first.
370
+ - `steps` is merged by key, and your key replaces the preset's: `"steps": { "primary": ["900"] }` changes `primary` and keeps the state roles.
371
+ - A boolean you write (`requireBase`, `conditions`) replaces the preset's.
372
+ - `without` leaves entries of the preset out before the merge. In `no-raw-colors` it holds patterns for `steps` keys. In `no-arbitrary-values` it holds `allow` entries, written exactly as in the table below. In `no-restyle` it holds patterns: a contract whose `pattern` matches is left out, and so is an exclusive group that holds a matching name.
373
+
374
+ ```json
375
+ {
376
+ "teacss/no-raw-colors": ["error", { "preset": "official", "without": ["focused"] }],
377
+ "teacss/no-arbitrary-values": ["error", { "preset": "official", "without": ["rd:9999px"] }],
378
+ "teacss/no-restyle": ["error", { "preset": "official", "without": ["surface-*", "toggle"] }]
379
+ }
380
+ ```
381
+
382
+ ### `no-raw-colors`
383
+
384
+ `steps`, from "Choosing a step" in `standard.md`: "Allowed steps: primary `000 200 300 800 850 900 950`; each state `200 900 950`; `focused-900` (`950` per the focus row); neutral all."
385
+
386
+ | Role | Steps |
387
+ | --- | --- |
388
+ | `primary` | `000` `200` `300` `800` `850` `900` `950` |
389
+ | `success`, `warning`, `failure`, `general` | `200` `900` `950` |
390
+ | `focused` | `900` `950` |
391
+
392
+ `neutral` and dictionary names have no entry and may use every step.
393
+
394
+ ### `no-arbitrary-values`
395
+
396
+ `allow` holds the bracket values and arbitrary conditions that `presets.md` and `design.md` write. An entry is the written class or condition itself, or a pattern for the one part of it that the sentence leaves open: the block name, the ARIA state, the length. One comes from `standard.md`, which gives no other way to span every column.
397
+
398
+ | Pattern | Written as |
399
+ | --- | --- |
400
+ | `/^@\[\.[\w-]+_?&\]$/` | one class name before `&`: `flex-direction:column@[.card&]`, `p:2@[.input-shell&]`, `m-block:4@[.popover-content&]` |
401
+ | `@aria-[*]`, `@in-aria-[*]`, `@group-aria-[*]` | `font-weight:5x@aria-[current=page]`, `opacity:100@in-aria-[checked=true]`, `@group-aria-[checked=true]` |
402
+ | `@[&:not([aria-current=page])]` | the breadcrumb link shared by current and ordinary pages |
403
+ | `@[:focus-visible>&]`, `@[&_a:focus-visible]`, `@[&:has(>:is(input,textarea,select):focus-visible)]` | the focus rings of card media, `article` links and wrappers of hidden native controls |
404
+ | `@[&:has(>:first-child>:checked)]` | the checkbox row of a table |
405
+ | `@[&_>_.avatar]` | the ring color of `avatar-group--ring` |
406
+ | `@[&:where(:dir(rtl))]` | the RTL target of a look |
407
+ | `transition-property:[scale]` | the press transition written out |
408
+ | `flex:[1_1_12ch]` | the basis of `list-content` |
409
+ | `/^\$frame-offset:[^@]+$/`, `/^\$site-content-width:[^@]+$/`, `/^\$site-gutter:[^@]+$/` | any value of the three variables: `$frame-offset:[3.5rem]`, `$site-content-width:[60rem] $site-gutter:1rem` |
410
+ | `font-size:24px` | the glyph size that `presets.md` writes; another size, such as `font-size:14px`, is reported |
411
+ | `/^grid-columns:\[repeat\([^@]+\)\]$/` | one `repeat(...)`: `grid-columns:[repeat(2,minmax(0,1fr))]@md`, `grid-columns:[repeat(auto-fit,_minmax(min(100%,16rem),_1fr))]` |
412
+ | `grid-column:[1/-1]` | the full-width span in `standard.md` |
413
+ | `max-w:[65ch]` | the prose measure |
414
+ | `rd:9999px` | the pill radius |
415
+ | `/^rd:\[calc\(var\(--radius-\w+\)_-_[^@]+\)\]$/` | a radius step minus a length: `rd:[calc(var(--radius-4x)_-_1px)]` |
416
+ | `p-b:[env(safe-area-inset-bottom)]` | the safe-area padding of a full-bleed surface |
417
+
418
+ None of these entries matches a class with a condition as a whole, so the conditions of an allowed class are still checked: `max-w:[65ch]@md` and `rd:9999px!` pass, and `max-w:[65ch]@[&>li]` is reported for its condition.
419
+
420
+ ### `no-restyle`
421
+
422
+ `requireBase` is `true`: "Modifiers accompany their base and use whole words" (`presets.md`, Naming) and "Each variant sits beside `btn`" (`design.md`, Buttons). `standalone` holds the two modifiers that Official itself writes without their base, each only beside the class it is written with: `toast--shown` beside `toast-motion` (`presets.md`), and `modal--backdrop-motion` beside `sheet` (the Official sheet example).
423
+
424
+ | Subject | Contract | Sentence |
425
+ | --- | --- | --- |
426
+ | `btn` | One of `btn--primary`, `btn--outline`, `btn--neutral`, `btn--minimal`, `btn--general`, `btn--success`, `btn--warning`, `btn--failure`, whatever their conditions. | "Choose one variant from the catalogue." (`presets.md`) |
427
+ | `surface-*` | One of the six surface shortcuts, whatever their conditions. | "Choose one surface before merging classes; `cn` does not resolve different surface names." (`presets.md`) |
428
+ | `outlined` | Not with a surface shortcut, `toolbar`, `tab-list`, `sheet`, `tooltip-content`, `modal` or `mockup-code`, whatever their conditions. | "Do not add `outlined` to a `surface-*` shortcut or to a component that paints its own border" (`presets.md`) |
429
+ | `ring` | One of the six rings for the same condition. | "Pick one ring per variant" (`presets.md`) |
430
+ | `dropdown-panel` | One of `dropdown-panel--popover` and `dropdown-panel--floating`, whatever their conditions. | "Choose one, on `dropdown-panel`, never on `dropdown-content`." (`presets.md`) |
431
+ | `dropdown-content` | Denies `dropdown-panel--*`. | The same sentence. |
432
+ | `collapse-motion` | Not with `collapse`, not with `collapse-folds`, whatever their conditions. | "do not combine it with the grid-based `collapse` or with `collapse-folds`" (`presets.md`) |
433
+ | `calendar-grid` | Not with `table`, whatever their conditions. | "Do not compose `calendar-grid` with `table`." (`presets.md`) |
434
+ | `toggle` | Denies a padding other than zero (`p:0`, `p:[0]` and `p:0px` pass). | "Keep a definite width and height, zero track padding" (`presets.md`) |
435
+ | `icon-crossfade` | Denies `blur:`, the classes that declare `scale`, `filter:` with a `blur(` value and `transform:` with a `scale` value. | "Do not add blur or scale poses to the default swap." (`presets.md`) |
436
+
437
+ The preset has no contract for a part unless a sentence states one. The references say that utilities override the defaults of most parts, and the Official examples add state fills to button variants, so the preset does not deny utilities on `btn`, `card` or the other components.
438
+
439
+ ## What it cannot see
440
+
441
+ A clean oxlint run does not prove that a project follows the policy. The plugin does not check:
442
+
443
+ - **Templates of Vue, Svelte and Astro files.** oxlint passes only the script part of these files to plugins, and the plugin skips them.
444
+ - **HTML and JSON.** Classes in `.html` files and in data files are not read.
445
+ - **CSS files.** `@apply` and hand-written rules are not checked. A hand-written CSS class used in markup is caught by `no-unknown-classes` unless you allow it.
446
+ - **Values it cannot read statically.** Strings from another module, object lookups and function results are not classes to the plugin. `require-static-classes` reports them where they are used as a class value, but their content is never checked. The result of an imported function called like a recipe is accepted without a report.
447
+ - **Other ways to pass a class.** Spread props (`<i {...{ className: "..." }} />`, `{...props}`), `React.createElement("div", { className })`, and props with another name (`containerClassName`, `classNames={{ ... }}`) are not class positions.
448
+ - **Callback parameters.** In `["p:4"].map((c) => <i className={c} />)` the parameter `c` is accepted and the array is not read.
449
+ - **CSS-module objects.** `styles.root` is reported by `require-static-classes`. Turn the rule off for those directories with oxlint's `overrides`.
450
+ - **New declaration files in a running process.** A CSS file that `@source` starts to match is picked up only by a new oxlint process. Changes to the entry and to files already loaded are picked up within a second.
451
+ - **`oxlint-disable` comments and edits to `.oxlintrc.json`.** Both switch the rules off. Count the disable comments in review or in CI.
452
+ - **Inline integration options.** Shortcuts or theme values passed to an integration in JavaScript are unknown to the plugin, so classes that depend on them are reported as unknown.
453
+
454
+ The editor's `unmatched-token` diagnostic from `teacss lsp` and `no-unknown-classes` can both report the same unknown class in JSX.
455
+
456
+ ## License
457
+
458
+ MIT