@actioneer/ads-lint 0.1.0 → 1.0.61
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 +33 -3
- package/bin/ads-lint.mjs +4 -0
- package/package.json +2 -2
- package/src/config.mjs +57 -1
- package/src/index.mjs +11 -0
- package/src/jsx.mjs +135 -0
- package/src/rules/buttons.mjs +76 -0
- package/src/rules/charts.mjs +43 -0
- package/src/rules/collections.mjs +273 -0
- package/src/rules/controls.mjs +157 -0
- package/src/rules/elevation.mjs +118 -0
- package/src/rules/empty-states.mjs +99 -0
- package/src/rules/modals.mjs +204 -0
- package/src/rules/motion.mjs +14 -6
- package/src/rules/recipes.mjs +121 -0
- package/src/rules/selection.mjs +76 -0
- package/src/rules/tables.mjs +253 -0
- package/src/runner.mjs +11 -1
- package/src/version-check.mjs +76 -0
package/README.md
CHANGED
|
@@ -8,6 +8,19 @@ It runs in two tiers: the **TypeScript compiler API** when `typescript` is
|
|
|
8
8
|
resolvable (exact import analysis), degrading to a **regex parser** when it
|
|
9
9
|
isn't — so it works in a fresh repo before `npm i`.
|
|
10
10
|
|
|
11
|
+
## Install it at the same version as `@actioneer/ads`
|
|
12
|
+
|
|
13
|
+
The linter ships with every ADS release, at the same version number. Install
|
|
14
|
+
and update the two together:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -D @actioneer/ads-lint@<your @actioneer/ads version>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
An older linter skips every rule added since it was published. When the run
|
|
21
|
+
finds a newer `@actioneer/ads` installed it reports `ads-lint-stale` as an
|
|
22
|
+
error (`versionCheck: false` in the config turns this off for a deliberate pin).
|
|
23
|
+
|
|
11
24
|
## What it checks
|
|
12
25
|
|
|
13
26
|
| Rule | Severity | Principle |
|
|
@@ -15,11 +28,25 @@ isn't — so it works in a fresh repo before `npm i`.
|
|
|
15
28
|
| `external-ui-import` — importing radix/mui/assistant-ui/etc. directly | error | P7 ADS-first |
|
|
16
29
|
| `deep-import` — reaching past the barrel (`@actioneer/ads/button`) | error | P7 |
|
|
17
30
|
| `barrel-default-import` / `-namespace-import` / `-aliased-import` | error | P7 |
|
|
18
|
-
| `icon-package-import` — importing
|
|
31
|
+
| `icon-package-import` — importing Phosphor or another icon package outside the registry | error | P4 icons |
|
|
19
32
|
| `hardcoded-hex` — a raw `#rrggbb` in code | error | tokens-only |
|
|
20
33
|
| `arbitrary-color` — `bg-[#fff]` / `text-[rgb(...)]` | error | tokens-only |
|
|
21
34
|
| `arbitrary-dimension` — `w-[13px]` / `gap-[1.5rem]` | warn | tokens-only |
|
|
22
|
-
| Motion: `unbounded-transition`, `sluggish-easing`, `zero-scale-entrance`, `undersized-zoom-entrance`, `
|
|
35
|
+
| Motion: `unbounded-transition`, `sluggish-easing`, `zero-scale-entrance`, `undersized-zoom-entrance`, `legacy-motion-token`, `raw-spring-config`, `layout-property-transition`, `layout-keyframe-disclosure` | error | P3 motion |
|
|
36
|
+
| Tables: `table-column-icon` (any `icon=` but `{null}`/`{undefined}`, or a glyph child), `table-cell-stacked` (`<br>`, a `flex-col`/`grid`/`space-y-*` stack of two, two children one of them block-level, an `<Avatar>`), `table-pagination` ("Page N of", "Rows per page", Previous + Next, "Next page" after a `Table`), plus the actions-column and record-name rules | error | tables |
|
|
37
|
+
| Collections: `collection-toolbar-missing` (a search/filter row or a header Search button with no `CollectionToolbar`), `search-full-width` (a full-width field typed search, led by the Search glyph, or labelled "Search…"), `page-content-top-padding` (class or `style` top spacing on the content or its first wrapper; a toolbar with no gap under an `mb-0` header) | error | P11, collection screens |
|
|
38
|
+
| Recipes: `call-panel-hand-rolled` (a Drawer with a Transcript or AudioWaveform — use `CallPanel`), `filter-menu-hand-rolled` (a Popover of Checkboxes — use the column filter or `Filters`), `filter-chip-clear-button` (a Chip with its own clear button — use `Chip onClose`), `script-opening-line-hand-rolled` (use `ScriptOpeningLine`), `script-character-limit` ("893 / 2,000,000 chars") | error | screen recipes |
|
|
39
|
+
| `ads-lint-stale` — this linter is older than the installed `@actioneer/ads` | error | release lockstep |
|
|
40
|
+
| `collection-toolbar-icon-action` — an icon-only `Button` / `TooltipIconButton` in `CollectionToolbar actions` that is not `SearchDisclosure`, `Filters` or `TableColumnsMenu` (a setting such as Caller numbers is a labelled header button) | error | collection screens, workspace setting modals |
|
|
41
|
+
| `modal-footer-done` — a `ModalFooter` whose only action is a `Button` (or `ModalClose`) labelled Done, Close, OK or Got it | error | workspace setting modals |
|
|
42
|
+
| `switch-on-off-text` — literal "On"/"Off" (text, a string, or a `cond ? "On" : "Off"` expression, bare or in a wrapper) beside a `Switch`, or as its label | error | P8 |
|
|
43
|
+
| `field-lock-icon` — a `Lock*` glyph in a `Field`/`InputField` `actions`, `label` or `info` (including through a local `const`) | error | campaign setup rail |
|
|
44
|
+
| `stepper-as-status` — a `Stepper` inside a `TableCell`, `DrawerHeader`, `DrawerMeta`, `BodyPageHeader` or `Breadcrumbs meta` | error | P8, memory surfaces |
|
|
45
|
+
| `shadow-ask-misuse` — the `shadow-ask` utility in a `className`, a `cn`/`clsx`/`cva`/`twMerge` string or a CSS `@apply` anywhere but `src/components/ask-actioneer.tsx` (`elevation.askShadowAllow`); prose naming the token is not flagged | error | elevation (principle 2) |
|
|
46
|
+
| `empty-state-table-header` — an `EmptyState` inside a `Table`, `TableBody` or `TableCell`: with nothing to list the table is not drawn (`emptyStates.tableAllow` exempts the library) | error | P8, empty states |
|
|
47
|
+
| `shadow-static-surface` — `shadow-card` on a `div`/`section`/`Card` nobody can press (no `onClick`, `href`, `isPressable`, `role="button"`) | error | elevation |
|
|
48
|
+
| `selected-edge-action` — a strong `border`/`ring`/`outline` on a selection prefix (`aria-selected:`, `data-[state=on]:` …) or in a `selected ? "…"` / `isActive && "…"` class | error | selection |
|
|
49
|
+
| `chart-dual-axis` (any `dualAxis` but `{false}`), `export-button-no-icon` (`Export`, `{"Export"}`, `{t("export")}`, "Download CSV"), `empty-state-no-description` (missing or empty) | error | charts, P8 |
|
|
23
50
|
|
|
24
51
|
Errors fail the run (exit 1); warnings don't unless `--strict`.
|
|
25
52
|
|
|
@@ -46,7 +73,10 @@ export default {
|
|
|
46
73
|
|
|
47
74
|
The ADS library repo itself runs in **library-dev mode** (see this repo's
|
|
48
75
|
`ads-lint.config.mjs`): `libraryRoot: "src/components"` exempts the library's own
|
|
49
|
-
internals, and `libraryPackage: "@/components"` matches the local alias.
|
|
76
|
+
internals, and `libraryPackage: "@/components"` matches the local alias. Its
|
|
77
|
+
`motion.allow` contains only `src/lib/motion.ts`, the sanctioned definition
|
|
78
|
+
site for raw spring parameters; consumers import named presets from
|
|
79
|
+
`@actioneer/ads`.
|
|
50
80
|
|
|
51
81
|
## Wiring into a consumer repo
|
|
52
82
|
|
package/bin/ads-lint.mjs
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import process from "node:process";
|
|
15
15
|
import { loadConfig } from "../src/config.mjs";
|
|
16
16
|
import { resolveFiles, lintFiles, formatFindings } from "../src/runner.mjs";
|
|
17
|
+
import { staleLinterFinding } from "../src/version-check.mjs";
|
|
17
18
|
|
|
18
19
|
function parseArgs(argv) {
|
|
19
20
|
const opts = { files: [], staged: false, diff: null, all: false, strict: false, quiet: false };
|
|
@@ -53,6 +54,9 @@ async function main() {
|
|
|
53
54
|
const cfg = await loadConfig(cwd);
|
|
54
55
|
const files = resolveFiles(opts, cfg, cwd);
|
|
55
56
|
const { findings, fileCount } = lintFiles(files, cfg, cwd);
|
|
57
|
+
// An older linter than the installed ADS skips every newer rule: say so first.
|
|
58
|
+
const stale = staleLinterFinding(cwd, cfg);
|
|
59
|
+
if (stale) findings.unshift(stale);
|
|
56
60
|
|
|
57
61
|
const errors = findings.filter((f) => f.severity === "error");
|
|
58
62
|
const warns = findings.filter((f) => f.severity === "warn");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@actioneer/ads-lint",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Design linter for the Actioneer Design System (ADS 1.0). Flags deviations from ADS principles on changed files.",
|
|
3
|
+
"version": "1.0.61",
|
|
4
|
+
"description": "Design linter for the Actioneer Design System (ADS 1.0). Ships in lockstep with @actioneer/ads: install the same version. Flags deviations from ADS principles on changed files.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"ads-lint": "bin/ads-lint.mjs"
|
package/src/config.mjs
CHANGED
|
@@ -22,6 +22,10 @@ export const DEFAULT_CONFIG = {
|
|
|
22
22
|
// File extensions the runner will read.
|
|
23
23
|
extensions: [".ts", ".tsx", ".css"],
|
|
24
24
|
|
|
25
|
+
// Report an error when the installed @actioneer/ads is newer than this
|
|
26
|
+
// linter (they ship in lockstep). false only for a deliberate pin.
|
|
27
|
+
versionCheck: true,
|
|
28
|
+
|
|
25
29
|
// Root walked by `--all` when no explicit files are passed.
|
|
26
30
|
root: "src",
|
|
27
31
|
|
|
@@ -60,7 +64,12 @@ export const DEFAULT_CONFIG = {
|
|
|
60
64
|
"^react-toastify$",
|
|
61
65
|
],
|
|
62
66
|
// Icon packages may only be imported from the icon registry (principle 4).
|
|
63
|
-
bannedIconPackages: [
|
|
67
|
+
bannedIconPackages: [
|
|
68
|
+
"^@phosphor-icons/react$",
|
|
69
|
+
"^@hugeicons/",
|
|
70
|
+
"^lucide-react$",
|
|
71
|
+
"^@fortawesome/",
|
|
72
|
+
],
|
|
64
73
|
// File(s) allowed to import icon packages directly (the ADS registry).
|
|
65
74
|
iconRegistryAllowlist: ["src/lib/icons.tsx"],
|
|
66
75
|
// Sanctioned package subpaths a consumer MAY import directly (the design
|
|
@@ -76,6 +85,53 @@ export const DEFAULT_CONFIG = {
|
|
|
76
85
|
allow: [],
|
|
77
86
|
},
|
|
78
87
|
|
|
88
|
+
modals: {
|
|
89
|
+
enabled: true,
|
|
90
|
+
// Globs where a Modal may set its own height (none by default).
|
|
91
|
+
allow: [],
|
|
92
|
+
// Two-pane browsers whose header is a structural bar with a full-width
|
|
93
|
+
// hairline under it (ChatHistory, user-mandated 2026-11-28).
|
|
94
|
+
structuralHeaderAllow: ["src/components/chat-history.tsx"],
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
// Screens never draw a table around an EmptyState (user-mandated 2026-11-29).
|
|
98
|
+
// The library authors Table itself; everything else draws the EmptyState in place of the table.
|
|
99
|
+
emptyStates: {
|
|
100
|
+
enabled: true,
|
|
101
|
+
allow: [],
|
|
102
|
+
tableAllow: ["src/components/**"],
|
|
103
|
+
},
|
|
104
|
+
buttons: { enabled: true, allow: [] },
|
|
105
|
+
// Selected items take the subtle T5 edge (border-border-selected).
|
|
106
|
+
selection: { enabled: true, allow: [] },
|
|
107
|
+
// shadow-ask is the AskActioneer button's own lift (user-mandated 2026-11-29):
|
|
108
|
+
// only the component that draws that button may use it.
|
|
109
|
+
elevation: { enabled: true, allow: [], askShadowAllow: ["src/components/ask-actioneer.tsx"] },
|
|
110
|
+
// Switch labels, lock glyphs on fields, a Stepper drawn as a status
|
|
111
|
+
// (user-mandated 2026-11-28). The Switch and Stepper docs show the bare
|
|
112
|
+
// primitives in their own states.
|
|
113
|
+
controls: { enabled: true, allow: [] },
|
|
114
|
+
// The library authors the row itself; the SearchDisclosure and Tabs docs show
|
|
115
|
+
// those primitives on their own.
|
|
116
|
+
collections: {
|
|
117
|
+
enabled: true,
|
|
118
|
+
allow: [
|
|
119
|
+
"src/components/**",
|
|
120
|
+
"src/showcase/pages/search-bar.tsx",
|
|
121
|
+
"src/showcase/pages/tabs.tsx",
|
|
122
|
+
// The showcase's own navigation search is the purpose of that rail.
|
|
123
|
+
"src/showcase/App.tsx",
|
|
124
|
+
// Navigation prototypes explore sidebar layouts, not product screens.
|
|
125
|
+
"src/prototypes/**",
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
// The ComboChart showcase and stories document the deprecated prop.
|
|
129
|
+
charts: { enabled: true, allow: ["src/showcase/**", "src/stories/**"] },
|
|
130
|
+
tables: {
|
|
131
|
+
enabled: true,
|
|
132
|
+
allow: [],
|
|
133
|
+
},
|
|
134
|
+
|
|
79
135
|
literals: {
|
|
80
136
|
// Bare hex colors in .ts/.tsx (e.g. "#0a0a0b") — should be a token.
|
|
81
137
|
hex: true,
|
package/src/index.mjs
CHANGED
|
@@ -6,3 +6,14 @@ export { resolveFiles, lintFiles, formatFindings } from "./runner.mjs";
|
|
|
6
6
|
export { lintImports } from "./rules/imports.mjs";
|
|
7
7
|
export { lintMotion } from "./rules/motion.mjs";
|
|
8
8
|
export { lintLiterals } from "./rules/literals.mjs";
|
|
9
|
+
export { lintModals, FOOTER_RULES, CONFIRM_RULES } from "./rules/modals.mjs";
|
|
10
|
+
export { lintTables } from "./rules/tables.mjs";
|
|
11
|
+
export { lintEmptyStates } from "./rules/empty-states.mjs";
|
|
12
|
+
export { lintButtons, BUTTON_RULES } from "./rules/buttons.mjs";
|
|
13
|
+
export { lintCharts } from "./rules/charts.mjs";
|
|
14
|
+
export { lintCollections, COLLECTION_RULES } from "./rules/collections.mjs";
|
|
15
|
+
export { lintSelection, SELECTION_RULES } from "./rules/selection.mjs";
|
|
16
|
+
export { lintElevation, ELEVATION_RULES } from "./rules/elevation.mjs";
|
|
17
|
+
export { lintControls, CONTROL_RULES } from "./rules/controls.mjs";
|
|
18
|
+
export { staleLinterFinding, compareVersions, VERSION_RULE } from "./version-check.mjs";
|
|
19
|
+
export { lintRecipes, RECIPE_RULES } from "./rules/recipes.mjs";
|
package/src/jsx.mjs
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Small JSX source helpers shared by the rules. They read source text, not an
|
|
2
|
+
// AST: attribute expressions (`onSort={() => a > b}`), strings and template
|
|
3
|
+
// literals are skipped so a `>` inside them never ends a tag.
|
|
4
|
+
|
|
5
|
+
/** The opening tag starting at `start` (a `<`), with attribute expressions skipped. */
|
|
6
|
+
export function openingTag(source, start) {
|
|
7
|
+
let depth = 0;
|
|
8
|
+
let quote = null;
|
|
9
|
+
for (let i = start + 1; i < source.length; i++) {
|
|
10
|
+
const c = source[i];
|
|
11
|
+
if (quote) {
|
|
12
|
+
if (c === quote) quote = null;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (c === '"' || c === "'" || c === "`") quote = c;
|
|
16
|
+
else if (c === "{") depth++;
|
|
17
|
+
else if (c === "}") depth--;
|
|
18
|
+
else if (c === ">" && depth === 0) return source.slice(start, i + 1);
|
|
19
|
+
}
|
|
20
|
+
return source.slice(start);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Index just past the element that opens at `start` (self-closing, or up to
|
|
25
|
+
* its matching close tag — same-name nesting counted).
|
|
26
|
+
*/
|
|
27
|
+
export function elementEnd(source, start, name) {
|
|
28
|
+
const tag = openingTag(source, start);
|
|
29
|
+
if (tag.endsWith("/>")) return start + tag.length;
|
|
30
|
+
const esc = name.replace(/[.$]/g, "\\$&");
|
|
31
|
+
const re = new RegExp(`<${esc}(?![\\w.])|</${esc}\\s*>`, "g");
|
|
32
|
+
re.lastIndex = start + tag.length;
|
|
33
|
+
let depth = 1;
|
|
34
|
+
for (let m; (m = re.exec(source)); ) {
|
|
35
|
+
if (m[0].startsWith("</")) {
|
|
36
|
+
if (--depth === 0) return m.index + m[0].length;
|
|
37
|
+
} else if (!openingTag(source, m.index).endsWith("/>")) depth++;
|
|
38
|
+
}
|
|
39
|
+
return start + tag.length;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The raw value of a top-level attribute (not one nested in another prop's JSX). */
|
|
43
|
+
export function topLevelAttr(tag, name) {
|
|
44
|
+
let depth = 0;
|
|
45
|
+
let quote = null;
|
|
46
|
+
for (let i = 1; i < tag.length; i++) {
|
|
47
|
+
const c = tag[i];
|
|
48
|
+
if (quote) {
|
|
49
|
+
if (c === quote) quote = null;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (depth === 0 && tag.startsWith(`${name}=`, i) && /\s/.test(tag[i - 1])) {
|
|
53
|
+
const start = i + name.length + 1;
|
|
54
|
+
const open = tag[start];
|
|
55
|
+
if (open === '"' || open === "'") return tag.slice(start, tag.indexOf(open, start + 1) + 1);
|
|
56
|
+
if (open !== "{") return "";
|
|
57
|
+
let d = 0;
|
|
58
|
+
for (let j = start; j < tag.length; j++) {
|
|
59
|
+
if (tag[j] === "{") d++;
|
|
60
|
+
else if (tag[j] === "}" && --d === 0) return tag.slice(start, j + 1);
|
|
61
|
+
}
|
|
62
|
+
return tag.slice(start);
|
|
63
|
+
}
|
|
64
|
+
if (c === '"' || c === "'" || c === "`") quote = c;
|
|
65
|
+
else if (c === "{") depth++;
|
|
66
|
+
else if (c === "}") depth--;
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Class strings in a tag's own className: the literal, or the string literals inside className={…}. */
|
|
72
|
+
export function classText(tag) {
|
|
73
|
+
const value = topLevelAttr(tag, "className") ?? "";
|
|
74
|
+
return [...value.matchAll(/"([^"]*)"|'([^']*)'|`([^`]*)`/g)].map((s) => ` ${s[1] ?? s[2] ?? s[3]} `).join(" ");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Index just past the `{…}` expression that opens at `start`. */
|
|
78
|
+
function expressionEnd(source, start) {
|
|
79
|
+
let depth = 0;
|
|
80
|
+
let quote = null;
|
|
81
|
+
for (let i = start; i < source.length; i++) {
|
|
82
|
+
const c = source[i];
|
|
83
|
+
if (quote) {
|
|
84
|
+
if (c === "\\") i++;
|
|
85
|
+
else if (c === quote) quote = null;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (c === '"' || c === "'" || c === "`") quote = c;
|
|
89
|
+
else if (c === "{") depth++;
|
|
90
|
+
else if (c === "}" && --depth === 0) return i + 1;
|
|
91
|
+
}
|
|
92
|
+
return source.length;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The direct children of a JSX body: elements (with their name, opening tag
|
|
97
|
+
* and inner source), `{expressions}` and non-blank text. JSX comments and
|
|
98
|
+
* whitespace are dropped.
|
|
99
|
+
*/
|
|
100
|
+
export function jsxChildren(body) {
|
|
101
|
+
const out = [];
|
|
102
|
+
let i = 0;
|
|
103
|
+
while (i < body.length) {
|
|
104
|
+
const c = body[i];
|
|
105
|
+
if (c === "{") {
|
|
106
|
+
const end = expressionEnd(body, i);
|
|
107
|
+
const text = body.slice(i, end);
|
|
108
|
+
if (!/^\{\s*\/\*[\s\S]*\*\/\s*\}$/.test(text)) out.push({ kind: "expression", text });
|
|
109
|
+
i = end;
|
|
110
|
+
} else if (c === "<" && /[A-Za-z>]/.test(body[i + 1] ?? "")) {
|
|
111
|
+
const name = /^<([A-Za-z][\w.]*)?/.exec(body.slice(i))[1] ?? "";
|
|
112
|
+
const tag = openingTag(body, i);
|
|
113
|
+
let end;
|
|
114
|
+
let inner = "";
|
|
115
|
+
if (!name) {
|
|
116
|
+
// Fragment: <>…</>
|
|
117
|
+
const close = body.indexOf("</>", i + 2);
|
|
118
|
+
end = close < 0 ? body.length : close + 3;
|
|
119
|
+
inner = body.slice(i + 2, close < 0 ? body.length : close);
|
|
120
|
+
} else {
|
|
121
|
+
end = elementEnd(body, i, name);
|
|
122
|
+
inner = tag.endsWith("/>") ? "" : body.slice(i + tag.length, Math.max(i + tag.length, end - name.length - 3));
|
|
123
|
+
}
|
|
124
|
+
out.push({ kind: "element", name, tag, inner, text: body.slice(i, end) });
|
|
125
|
+
i = end;
|
|
126
|
+
} else {
|
|
127
|
+
const next = body.slice(i).search(/[{<]/);
|
|
128
|
+
const end = next < 0 ? body.length : i + Math.max(next, 1);
|
|
129
|
+
const text = body.slice(i, end);
|
|
130
|
+
if (text.trim()) out.push({ kind: "text", text });
|
|
131
|
+
i = end;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Button rules (user-mandated 2026-11-27).
|
|
2
|
+
//
|
|
3
|
+
// Buttons are text-only by default (principle 8), with one named exception:
|
|
4
|
+
// an Export action always leads with the Download glyph, so it reads as "this
|
|
5
|
+
// gives you a file" at a glance and looks the same on every screen.
|
|
6
|
+
|
|
7
|
+
import { matchesAny } from "../config.mjs";
|
|
8
|
+
|
|
9
|
+
export const BUTTON_RULES = [
|
|
10
|
+
{
|
|
11
|
+
name: "export-button-no-icon",
|
|
12
|
+
severity: "error",
|
|
13
|
+
guidance:
|
|
14
|
+
"Lead every Export button with the Download glyph: `<Button variant=\"outline\" startContent={<Download />}>Export</Button>` (Download from @/lib/icons). On a page it sits in the header bar, with the page's filters to its right.",
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const RULE = Object.fromEntries(BUTTON_RULES.map((r) => [r.name, r]));
|
|
19
|
+
|
|
20
|
+
/** Finds each `<Button …>` opening tag, attribute expressions included, and the text after it. */
|
|
21
|
+
function* buttonTags(source) {
|
|
22
|
+
for (const m of source.matchAll(/<Button\b/g)) {
|
|
23
|
+
let i = m.index + m[0].length;
|
|
24
|
+
let depth = 0;
|
|
25
|
+
let quote = null;
|
|
26
|
+
for (; i < source.length; i++) {
|
|
27
|
+
const c = source[i];
|
|
28
|
+
if (quote) {
|
|
29
|
+
if (c === quote) quote = null;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (c === '"' || c === "'" || c === "`") quote = c;
|
|
33
|
+
else if (c === "{") depth++;
|
|
34
|
+
else if (c === "}") depth--;
|
|
35
|
+
else if (c === ">" && depth === 0) break;
|
|
36
|
+
}
|
|
37
|
+
const tag = source.slice(m.index, i + 1);
|
|
38
|
+
const rest = source.slice(i + 1, i + 120);
|
|
39
|
+
yield { index: m.index, tag, label: rest.split("<")[0].trim() };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* An export label, written plainly ("Export", "Export to Excel"), as a string
|
|
45
|
+
* expression ({"Export"}), through a translation key ({t("export")},
|
|
46
|
+
* {t("reports.export")}), or as a file download ("Download CSV").
|
|
47
|
+
*/
|
|
48
|
+
function isExportLabel(label) {
|
|
49
|
+
const text = label
|
|
50
|
+
.replace(/^\{\s*(["'`])([\s\S]*?)\1\s*\}/, "$2")
|
|
51
|
+
.replace(/^\{\s*(?:t|i18n\.t|intl\.formatMessage)\(\s*["'`]([^"'`]*)["'`][^)]*\)\s*\}/, (_, key) => key.split(/[.:]/).pop());
|
|
52
|
+
return /^export\b/i.test(text) || /^download\s+(?:as\s+)?(?:csv|xlsx?|excel|pdf|json|report|data)\b/i.test(text);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function lintButtons(relPath, source, cfg) {
|
|
56
|
+
if (cfg.buttons?.enabled === false) return [];
|
|
57
|
+
if (matchesAny(relPath, cfg.buttons?.allow ?? [])) return [];
|
|
58
|
+
if (!/\.(tsx|jsx)$/.test(relPath)) return [];
|
|
59
|
+
if (!/<Button\b/.test(source)) return [];
|
|
60
|
+
|
|
61
|
+
const findings = [];
|
|
62
|
+
for (const { index, tag, label } of buttonTags(source)) {
|
|
63
|
+
if (tag.endsWith("/>")) continue;
|
|
64
|
+
if (!isExportLabel(label)) continue;
|
|
65
|
+
if (/\bstartContent=\{\s*<Download\b/.test(tag)) continue;
|
|
66
|
+
const match = `${tag} ${label}`.replace(/\s+/g, " ");
|
|
67
|
+
findings.push({
|
|
68
|
+
line: source.slice(0, index).split("\n").length,
|
|
69
|
+
rule: "export-button-no-icon",
|
|
70
|
+
severity: RULE["export-button-no-icon"].severity,
|
|
71
|
+
match: match.length > 80 ? `${match.slice(0, 77)}...` : match,
|
|
72
|
+
guidance: RULE["export-button-no-icon"].guidance,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return findings;
|
|
76
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Chart rules (user-mandated 2026-11-27, from the Voice insights review).
|
|
2
|
+
//
|
|
3
|
+
// One axis per chart: two measures on different scales (calls and answer
|
|
4
|
+
// rate) are two charts over the same categories, never one chart with a left
|
|
5
|
+
// and a right scale — readers compare the lines' heights, which mean nothing
|
|
6
|
+
// across two scales.
|
|
7
|
+
|
|
8
|
+
import { matchesAny } from "../config.mjs";
|
|
9
|
+
import { openingTag, topLevelAttr } from "../jsx.mjs";
|
|
10
|
+
|
|
11
|
+
export const CHART_RULES = [
|
|
12
|
+
{
|
|
13
|
+
name: "chart-dual-axis",
|
|
14
|
+
severity: "error",
|
|
15
|
+
guidance:
|
|
16
|
+
"One axis per chart. Put the second measure in its own chart over the same categories (e.g. Calls per day + Answer rate), or stack the parts so the ratio reads from the bars — never ComboChart dualAxis.",
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const RULE = Object.fromEntries(CHART_RULES.map((r) => [r.name, r]));
|
|
21
|
+
|
|
22
|
+
export function lintCharts(relPath, source, cfg) {
|
|
23
|
+
if (cfg.charts?.enabled === false) return [];
|
|
24
|
+
if (matchesAny(relPath, cfg.charts?.allow ?? [])) return [];
|
|
25
|
+
if (!/\.(tsx|jsx)$/.test(relPath)) return [];
|
|
26
|
+
const findings = [];
|
|
27
|
+
// Any dualAxis that is not literally {false}: bare, {true}, or a pass-through ({spec.dualAxis}).
|
|
28
|
+
for (const m of source.matchAll(/<(?:ComboChart|ComposedChart)\b/g)) {
|
|
29
|
+
const tag = openingTag(source, m.index);
|
|
30
|
+
const value = topLevelAttr(tag, "dualAxis");
|
|
31
|
+
const bare = /\sdualAxis(?=[\s/>])/.test(tag);
|
|
32
|
+
if (!bare && (value === null || /^\{\s*false\s*\}$/.test(value))) continue;
|
|
33
|
+
const match = tag.replace(/\s+/g, " ");
|
|
34
|
+
findings.push({
|
|
35
|
+
line: source.slice(0, m.index).split("\n").length,
|
|
36
|
+
rule: "chart-dual-axis",
|
|
37
|
+
severity: RULE["chart-dual-axis"].severity,
|
|
38
|
+
match: match.length > 80 ? `${match.slice(0, 77)}...` : match,
|
|
39
|
+
guidance: RULE["chart-dual-axis"].guidance,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return findings;
|
|
43
|
+
}
|