@teacss/linter 1.0.0 → 1.1.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/LICENSE.third-party.md +5538 -0
- package/README.md +4 -4
- package/dist/project.js +29 -2
- package/dist/sites.js +7 -3
- package/dist/tokens.js +37 -20
- package/package.json +5 -10
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
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
4
|
|
|
5
|
-
Install it with oxlint as development dependencies: `npm install --save-dev @teacss/linter oxlint@1.
|
|
5
|
+
Install it with oxlint as development dependencies: `npm install --save-dev @teacss/linter oxlint@1.96`. It needs Node.js 26 or later and oxlint 1.95.x or 1.96.x. The oxlint API for JavaScript plugins is in alpha, so the supported oxlint range holds only the tested minor versions, 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
6
|
|
|
7
7
|
## Setup
|
|
8
8
|
|
|
@@ -301,7 +301,7 @@ Not reported:
|
|
|
301
301
|
- A function parameter and values taken from one (a forwarded `className`, `props.className`, `this.props.className`).
|
|
302
302
|
- `undefined`, `null` and `void 0`.
|
|
303
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.
|
|
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. A spread in that object is passed through when its value comes from a function parameter, as in `button({ ...props })` and `button({ ...variants, className })`. Any other spread, such as `button({ ...defaults })`, is reported: the plugin does not read the object it spreads.
|
|
305
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
306
|
|
|
307
307
|
A method call on the result of a call, such as `rec().concat("...")`, is reported.
|
|
@@ -413,7 +413,7 @@ Your own options join the preset:
|
|
|
413
413
|
| `grid-column:[1/-1]` | the full-width span in `standard.md` |
|
|
414
414
|
| `max-w:[34em]` | the prose measure |
|
|
415
415
|
| `rd:9999px` | the pill radius |
|
|
416
|
-
| `/^rd:\[calc\(var\(--radius-\w+\)_-_[^@]+\)\]$/` | a radius step minus a length: `rd:[calc(var(--radius-4x)_-_1px)]` |
|
|
416
|
+
| `/^rd:\[calc\(var\(--radius-\w+\)_-_[^@]+\)\]$/` | a radius step minus a length: `rd:[calc(var(--radius-4x)_-_var(--spacing)_-_1px)]` |
|
|
417
417
|
| `p-b:[env(safe-area-inset-bottom)]` | the safe-area padding of a full-bleed surface |
|
|
418
418
|
|
|
419
419
|
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:[34em]@md` and `rd:9999px!` pass, and `max-w:[34em]@[&>li]` is reported for its condition.
|
|
@@ -448,7 +448,7 @@ A clean oxlint run does not prove that a project follows the policy. The plugin
|
|
|
448
448
|
- **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.
|
|
449
449
|
- **Callback parameters.** In `["p:4"].map((c) => <i className={c} />)` the parameter `c` is accepted and the array is not read.
|
|
450
450
|
- **CSS-module objects.** `styles.root` is reported by `require-static-classes`. Turn the rule off for those directories with oxlint's `overrides`.
|
|
451
|
-
- **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
|
+
- **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. After a load error, the plugin watches the entry, the files it imports and the file the error names, so an edit to any of them is picked up within a second too. One exception: while an imported file repeats `@radius`, an import between the entry and that file is not watched.
|
|
452
452
|
- **`oxlint-disable` comments and edits to `.oxlintrc.json`.** Both switch the rules off. Count the disable comments in review or in CI.
|
|
453
453
|
- **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.
|
|
454
454
|
|
package/dist/project.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
2
|
+
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
3
3
|
import { Engine, expandClassGroups, parseEntry, splitClassTokens } from "@teacss/engine";
|
|
4
4
|
const CANDIDATES = ["package.json", "index.css", "src/index.css"];
|
|
5
5
|
const RECHECK_MS = 1000;
|
|
@@ -72,6 +72,31 @@ export class Project {
|
|
|
72
72
|
}
|
|
73
73
|
const slots = new Map();
|
|
74
74
|
const stampOf = (files) => files.map((file) => statSync(file, { throwIfNoEntry: false })?.mtimeMs ?? 0).join(" ");
|
|
75
|
+
function namedFiles(details) {
|
|
76
|
+
const diagnostics = Array.isArray(details?.diagnostics) ? details.diagnostics : [];
|
|
77
|
+
return [details?.path, ...diagnostics.map(({ file }) => file)].filter((file) => typeof file === "string" && isAbsolute(file));
|
|
78
|
+
}
|
|
79
|
+
function entryPaths(root, entry) {
|
|
80
|
+
if (entry !== null)
|
|
81
|
+
return [entry];
|
|
82
|
+
let configured;
|
|
83
|
+
try {
|
|
84
|
+
configured = JSON.parse(readFileSync(join(root, "package.json"), "utf8")).teacss?.entry;
|
|
85
|
+
}
|
|
86
|
+
catch { }
|
|
87
|
+
const defaults = [join(root, "index.css"), join(root, "src/index.css")];
|
|
88
|
+
return (typeof configured === "string" ? [resolve(root, configured), ...defaults] : defaults).filter((file) => existsSync(file));
|
|
89
|
+
}
|
|
90
|
+
function importGraph(engine, root, entry) {
|
|
91
|
+
return entryPaths(root, entry).flatMap((entryPath) => {
|
|
92
|
+
try {
|
|
93
|
+
return engine.inspectEntry({ root, entryPath }).configFiles;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
75
100
|
function load(root, entry) {
|
|
76
101
|
const candidates = entry === null ? CANDIDATES.map((name) => join(root, name)) : [entry];
|
|
77
102
|
const slot = { checkedAt: Date.now(), stamp: "", watched: candidates, project: null, failure: null, reported: new Set() };
|
|
@@ -85,9 +110,11 @@ function load(root, entry) {
|
|
|
85
110
|
}
|
|
86
111
|
}
|
|
87
112
|
catch (error) {
|
|
113
|
+
const details = error.details;
|
|
88
114
|
const message = (error instanceof Error ? error.message : String(error)).replace(/\s+/g, " ");
|
|
89
|
-
const path =
|
|
115
|
+
const path = details?.path;
|
|
90
116
|
slot.failure = typeof path === "string" && !message.includes(path) ? `${message}: ${path}` : message;
|
|
117
|
+
slot.watched = [...new Set([...candidates, ...namedFiles(details), ...importGraph(engine, root, entry)])];
|
|
91
118
|
}
|
|
92
119
|
if (slot.project === null)
|
|
93
120
|
engine.dispose();
|
package/dist/sites.js
CHANGED
|
@@ -189,7 +189,7 @@ export class Reader {
|
|
|
189
189
|
if (!this.#recipeCallee(node.callee) || rest.length > 0 || (selection !== null && selection.type !== "ObjectExpression"))
|
|
190
190
|
return false;
|
|
191
191
|
if (selection?.type === "ObjectExpression")
|
|
192
|
-
for (const [name, value] of this.#fields(selection, site))
|
|
192
|
+
for (const [name, value] of this.#fields(selection, site, true))
|
|
193
193
|
if (name === "className")
|
|
194
194
|
this.#read(value, site, true, true);
|
|
195
195
|
return true;
|
|
@@ -338,10 +338,14 @@ export class Reader {
|
|
|
338
338
|
site.unreadable.push(node);
|
|
339
339
|
return null;
|
|
340
340
|
}
|
|
341
|
-
#fields(node, site) {
|
|
341
|
+
#fields(node, site, forwardSpreads = false) {
|
|
342
342
|
const fields = [];
|
|
343
343
|
for (const property of this.#object(node, site)?.properties ?? []) {
|
|
344
|
-
if (property.type === "SpreadElement"
|
|
344
|
+
if (property.type === "SpreadElement") {
|
|
345
|
+
if (!forwardSpreads || !this.fromParameter(property.argument))
|
|
346
|
+
site.unreadable.push(property);
|
|
347
|
+
}
|
|
348
|
+
else if (property.computed)
|
|
345
349
|
site.unreadable.push(property);
|
|
346
350
|
else if (property.key.type === "Identifier")
|
|
347
351
|
fields.push([property.key.name, property.value]);
|
package/dist/tokens.js
CHANGED
|
@@ -2,10 +2,41 @@ export const CSS_MARKER = ":css:";
|
|
|
2
2
|
const SPACES = " \t\n\r\f";
|
|
3
3
|
const OPENERS = "([{";
|
|
4
4
|
const CLOSERS = ")]}";
|
|
5
|
+
const QUOTES = `"'`;
|
|
5
6
|
const isSpace = (char) => char !== undefined && SPACES.includes(char);
|
|
7
|
+
const opensQuote = (char, open) => QUOTES.includes(char) && open.some((opener) => opener !== "{");
|
|
8
|
+
function* unquoted(value, from, to) {
|
|
9
|
+
const open = [];
|
|
10
|
+
let quote = "";
|
|
11
|
+
let quoteAt = from;
|
|
12
|
+
for (let index = from; index < to || quote !== ""; index++) {
|
|
13
|
+
if (index >= to) {
|
|
14
|
+
quote = "";
|
|
15
|
+
index = quoteAt;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const char = value[index];
|
|
19
|
+
if (char === "\\")
|
|
20
|
+
index++;
|
|
21
|
+
else if (quote !== "") {
|
|
22
|
+
if (char === quote)
|
|
23
|
+
quote = "";
|
|
24
|
+
}
|
|
25
|
+
else if (opensQuote(char, open)) {
|
|
26
|
+
quote = char;
|
|
27
|
+
quoteAt = index;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
if (OPENERS.includes(char))
|
|
31
|
+
open.push(char);
|
|
32
|
+
else if (CLOSERS.includes(char))
|
|
33
|
+
open.pop();
|
|
34
|
+
yield [index, open.length];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
6
38
|
function cut(value, from, to, separator, offset) {
|
|
7
39
|
const spans = [];
|
|
8
|
-
let depth = 0;
|
|
9
40
|
let start = from;
|
|
10
41
|
const flush = (end) => {
|
|
11
42
|
let head = start;
|
|
@@ -17,15 +48,8 @@ function cut(value, from, to, separator, offset) {
|
|
|
17
48
|
if (tail > head)
|
|
18
49
|
spans.push({ text: value.slice(head, tail), start: offset + head, end: offset + tail });
|
|
19
50
|
};
|
|
20
|
-
for (
|
|
21
|
-
|
|
22
|
-
if (char === "\\")
|
|
23
|
-
index++;
|
|
24
|
-
else if (OPENERS.includes(char))
|
|
25
|
-
depth++;
|
|
26
|
-
else if (CLOSERS.includes(char))
|
|
27
|
-
depth = Math.max(0, depth - 1);
|
|
28
|
-
else if (depth === 0 && separator(char)) {
|
|
51
|
+
for (const [index, depth] of unquoted(value, from, to)) {
|
|
52
|
+
if (depth === 0 && separator(value[index])) {
|
|
29
53
|
flush(index);
|
|
30
54
|
start = index + 1;
|
|
31
55
|
}
|
|
@@ -42,16 +66,9 @@ export function conditionsOf(token) {
|
|
|
42
66
|
.map(({ text }) => text);
|
|
43
67
|
}
|
|
44
68
|
function closingBrace(text) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (char === "\\")
|
|
49
|
-
index++;
|
|
50
|
-
else if (OPENERS.includes(char))
|
|
51
|
-
depth++;
|
|
52
|
-
else if (CLOSERS.includes(char) && --depth === 0)
|
|
53
|
-
return char === "}" ? index : -1;
|
|
54
|
-
}
|
|
69
|
+
for (const [index, depth] of unquoted(text, 0, text.length))
|
|
70
|
+
if (depth === 0)
|
|
71
|
+
return text[index] === "}" ? index : -1;
|
|
55
72
|
return -1;
|
|
56
73
|
}
|
|
57
74
|
export function groupMembers(group) {
|
package/package.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teacss/linter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "oxlint plugin for TeaCSS: limits which classes a project may write",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/teacss/teacss-rs.git",
|
|
10
|
-
"directory": "packages/linter"
|
|
11
|
-
},
|
|
12
|
-
"homepage": "https://github.com/teacss/teacss-rs/tree/master/packages/linter#readme",
|
|
7
|
+
"homepage": "https://css.teakit.org",
|
|
13
8
|
"main": "./dist/index.js",
|
|
14
9
|
"types": "./dist/index.d.ts",
|
|
15
10
|
"exports": {
|
|
@@ -33,14 +28,14 @@
|
|
|
33
28
|
"node": ">=26"
|
|
34
29
|
},
|
|
35
30
|
"dependencies": {
|
|
36
|
-
"@teacss/engine": "1.
|
|
31
|
+
"@teacss/engine": "1.1.0"
|
|
37
32
|
},
|
|
38
33
|
"peerDependencies": {
|
|
39
|
-
"oxlint": "1.95.x"
|
|
34
|
+
"oxlint": "1.95.x || 1.96.x"
|
|
40
35
|
},
|
|
41
36
|
"devDependencies": {
|
|
42
37
|
"@types/node": "^26.6.11",
|
|
43
|
-
"oxlint": "1.
|
|
38
|
+
"oxlint": "1.96.0",
|
|
44
39
|
"typescript": "^7.0.2"
|
|
45
40
|
},
|
|
46
41
|
"scripts": {
|