@slashsuite/oxlint-ui 0.0.0-stage → 0.1.1
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/.oxlintrc.json +26 -0
- package/LICENSE +21 -0
- package/README.md +72 -2
- package/package.json +55 -4
- package/plugin.js +293 -0
- package/ui-react.json +1 -0
package/.oxlintrc.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jsPlugins": ["./plugin.js"],
|
|
3
|
+
"rules": {
|
|
4
|
+
"uislash/style-block": "error",
|
|
5
|
+
"uislash/raw-colour": "error",
|
|
6
|
+
"uislash/dark-variant": "error",
|
|
7
|
+
"uislash/styling-prop": "error",
|
|
8
|
+
"uislash/duplicate-component": "error",
|
|
9
|
+
"uislash/inline-colour": "error",
|
|
10
|
+
"uislash/raw-element": "error"
|
|
11
|
+
},
|
|
12
|
+
"overrides": [
|
|
13
|
+
{
|
|
14
|
+
"files": ["**/*.test.*", "**/*.spec.*", "**/*.d.ts"],
|
|
15
|
+
"rules": {
|
|
16
|
+
"uislash/style-block": "off",
|
|
17
|
+
"uislash/raw-colour": "off",
|
|
18
|
+
"uislash/dark-variant": "off",
|
|
19
|
+
"uislash/styling-prop": "off",
|
|
20
|
+
"uislash/duplicate-component": "off",
|
|
21
|
+
"uislash/inline-colour": "off",
|
|
22
|
+
"uislash/raw-element": "off"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jacobus Langner
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @slashsuite/oxlint-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An [oxlint](https://oxc.rs/docs/guide/usage/linter.html) config and plugin for apps built on
|
|
4
|
+
[`@slashsuite/ui-react`](../ui-react). It holds an app to building its UI the UISlash way: compose
|
|
5
|
+
the library's parts, configured through props, and write no styling of your own. Every message says
|
|
6
|
+
what to use instead.
|
|
7
|
+
|
|
8
|
+
These are the hard rules of the `ui-review` pull request check (`tools/ui-review`, its layer 1), run
|
|
9
|
+
on every file an app lints, so an agent or a person hears about them in the editor, before a pull
|
|
10
|
+
request exists. A parity test in this package runs the check's own cases through both and asserts
|
|
11
|
+
the same verdict, line for line and word for word.
|
|
12
|
+
|
|
13
|
+
Status: `0.x`. License: MIT.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
bun add -d -E @slashsuite/oxlint-ui oxlint@1.94.0
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The oxlint peer is an exact version: oxlint's `jsPlugins`, which loads this package's plugin, is
|
|
22
|
+
alpha and not under semver, so the two move together, in a release of this package.
|
|
23
|
+
|
|
24
|
+
## Use
|
|
25
|
+
|
|
26
|
+
Extend the config from the app's `.oxlintrc.json`. `extends` takes a path, relative to the file:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"extends": ["./node_modules/@slashsuite/oxlint-ui/.oxlintrc.json"]
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Every rule is on, as an error, for every file oxlint lints. Test files (`*.test.*`, `*.spec.*`) and
|
|
35
|
+
`.d.ts` files are outside it: a test may render raw markup to drive a part, and
|
|
36
|
+
`@slashsuite/oxlint-testing` is the lint for tests.
|
|
37
|
+
|
|
38
|
+
## The rules
|
|
39
|
+
|
|
40
|
+
| Rule | Fails | Use instead |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| `uislash/style-block` | A `<style>` element in JSX. | Compose `@slashsuite/ui-react` parts; ask uislash for what is missing. |
|
|
43
|
+
| `uislash/raw-colour` | A stock Tailwind colour utility (`bg-slate-800`, `hover:text-violet-700`) or an arbitrary colour (`bg-[#1e1e2e]`) in any string or template literal. The message names the palette role the utility has. | The part that carries the colour. |
|
|
44
|
+
| `uislash/dark-variant` | A `dark:` variant in any string. | Nothing: a theme decides light or dark. |
|
|
45
|
+
| `uislash/styling-prop` | `className`, `class` or `style` on a component imported from `@slashsuite/ui-react`, under its own name or an alias. | The part's props, or a variant asked of uislash. |
|
|
46
|
+
| `uislash/duplicate-component` | A local component (a function, a class, an arrow, `memo(…)` or `forwardRef(…)`) named like a `@slashsuite/ui-react` export and not imported from it, or a file named after one. | The UISlash one, or another name. |
|
|
47
|
+
| `uislash/inline-colour` | A colour literal (hex, a colour function such as `rgb()` or `oklch()`, or a CSS named colour) in a JSX `style` value. | The part, or its `tone`, that carries the colour. |
|
|
48
|
+
| `uislash/raw-element` | A raw `<button>`, `<input>`, `<select>`, `<textarea>` or `<dialog>` in a `.tsx` or `.jsx` file. An `<input>` is told apart by its `type`; `type="hidden"` and `<img>` pass. | The part the message names: `Button`, `Input`, `Checkbox`, `Slider`, `Select`, `Textarea`, `Dialog` and the rest. |
|
|
49
|
+
|
|
50
|
+
A colour word in prose, in a plain string or in a comment is not a colour literal and passes.
|
|
51
|
+
|
|
52
|
+
**New stylesheets stay a `ui-review` check.** A linter sees one file's code, not that a pull request
|
|
53
|
+
adds a `.css` file, so `new-css` is not here.
|
|
54
|
+
|
|
55
|
+
## Where the component list comes from
|
|
56
|
+
|
|
57
|
+
The plugin reads `ui-react.json`, which ships with it: the components `@slashsuite/ui-react` exports
|
|
58
|
+
(from its `src/index.ts`), its palette (`palette.json`, the role of each colour utility) and the
|
|
59
|
+
fixed colour and element tables. It is written from the uislash source when the package is packed,
|
|
60
|
+
through the same code `ui-review` uses, so the two can never list different things. A release of
|
|
61
|
+
this package carries the list of the commit it was released from; an app on an older or newer
|
|
62
|
+
`@slashsuite/ui-react` gets that list, so keep the two on the same release.
|
|
63
|
+
|
|
64
|
+
## In this repo
|
|
65
|
+
|
|
66
|
+
`bunx moon run oxlint-ui:test` runs two suites. `test/fixtures.test.ts` lints `fixtures/`: one bad
|
|
67
|
+
and one good file per rule, each reported line of a bad file marked `// expect: <rule>` (on the line,
|
|
68
|
+
or on its own on the line below), and fails on a miss, on anything unmarked and on any report from
|
|
69
|
+
a good file. `test/parity.test.ts` runs `tools/ui-review/test/cases.ts` through layer 1 and through
|
|
70
|
+
oxlint. A rule changed in one changes in the other, and a new case goes in `cases.ts`.
|
|
71
|
+
|
|
72
|
+
`bun packages/oxlint-ui/scripts/data.ts` writes `ui-react.json`; the test, the pack check and
|
|
73
|
+
`prepack` run it, and the file is not committed.
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slashsuite/oxlint-ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "An oxlint config and plugin that holds an app to building its UI from @slashsuite/ui-react: no <style>, no raw colour, no dark: variant, no styling prop, no look-alike component, no inline colour and no raw element that has a part.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"design-system",
|
|
7
|
+
"lint",
|
|
8
|
+
"oxlint",
|
|
9
|
+
"slashsuite",
|
|
10
|
+
"tailwindcss",
|
|
11
|
+
"uislash"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/slashsuite/uislash/tree/main/packages/oxlint-ui#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/slashsuite/uislash/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Jacobus Langner",
|
|
20
|
+
"url": "https://github.com/madangryscientist"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/slashsuite/uislash.git",
|
|
25
|
+
"directory": "packages/oxlint-ui"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
".oxlintrc.json",
|
|
29
|
+
"plugin.js",
|
|
30
|
+
"ui-react.json",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
],
|
|
33
|
+
"type": "module",
|
|
34
|
+
"exports": {
|
|
35
|
+
"./.oxlintrc.json": "./.oxlintrc.json",
|
|
36
|
+
"./plugin.js": "./plugin.js",
|
|
37
|
+
"./ui-react.json": "./ui-react.json",
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"lint": "oxlint -c ../../.oxlintrc.json --type-aware --deny-warnings --ignore-pattern 'fixtures/**' && bun ../../scripts/check-slop.ts",
|
|
43
|
+
"test": "bun scripts/data.ts && vitest run --dir test",
|
|
44
|
+
"pack-check": "bun scripts/data.ts && npm pack --dry-run --json --ignore-scripts | bun scripts/pack-files.ts && bun scripts/consumer.ts",
|
|
45
|
+
"prepack": "bun scripts/data.ts"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/bun": "1.4.4",
|
|
49
|
+
"vitest": "5.1.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"oxlint": "1.94.0"
|
|
53
|
+
},
|
|
54
|
+
"nx": {
|
|
55
|
+
"name": "oxlint-ui"
|
|
56
|
+
}
|
|
57
|
+
}
|
package/plugin.js
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The UISlash rules, loaded by oxlint's `jsPlugins` as `uislash`: the hard rules the `ui-review`
|
|
5
|
+
* pull request check runs on a diff, here on the AST of every file an app lints. Plain ESM over
|
|
6
|
+
* the ESTree AST oxlint hands an ESLint-style plugin. Each message says what to use instead.
|
|
7
|
+
*
|
|
8
|
+
* `ui-react.json` (written at pack time from the `@slashsuite/ui-react` source) holds the
|
|
9
|
+
* components it exports, its palette and the colour and element tables.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const DATA = new URL("./ui-react.json", import.meta.url);
|
|
13
|
+
if (!existsSync(DATA)) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
"@slashsuite/oxlint-ui: ui-react.json is missing. It is written when the package is packed; in the uislash repo, run `bun packages/oxlint-ui/scripts/data.ts`.",
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
const data = JSON.parse(readFileSync(DATA, "utf8"));
|
|
19
|
+
const components = new Set(data.components);
|
|
20
|
+
const palette = new Map(Object.entries(data.palette));
|
|
21
|
+
|
|
22
|
+
const UI_PACKAGE = /^@(?:slashsuite|hackcove)\/ui-react$/;
|
|
23
|
+
const STYLING = new Set(["className", "class", "class:list", "style"]);
|
|
24
|
+
const JSX_FILE = /\.[cm]?[jt]sx$/;
|
|
25
|
+
|
|
26
|
+
const UTILITY = "(?:bg|text|border|outline|ring|accent|fill|stroke|decoration|divide)";
|
|
27
|
+
const HUES =
|
|
28
|
+
"white|black|slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose";
|
|
29
|
+
const COLOUR = new RegExp(
|
|
30
|
+
`(?<![\\w-])(?:[a-z-]+:)*${UTILITY}-(?:${HUES})(?:-\\d{2,3})?(?:\\/\\d+)?(?![\\w-])`,
|
|
31
|
+
"g",
|
|
32
|
+
);
|
|
33
|
+
const ARBITRARY_COLOUR = new RegExp(
|
|
34
|
+
`(?<![\\w-])(?:[a-z-]+:)*${UTILITY}-\\[(?:#[0-9a-fA-F]{3,8}|(?:rgb|hsl|oklch|oklab|color)\\([^\\]]*\\))\\]`,
|
|
35
|
+
"g",
|
|
36
|
+
);
|
|
37
|
+
const DARK = /(?<![\w-])dark:[\w[\]-]/;
|
|
38
|
+
const HEX = "(?<!url\\()#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3,4})(?![\\w-])";
|
|
39
|
+
const FUNCTION = "(?<![\\w-])(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\\(";
|
|
40
|
+
const NAMED = `(?<![\\w-])(?:${data.namedColours.join("|")})(?![\\w-])`;
|
|
41
|
+
const STYLE_COLOUR = new RegExp(`${HEX}|${FUNCTION}|${NAMED}`, "gi");
|
|
42
|
+
|
|
43
|
+
const rule = (description, create) => ({
|
|
44
|
+
meta: { type: "problem", docs: { description } },
|
|
45
|
+
create,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/** A JSX name as written: `Button`, `svg:g`, `UI.Button`. */
|
|
49
|
+
function jsxName(node) {
|
|
50
|
+
if (node.type === "JSXIdentifier") return node.name;
|
|
51
|
+
if (node.type === "JSXNamespacedName") return `${node.namespace.name}:${node.name.name}`;
|
|
52
|
+
if (node.type === "JSXMemberExpression") return `${jsxName(node.object)}.${node.property.name}`;
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The local names a file imports, as values, from `@slashsuite/ui-react`. */
|
|
57
|
+
function importedFromUi(program) {
|
|
58
|
+
const names = new Set();
|
|
59
|
+
for (const statement of program.body) {
|
|
60
|
+
if (statement.type !== "ImportDeclaration" || statement.importKind === "type") continue;
|
|
61
|
+
if (!UI_PACKAGE.test(statement.source.value)) continue;
|
|
62
|
+
for (const specifier of statement.specifiers) {
|
|
63
|
+
if (specifier.type === "ImportSpecifier" && specifier.importKind !== "type") {
|
|
64
|
+
names.add(specifier.local.name);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return names;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const SKIPPED_KEYS = new Set(["parent", "loc", "range"]);
|
|
72
|
+
const isNode = (value) =>
|
|
73
|
+
value !== null && typeof value === "object" && typeof value.type === "string";
|
|
74
|
+
|
|
75
|
+
/** The AST nodes directly under `node`. */
|
|
76
|
+
function childrenOf(node) {
|
|
77
|
+
return Object.entries(node)
|
|
78
|
+
.filter(([key]) => !SKIPPED_KEYS.has(key))
|
|
79
|
+
.flatMap(([, value]) => (Array.isArray(value) ? value : [value]))
|
|
80
|
+
.filter(isNode);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The text of a string literal or a template literal's text, as written; `undefined` otherwise. */
|
|
84
|
+
function stringText(node) {
|
|
85
|
+
if (node.type === "Literal" && typeof node.value === "string") return node.raw ?? node.value;
|
|
86
|
+
return node.type === "TemplateElement" ? node.value.raw : undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Each string piece of the code under `node`: string literals and template literal text. */
|
|
90
|
+
function stringsUnder(node, found = []) {
|
|
91
|
+
const text = stringText(node);
|
|
92
|
+
if (text !== undefined) found.push({ text, line: node.loc.start.line, node });
|
|
93
|
+
for (const child of childrenOf(node)) stringsUnder(child, found);
|
|
94
|
+
return found;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Every match of `pattern` in the strings, by the line it sits on, keeping the first node. */
|
|
98
|
+
function matchesByLine(strings, pattern, byLine = new Map()) {
|
|
99
|
+
for (const { text, line, node } of strings) {
|
|
100
|
+
for (const match of text.matchAll(pattern)) {
|
|
101
|
+
const at = line + (text.slice(0, match.index).match(/\n/g)?.length ?? 0);
|
|
102
|
+
const entry = byLine.get(at) ?? { node, found: [] };
|
|
103
|
+
entry.found.push(match[0]);
|
|
104
|
+
byLine.set(at, entry);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return byLine;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Report one message per line, at that line. */
|
|
111
|
+
function reportByLine(context, byLine, message) {
|
|
112
|
+
for (const [line, { found }] of [...byLine].toSorted(([a], [b]) => a - b)) {
|
|
113
|
+
context.report({
|
|
114
|
+
message: message(found),
|
|
115
|
+
loc: { start: { line, column: 0 }, end: { line, column: 0 } },
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** A rule that reads every string piece in the file once it is parsed. */
|
|
121
|
+
const onStrings = (description, check) =>
|
|
122
|
+
rule(description, (context) => ({
|
|
123
|
+
"Program:exit"(program) {
|
|
124
|
+
check(context, stringsUnder(program));
|
|
125
|
+
},
|
|
126
|
+
}));
|
|
127
|
+
|
|
128
|
+
const styleBlock = rule("no <style> element in JSX", (context) => ({
|
|
129
|
+
JSXOpeningElement(node) {
|
|
130
|
+
if (jsxName(node.name) !== "style") return;
|
|
131
|
+
context.report({
|
|
132
|
+
node,
|
|
133
|
+
message:
|
|
134
|
+
"<style> block. UISlash apps write no CSS of their own: compose @slashsuite/ui-react parts, and ask uislash for what is missing.",
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
}));
|
|
138
|
+
|
|
139
|
+
const rawColour = onStrings("no stock Tailwind colour utility", (context, strings) => {
|
|
140
|
+
const stock = matchesByLine(strings, COLOUR);
|
|
141
|
+
const arbitrary = matchesByLine(strings, ARBITRARY_COLOUR);
|
|
142
|
+
const byLine = new Map(stock);
|
|
143
|
+
for (const [line, entry] of arbitrary) {
|
|
144
|
+
const known = byLine.get(line);
|
|
145
|
+
byLine.set(line, known ? { ...known, found: [...known.found, ...entry.found] } : entry);
|
|
146
|
+
}
|
|
147
|
+
reportByLine(context, byLine, (used) => {
|
|
148
|
+
const roles = [...new Set(used.flatMap((utility) => palette.get(utility) ?? []))];
|
|
149
|
+
const role = roles.length === 0 ? "" : ` (the ${roles.join(", ")} role of the palette)`;
|
|
150
|
+
return `Raw colour utility ${used.map((u) => `\`${u}\``).join(", ")}${role}. Colour belongs to the theme and to @slashsuite/ui-react parts; use the part that carries it, or ask uislash for one.`;
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const darkVariant = onStrings("no dark: variant", (context, strings) => {
|
|
155
|
+
const byLine = new Map();
|
|
156
|
+
for (const { text, line, node } of strings) {
|
|
157
|
+
text.split("\n").forEach((part, i) => {
|
|
158
|
+
if (DARK.test(part) && !byLine.has(line + i)) byLine.set(line + i, { node, found: [] });
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
reportByLine(
|
|
162
|
+
context,
|
|
163
|
+
byLine,
|
|
164
|
+
() =>
|
|
165
|
+
"`dark:` variant. A theme decides light or dark; an app never branches on it. Remove the variant.",
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const stylingProp = rule("no className or style on a @slashsuite/ui-react component", (context) => {
|
|
170
|
+
let imported = new Set();
|
|
171
|
+
return {
|
|
172
|
+
Program(program) {
|
|
173
|
+
imported = importedFromUi(program);
|
|
174
|
+
},
|
|
175
|
+
JSXOpeningElement(node) {
|
|
176
|
+
const component = jsxName(node.name);
|
|
177
|
+
if (!imported.has(component)) return;
|
|
178
|
+
for (const attribute of node.attributes) {
|
|
179
|
+
if (attribute.type !== "JSXAttribute") continue;
|
|
180
|
+
const prop = jsxName(attribute.name);
|
|
181
|
+
if (!STYLING.has(prop)) continue;
|
|
182
|
+
context.report({
|
|
183
|
+
node: attribute,
|
|
184
|
+
message: `\`${prop}\` on <${component}>. @slashsuite/ui-react components take no styling props: compose the parts, or ask uislash for the variant you need.`,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const duplicateMessage = (name) =>
|
|
192
|
+
`Local component \`${name}\` has the same name as an @slashsuite/ui-react export. If it does the same job, import the UISlash one, and if that one does not fit, ask uislash for what is missing rather than building a look-alike. If it is a different thing, rename it so it is not mistaken for the UISlash one.`;
|
|
193
|
+
|
|
194
|
+
const WRAPPERS = new Set(["memo", "forwardRef"]);
|
|
195
|
+
|
|
196
|
+
/** An initialiser that makes a component: a function, `memo(…)`, `forwardRef(…)`, `React.…`. */
|
|
197
|
+
function makesComponent(init) {
|
|
198
|
+
if (!init) return false;
|
|
199
|
+
if (init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression") return true;
|
|
200
|
+
const callee = init.type === "CallExpression" ? init.callee : init;
|
|
201
|
+
if (callee.type === "Identifier") return init !== callee && WRAPPERS.has(callee.name);
|
|
202
|
+
return callee.type === "MemberExpression" && callee.object.name === "React";
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const duplicateComponent = rule(
|
|
206
|
+
"no local component named like a @slashsuite/ui-react export",
|
|
207
|
+
(context) => {
|
|
208
|
+
let imported = new Set();
|
|
209
|
+
const check = (node, name) => {
|
|
210
|
+
if (components.has(name) && !imported.has(name)) {
|
|
211
|
+
context.report({ node, message: duplicateMessage(name) });
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
return {
|
|
215
|
+
Program(program) {
|
|
216
|
+
imported = importedFromUi(program);
|
|
217
|
+
const stem = /([^/\\]+?)(?:\.[^./\\]+)$/.exec(context.filename)?.[1] ?? "";
|
|
218
|
+
if (components.has(stem)) {
|
|
219
|
+
context.report({
|
|
220
|
+
message: duplicateMessage(stem),
|
|
221
|
+
loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
FunctionDeclaration(node) {
|
|
226
|
+
if (node.id) check(node, node.id.name);
|
|
227
|
+
},
|
|
228
|
+
ClassDeclaration(node) {
|
|
229
|
+
if (node.id) check(node, node.id.name);
|
|
230
|
+
},
|
|
231
|
+
VariableDeclarator(node) {
|
|
232
|
+
if (node.id.type === "Identifier" && makesComponent(node.init)) check(node, node.id.name);
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
},
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
const inlineColour = rule("no colour literal in a style value", (context) => ({
|
|
239
|
+
JSXAttribute(node) {
|
|
240
|
+
if (jsxName(node.name) !== "style" || !node.value) return;
|
|
241
|
+
const byLine = matchesByLine(stringsUnder(node.value), STYLE_COLOUR);
|
|
242
|
+
for (const entry of byLine.values()) {
|
|
243
|
+
entry.found = entry.found.map((colour) => colour.replace(/\($/, "(…)"));
|
|
244
|
+
}
|
|
245
|
+
reportByLine(
|
|
246
|
+
context,
|
|
247
|
+
byLine,
|
|
248
|
+
(colours) =>
|
|
249
|
+
`Colour ${colours.map((c) => `\`${c}\``).join(", ")} in a \`style\` value. Colour belongs to the theme and to @slashsuite/ui-react parts: use the part (or its \`tone\`) that carries it, or ask uislash for one.`,
|
|
250
|
+
);
|
|
251
|
+
},
|
|
252
|
+
}));
|
|
253
|
+
|
|
254
|
+
/** The part to use for a raw element, `undefined` when the element is allowed. */
|
|
255
|
+
function partFor(element, inputType) {
|
|
256
|
+
if (!Object.hasOwn(data.rawElements, element)) return undefined;
|
|
257
|
+
if (element !== "input" || inputType === undefined) return data.rawElements[element];
|
|
258
|
+
if (data.plainInputs.includes(inputType)) return undefined;
|
|
259
|
+
return Object.hasOwn(data.inputTypes, inputType) ? data.inputTypes[inputType] : "`Input`";
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** An `<input>`'s `type`, when it is written as a plain string. */
|
|
263
|
+
function inputTypeOf(node) {
|
|
264
|
+
const type = node.attributes.find((a) => a.type === "JSXAttribute" && jsxName(a.name) === "type");
|
|
265
|
+
const value = type?.value;
|
|
266
|
+
return value?.type === "Literal" && /^[\w-]+$/.test(value.value) ? value.value : undefined;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const rawElement = rule("no raw HTML element that has a @slashsuite/ui-react part", (context) => ({
|
|
270
|
+
JSXOpeningElement(node) {
|
|
271
|
+
if (!JSX_FILE.test(context.filename)) return;
|
|
272
|
+
const element = jsxName(node.name);
|
|
273
|
+
const part = partFor(element, inputTypeOf(node));
|
|
274
|
+
if (part === undefined) return;
|
|
275
|
+
context.report({
|
|
276
|
+
node,
|
|
277
|
+
message: `Raw <${element}>. @slashsuite/ui-react has the part for it: use ${part}, which carries the theme, focus and states. If it does not fit, ask uislash for the variant rather than building one.`,
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
}));
|
|
281
|
+
|
|
282
|
+
export default {
|
|
283
|
+
meta: { name: "uislash" },
|
|
284
|
+
rules: {
|
|
285
|
+
"style-block": styleBlock,
|
|
286
|
+
"raw-colour": rawColour,
|
|
287
|
+
"dark-variant": darkVariant,
|
|
288
|
+
"styling-prop": stylingProp,
|
|
289
|
+
"duplicate-component": duplicateComponent,
|
|
290
|
+
"inline-colour": inlineColour,
|
|
291
|
+
"raw-element": rawElement,
|
|
292
|
+
},
|
|
293
|
+
};
|
package/ui-react.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"components":["AppShell","AppShellBrand","ArticleLayout","Audio","Avatar","AvatarStack","Badge","BottomSheet","Breadcrumbs","BulletItem","BulletList","Button","ButtonGroup","CallToAction","Callout","Caption","Card","CardGrid","CardGridRow","CartButton","CenteredLayout","ChatComposer","ChatMessage","ChatThread","Checkbox","Cluster","ClusterGrow","Code","CodeBlock","CodeExample","ColourSchemeToggle","ColourSwatch","Combobox","ConfirmDialog","Container","CopyButton","CopyLine","DateField","DateRangePicker","DateTimeField","DetailLayout","Dialog","Disclosure","Display","Divider","DocsLayout","Drawer","EmbedFrame","EmptyState","ErrorPage","Field","FieldDialog","Fieldset","FileDrop","FlowDiagram","Forbidden","FormGrid","FormLayout","FormRow","FormRowField","FullBleedLayout","Hero","Icon","IconButton","Image","InlineEdit","Input","Kbd","KeyValue","KeyValueList","Lead","Legend","Lightbox","LinkProvider","ListLayout","ListRow","Maintenance","Mark","Markdown","MediaTile","Menu","MetaList","Morph","NavigationProgress","NotFound","NumberField","Offline","OutlineRegion","Overline","PageFade","PageHeader","PageHeading","Pagination","Pill","Popover","Price","ProductTile","ProgressBar","PromoBanner","Prose","ProseLayout","Radio","RadioGroup","RegionFrame","ScrollStrip","Section","SectionHeading","SegmentedControl","Select","Show","SideColumn","SidebarLayout","SiteFooter","SiteSearch","Slider","SortableItem","SortableList","SortableSection","SplitBar","Stack","StackedBar","StatTile","StateMachine","Step","Stepper","Steps","StickyBar","SubsectionHeading","Switch","Table","TableBody","TableCell","TableEditCell","TableExpandCell","TableFoot","TableGroupRow","TableHead","TableHeaderCell","TableOfContents","TableRow","Tabs","Text","TextLink","Textarea","Timeline","TimelineItem","ToastRegion","TrendChart","Video"],"palette":{"bg-gray-50":"canvas","bg-white":"surface","bg-slate-50":"subtle","hover:bg-slate-50":"subtle","border-slate-50":"subtle","bg-slate-100":"inset","hover:bg-slate-100":"inset","bg-slate-200":"skeleton","backdrop:bg-slate-900/35":"scrim","bg-black/90":"media-scrim","text-white":"media-scrim","text-white/70":"media-scrim","hover:bg-white/10":"media-scrim","focus-visible:outline-white":"media-scrim","bg-white/100":"media-matte","bg-zinc-50":"media-mat","bg-white/95":"header","border-slate-200":"line","border-slate-200/70":"line","border-slate-300":"line","text-slate-900":"ink","text-slate-700":"ink","text-slate-600":"ink","text-slate-500":"ink","text-slate-400":"ink","text-slate-300":"ink","placeholder:text-slate-400":"ink","bg-violet-600":"identity","hover:bg-violet-700":"accent","text-violet-50":"accent","text-violet-600":"accent","text-violet-700":"accent","hover:text-violet-700":"accent","bg-violet-50":"accent","hover:bg-violet-50":"accent","border-violet-600":"accent","hover:border-violet-400":"accent","outline-violet-600":"accent","target:outline-violet-600":"accent","focus-visible:outline-violet-600":"accent","has-focus-visible:outline-violet-600":"accent","accent-violet-600":"accent","bg-orange-600":"identity","bg-cyan-600":"identity","bg-emerald-600":"positive","bg-sky-600":"identity","bg-pink-600":"identity","bg-amber-600":"identity","bg-orange-100":"peer","bg-violet-100":"peer","bg-sky-100":"peer","bg-emerald-100":"peer","bg-amber-100":"peer","bg-blue-100":"peer","border-orange-300":"peer","border-violet-300":"peer","border-sky-300":"peer","border-emerald-300":"peer","border-amber-300":"peer","border-blue-300":"peer","bg-emerald-50":"positive","hover:bg-emerald-50":"positive","hover:bg-emerald-700":"positive","text-emerald-50":"positive","text-emerald-700":"positive","text-emerald-800":"positive","border-emerald-200":"positive","border-emerald-600":"positive","bg-amber-50":"warn","text-amber-700":"warn","text-amber-800":"warn","border-amber-200":"warn","border-amber-600":"warn","bg-red-50":"danger","hover:bg-red-50":"danger","bg-red-600":"danger","hover:bg-red-700":"danger","text-red-50":"danger","text-red-700":"danger","text-red-800":"danger","text-red-900":"danger","border-red-200":"danger","aria-invalid:border-red-200":"danger","has-aria-invalid:border-red-200":"danger","user-invalid:border-red-200":"danger","has-user-invalid:border-red-200":"danger","border-red-600":"danger","bg-blue-50":"info","text-blue-700":"info","text-blue-800":"info","border-blue-200":"info","bg-sky-50":"sky","text-sky-700":"sky","text-neutral-500":"viz","text-purple-700":"viz","text-indigo-600":"categorical","text-orange-600":"categorical","text-teal-600":"categorical","text-pink-600":"categorical","text-lime-600":"categorical","text-fuchsia-600":"categorical","text-rose-600":"categorical","text-yellow-600":"categorical","bg-indigo-400/25":"glow","bg-teal-400/25":"glow","bg-rose-400/25":"glow"},"namedColours":["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"],"rawElements":{"button":"`Button` (or `IconButton`)","input":"`Input` (or `NumberField`, `DateField`, `Checkbox`, `Switch`, `RadioGroup`, `Slider`)","select":"`Select` (or `Combobox`)","textarea":"`Textarea`","dialog":"`Dialog` (or `ConfirmDialog`, `Drawer`, `BottomSheet`)"},"inputTypes":{"checkbox":"`Checkbox` (or `Switch`)","radio":"`RadioGroup` with `Radio`","range":"`Slider`","number":"`NumberField`","date":"`DateField`","datetime-local":"`DateTimeField`","file":"`FileDrop`","submit":"`Button`","button":"`Button`","reset":"`Button`"},"plainInputs":["hidden"]}
|