@actioneer/ads-lint 0.2.0 → 1.0.62
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
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// Modal sizing rules (principle 8, user-mandated 2026-11-25).
|
|
2
|
+
//
|
|
3
|
+
// The Modal size decides its frame: `sm` confirmations hug their content
|
|
4
|
+
// (up to 320px); md/lg/xl forms keep a fixed 640px frame and hand the spare
|
|
5
|
+
// height to their long-text field automatically. A screen that passes its own
|
|
6
|
+
// `height` or a height class to Modal brings back the blank bands this
|
|
7
|
+
// replaced, so both are rejected here. Lone `<Modal ...>` openings are matched
|
|
8
|
+
// across lines; `=>` inside props is allowed.
|
|
9
|
+
|
|
10
|
+
import { matchesAny } from "../config.mjs";
|
|
11
|
+
import { elementEnd, jsxChildren, openingTag } from "../jsx.mjs";
|
|
12
|
+
|
|
13
|
+
const MODAL_OPEN = /<Modal\s(?:=>|[^<>])*?(?<!=)>/g;
|
|
14
|
+
const CHROME_OPEN = /<Modal(Header|Footer)\s(?:=>|[^<>])*?(?<!=)>/g;
|
|
15
|
+
const CLASS_VALUE = /className=(?:"([^"]*)"|\{([^}]*)\})/;
|
|
16
|
+
|
|
17
|
+
export const RULES = [
|
|
18
|
+
{
|
|
19
|
+
name: "modal-height-override",
|
|
20
|
+
severity: "error",
|
|
21
|
+
test: (tag) => /\sheight=["{]/.test(tag),
|
|
22
|
+
guidance:
|
|
23
|
+
"Leave Modal `height` unset: sm confirmations hug their content and md/lg/xl forms keep the fixed 640px frame, with a textarea Field filling it.",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "modal-height-class",
|
|
27
|
+
severity: "error",
|
|
28
|
+
test: (tag) => /className=[^>]*?["'`\s(](?:min-|max-)?h-/.test(tag),
|
|
29
|
+
guidance:
|
|
30
|
+
"Do not size a Modal with height classes. Pick the size (sm, md, lg, xl, full); the frame height follows from it.",
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
// Modal chrome (user-mandated 2026-11-25): the header and footer share the
|
|
35
|
+
// modal's white surface with no stroke — 40px surface washes under the title
|
|
36
|
+
// and above the footer appear only while content is hidden past them, and the ✕ shows
|
|
37
|
+
// only when there is no footer. A fill or stroke class on either brings back
|
|
38
|
+
// the band and lines this replaced.
|
|
39
|
+
export const CHROME_RULES = [
|
|
40
|
+
{
|
|
41
|
+
name: "modal-chrome-fill",
|
|
42
|
+
severity: "error",
|
|
43
|
+
test: (classes) => /(?:^|[\s"'`])bg-/.test(classes),
|
|
44
|
+
guidance:
|
|
45
|
+
"ModalHeader and ModalFooter share the modal's white surface — no background class.",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "modal-chrome-stroke",
|
|
49
|
+
severity: "error",
|
|
50
|
+
test: (classes) => /(?:^|[\s"'`])(?:border|divide)(?:-[tblrxy])?(?=[\s"'`]|$|-(?:border|tertiary|secondary|primary|strong|\[))/.test(classes),
|
|
51
|
+
guidance:
|
|
52
|
+
"No line under the modal header or above its footer: the modal fades content out under the title and above the footer only while content is hidden there.",
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
// A footer whose only action is Done / Close / OK / Got it (user-mandated
|
|
57
|
+
// 2026-11-28). When every control in the modal has already applied, the
|
|
58
|
+
// close button is the way out and the modal has no footer at all; a footer
|
|
59
|
+
// with one dismiss button repeats the ✕ (and hides it).
|
|
60
|
+
export const FOOTER_RULES = [
|
|
61
|
+
{
|
|
62
|
+
name: "modal-footer-done",
|
|
63
|
+
severity: "error",
|
|
64
|
+
guidance:
|
|
65
|
+
"A modal whose controls apply at once has no ModalFooter: drop the lone Done/Close/OK button and let the header ✕ (shown automatically without a footer), Esc and the scrim close it.",
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
// Deleting (user-mandated 2026-11-29). A record — a campaign, a journey, a
|
|
70
|
+
// connection — asks once, with the same ConfirmDialog everywhere: the title
|
|
71
|
+
// names the kind ("Delete journey?"), the description names the record and
|
|
72
|
+
// what goes with it, and the buttons are Cancel and Delete. Never a field to
|
|
73
|
+
// type DELETE into, a record name in the title, or the kind repeated on the
|
|
74
|
+
// button. A part of a record (a step, a condition, a row) asks nothing.
|
|
75
|
+
export const CONFIRM_RULES = [
|
|
76
|
+
{
|
|
77
|
+
name: "confirm-type-to-confirm",
|
|
78
|
+
severity: "error",
|
|
79
|
+
guidance:
|
|
80
|
+
'No "Type DELETE to confirm" field. Deleting a record asks once with ConfirmDialog (destructive): the title names the kind ("Delete journey?"), the description names the record and what goes with it, and the buttons are Cancel and Delete.',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: "confirm-title-names-record",
|
|
84
|
+
severity: "warn",
|
|
85
|
+
guidance:
|
|
86
|
+
'A ConfirmDialog title names the kind of thing ("Delete journey?"), never the record: a long name wraps the title over several lines. Put the record\'s name, in quotes, in the description.',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "confirm-label-repeats-kind",
|
|
90
|
+
severity: "warn",
|
|
91
|
+
guidance:
|
|
92
|
+
'The confirm button of a delete reads "Delete" on its own. The title already names what is deleted ("Delete journey?").',
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
const TYPE_TO_CONFIRM = /\bType\b[^\n]{0,30}?\b[A-Z]{3,}\b[^\n]{0,30}?\bto (?:confirm|continue|proceed)\b/g;
|
|
97
|
+
const CONFIRM_TITLE = /\btitle=(?:"([^"]*)"|\{([^]*?)\}(?=\s|\/?>|$))/;
|
|
98
|
+
const CONFIRM_LABEL = /\bconfirmLabel=(?:"([^"]*)"|\{\s*["'`]([^"'`]*)["'`]\s*\})/;
|
|
99
|
+
|
|
100
|
+
const DISMISS_LABEL = /^(?:Done|Close|OK|Ok|Okay|Got it)$/;
|
|
101
|
+
|
|
102
|
+
/** The visible label of a Button element: its text, or a string expression. */
|
|
103
|
+
function buttonLabel(child) {
|
|
104
|
+
const parts = jsxChildren(child.inner ?? "");
|
|
105
|
+
if (parts.length !== 1) return null;
|
|
106
|
+
const [part] = parts;
|
|
107
|
+
if (part.kind === "text") return part.text.trim();
|
|
108
|
+
if (part.kind === "expression") return /^\{\s*["'`]([^"'`]*)["'`]\s*\}$/.exec(part.text)?.[1].trim() ?? null;
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function footerActions(inner) {
|
|
113
|
+
let children = jsxChildren(inner);
|
|
114
|
+
// Unwrap a lone fragment: <ModalFooter><>…</></ModalFooter>.
|
|
115
|
+
if (children.length === 1 && children[0].kind === "element" && children[0].name === "") children = jsxChildren(children[0].inner);
|
|
116
|
+
return children;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function lintModals(relPath, source, cfg) {
|
|
120
|
+
if (cfg.modals?.enabled === false) return [];
|
|
121
|
+
if (matchesAny(relPath, cfg.modals?.allow ?? [])) return [];
|
|
122
|
+
if (!/\.(tsx|jsx)$/.test(relPath)) return [];
|
|
123
|
+
|
|
124
|
+
const findings = [];
|
|
125
|
+
MODAL_OPEN.lastIndex = 0;
|
|
126
|
+
for (const m of source.matchAll(MODAL_OPEN)) {
|
|
127
|
+
for (const rule of RULES) {
|
|
128
|
+
if (!rule.test(m[0])) continue;
|
|
129
|
+
findings.push({
|
|
130
|
+
line: source.slice(0, m.index).split("\n").length,
|
|
131
|
+
rule: rule.name,
|
|
132
|
+
severity: rule.severity,
|
|
133
|
+
match: m[0].length > 80 ? `${m[0].slice(0, 77)}...` : m[0],
|
|
134
|
+
guidance: rule.guidance,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
for (const m of source.matchAll(/<ModalFooter(?![\w.])/g)) {
|
|
139
|
+
const tag = openingTag(source, m.index);
|
|
140
|
+
if (tag.endsWith("/>")) continue;
|
|
141
|
+
const end = elementEnd(source, m.index, "ModalFooter");
|
|
142
|
+
const inner = source.slice(m.index + tag.length, end - "</ModalFooter>".length);
|
|
143
|
+
const actions = footerActions(inner);
|
|
144
|
+
if (actions.length !== 1) continue;
|
|
145
|
+
const [only] = actions;
|
|
146
|
+
if (only.kind !== "element" || !/^(?:Button|ModalClose)$/.test(only.name)) continue;
|
|
147
|
+
const label = only.name === "ModalClose" ? buttonLabel(only) ?? "Close" : buttonLabel(only);
|
|
148
|
+
if (!label || !DISMISS_LABEL.test(label)) continue;
|
|
149
|
+
const rule = FOOTER_RULES[0];
|
|
150
|
+
findings.push({
|
|
151
|
+
line: source.slice(0, m.index).split("\n").length,
|
|
152
|
+
rule: rule.name,
|
|
153
|
+
severity: rule.severity,
|
|
154
|
+
match: `<ModalFooter><${only.name}>${label}</${only.name}></ModalFooter>`,
|
|
155
|
+
guidance: rule.guidance,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
for (const m of source.matchAll(TYPE_TO_CONFIRM)) {
|
|
159
|
+
const rule = CONFIRM_RULES[0];
|
|
160
|
+
findings.push({
|
|
161
|
+
line: source.slice(0, m.index).split("\n").length,
|
|
162
|
+
rule: rule.name,
|
|
163
|
+
severity: rule.severity,
|
|
164
|
+
match: m[0].length > 80 ? `${m[0].slice(0, 77)}...` : m[0],
|
|
165
|
+
guidance: rule.guidance,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
for (const m of source.matchAll(/<ConfirmDialog(?![\w.])/g)) {
|
|
169
|
+
const tag = openingTag(source, m.index);
|
|
170
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
171
|
+
const title = CONFIRM_TITLE.exec(tag);
|
|
172
|
+
const titleValue = title ? title[1] ?? title[2] ?? "" : "";
|
|
173
|
+
// A quoted name, a template interpolation or a concatenated variable in the title.
|
|
174
|
+
if (title && (/[“”]/.test(titleValue) || (title[2] !== undefined && /\$\{|\+/.test(titleValue)))) {
|
|
175
|
+
const rule = CONFIRM_RULES[1];
|
|
176
|
+
findings.push({ line, rule: rule.name, severity: rule.severity, match: title[0].length > 80 ? `${title[0].slice(0, 77)}...` : title[0], guidance: rule.guidance });
|
|
177
|
+
}
|
|
178
|
+
const label = CONFIRM_LABEL.exec(tag);
|
|
179
|
+
const labelValue = label ? (label[1] ?? label[2] ?? "").trim() : "";
|
|
180
|
+
if (/^Delete\s+\S/.test(labelValue)) {
|
|
181
|
+
const rule = CONFIRM_RULES[2];
|
|
182
|
+
findings.push({ line, rule: rule.name, severity: rule.severity, match: label[0], guidance: rule.guidance });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
CHROME_OPEN.lastIndex = 0;
|
|
186
|
+
for (const m of source.matchAll(CHROME_OPEN)) {
|
|
187
|
+
const value = m[0].match(CLASS_VALUE);
|
|
188
|
+
if (!value) continue;
|
|
189
|
+
const classes = value[1] ?? value[2] ?? "";
|
|
190
|
+
for (const rule of CHROME_RULES) {
|
|
191
|
+
if (!rule.test(classes)) continue;
|
|
192
|
+
// A two-pane browser's header is a structural bar (ChatHistory, user-mandated 2026-11-28).
|
|
193
|
+
if (rule.name === "modal-chrome-stroke" && matchesAny(relPath, cfg.modals?.structuralHeaderAllow ?? [])) continue;
|
|
194
|
+
findings.push({
|
|
195
|
+
line: source.slice(0, m.index).split("\n").length,
|
|
196
|
+
rule: rule.name,
|
|
197
|
+
severity: rule.severity,
|
|
198
|
+
match: m[0].length > 80 ? `${m[0].slice(0, 77)}...` : m[0],
|
|
199
|
+
guidance: rule.guidance,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return findings;
|
|
204
|
+
}
|
package/src/rules/motion.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Motion rules (principle 3) — regex over .css/.ts/.tsx.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// Motion rules (principle 3) — regex over .css/.ts/.tsx. Shared animation
|
|
2
|
+
// uses the Animate UI-derived presets in src/lib/motion.ts; component-local
|
|
3
|
+
// CSS feedback may use explicit durations.
|
|
4
4
|
//
|
|
5
5
|
// This RULES table is the SINGLE SOURCE OF TRUTH for the motion policy — the
|
|
6
6
|
// repo's scripts/check-motion.mjs imports it too, so the two never drift.
|
|
@@ -33,10 +33,18 @@ export const RULES = [
|
|
|
33
33
|
guidance: "Use zoom-in/out-95 so the element retains physical presence.",
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
|
-
name: "
|
|
36
|
+
name: "legacy-motion-token",
|
|
37
37
|
severity: "error",
|
|
38
|
-
pattern:
|
|
39
|
-
guidance:
|
|
38
|
+
pattern: /--(?:ease|duration|stagger)-[a-z0-9-]+|--scale-press/g,
|
|
39
|
+
guidance:
|
|
40
|
+
"Remove the legacy CSS motion token. Import an Animate UI-derived preset from the ADS root barrel for shared animation, or keep simple CSS feedback local.",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "raw-spring-config",
|
|
44
|
+
severity: "error",
|
|
45
|
+
pattern: /\b(?:stiffness|damping|bounce|restDelta)\s*:/g,
|
|
46
|
+
guidance:
|
|
47
|
+
"Import the matching Animate UI-derived motion preset from the ADS barrel; library authors define role presets only in src/lib/motion.ts.",
|
|
40
48
|
},
|
|
41
49
|
{
|
|
42
50
|
name: "layout-property-transition",
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Recipe rules (owner-reported 2026-11-29).
|
|
2
|
+
//
|
|
3
|
+
// When ADS 1.0.60 was applied to the product, the script screen, call logs,
|
|
4
|
+
// table filters and filter chips were left as they were: each was a product's
|
|
5
|
+
// own build of something ADS already owns, and no rule said so. These rules
|
|
6
|
+
// name the ADS part to use instead.
|
|
7
|
+
//
|
|
8
|
+
// - call-panel-hand-rolled: a call's review panel rebuilt from Drawer parts
|
|
9
|
+
// (a Drawer with a Transcript or an AudioWaveform). Use CallPanel — it takes
|
|
10
|
+
// `loading` while the call's details are fetched.
|
|
11
|
+
// - filter-menu-hand-rolled: a Popover holding a list of Checkboxes is a
|
|
12
|
+
// hand-made filter menu. Use the table's own column filter (TableColumn
|
|
13
|
+
// filterOptions / filterValue / onFilterChange: multi-select "Show only" with
|
|
14
|
+
// counts) or Filters in the CollectionToolbar.
|
|
15
|
+
// - filter-chip-clear-button: a Chip followed by its own clear/remove button.
|
|
16
|
+
// Use Chip onClose — the chip carries its own ✕.
|
|
17
|
+
// - script-character-limit: "893 / 2,000,000 chars". Say the size in plain
|
|
18
|
+
// words at the foot ("526 characters"); ScriptStart and ScriptDocument do.
|
|
19
|
+
// - script-opening-line-hand-rolled: an "Opening line" label drawn by hand.
|
|
20
|
+
// Use ScriptOpeningLine (editable on a draft, read-only once running).
|
|
21
|
+
|
|
22
|
+
import { matchesAny } from "../config.mjs";
|
|
23
|
+
import { elementEnd } from "../jsx.mjs";
|
|
24
|
+
|
|
25
|
+
export const RECIPE_RULES = [
|
|
26
|
+
{
|
|
27
|
+
name: "call-panel-hand-rolled",
|
|
28
|
+
severity: "error",
|
|
29
|
+
guidance:
|
|
30
|
+
"A call's review panel is the ADS CallPanel — map the call onto a CallPanelCall and render <CallPanel call={…} onClose={…} />. Pass `loading={{ number, pickedUp }}` while the details are fetched. Never rebuild it from Drawer, DrawerSection, Transcript and AudioWaveform.",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "filter-menu-hand-rolled",
|
|
34
|
+
severity: "error",
|
|
35
|
+
guidance:
|
|
36
|
+
"A Popover of Checkboxes is a hand-made filter menu. Filter a table from its column header (TableColumn filterOptions + filterValue + onFilterChange: a multi-select \"Show only\" list with counts), or use Filters in the CollectionToolbar.",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "filter-chip-clear-button",
|
|
40
|
+
severity: "error",
|
|
41
|
+
guidance:
|
|
42
|
+
"An applied filter is one Chip with its own ✕: pass `onClose` to the Chip instead of placing a separate clear or remove button beside it.",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "script-character-limit",
|
|
46
|
+
severity: "error",
|
|
47
|
+
guidance:
|
|
48
|
+
"Say a script's size in plain words at its foot (\"526 characters\"), never as a used / limit counter. ScriptStart and ScriptDocument show it.",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "script-opening-line-hand-rolled",
|
|
52
|
+
severity: "error",
|
|
53
|
+
guidance:
|
|
54
|
+
"The opening line is the ADS ScriptOpeningLine — editable on a draft, read-only once the campaign runs, with its word count and info icon. Never draw the \"Opening line\" label and field by hand.",
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const RULE = Object.fromEntries(RECIPE_RULES.map((r) => [r.name, r]));
|
|
59
|
+
|
|
60
|
+
/** The ranges of every element named `name` in `source`, as [start, end] pairs. */
|
|
61
|
+
function elements(source, name) {
|
|
62
|
+
const out = [];
|
|
63
|
+
for (const m of source.matchAll(new RegExp(`<${name}(?![\\w.])`, "g"))) out.push([m.index, elementEnd(source, m.index, name)]);
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function lintRecipes(relPath, source, cfg) {
|
|
68
|
+
if (cfg.recipes?.enabled === false) return [];
|
|
69
|
+
if (matchesAny(relPath, cfg.recipes?.allow ?? [])) return [];
|
|
70
|
+
if (!/\.(tsx|jsx)$/.test(relPath)) return [];
|
|
71
|
+
// In library-dev mode the library's own files build these parts.
|
|
72
|
+
const libraryRoot = cfg.imports?.libraryRoot;
|
|
73
|
+
if (libraryRoot && relPath.startsWith(libraryRoot.replace(/\/?$/, "/"))) return [];
|
|
74
|
+
|
|
75
|
+
const findings = [];
|
|
76
|
+
const push = (name, index, match) =>
|
|
77
|
+
findings.push({
|
|
78
|
+
line: source.slice(0, index).split("\n").length,
|
|
79
|
+
rule: name,
|
|
80
|
+
severity: RULE[name].severity,
|
|
81
|
+
match: match.length > 80 ? `${match.slice(0, 77)}...` : match.replace(/\s+/g, " "),
|
|
82
|
+
guidance: RULE[name].guidance,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// call-panel-hand-rolled: a Drawer that holds a Transcript or an AudioWaveform.
|
|
86
|
+
if (/<Drawer(?![\w.])/.test(source) && /<(?:Transcript|AudioWaveform)(?![\w.])/.test(source) && !/<CallPanel(?![\w.])/.test(source)) {
|
|
87
|
+
for (const [start, end] of elements(source, "Drawer")) {
|
|
88
|
+
const body = source.slice(start, end);
|
|
89
|
+
const inner = /<(Transcript|AudioWaveform)(?![\w.])/.exec(body);
|
|
90
|
+
if (inner) push("call-panel-hand-rolled", start, `<Drawer> … <${inner[1]}>`);
|
|
91
|
+
}
|
|
92
|
+
// The panel's sections are often split into helper components outside the Drawer.
|
|
93
|
+
if (!findings.length && /<DrawerSection(?![\w.])/.test(source)) {
|
|
94
|
+
const at = source.search(/<(?:Transcript|AudioWaveform)(?![\w.])/);
|
|
95
|
+
push("call-panel-hand-rolled", at, "<DrawerSection> … <Transcript>");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// filter-menu-hand-rolled: a PopoverContent that holds Checkboxes.
|
|
100
|
+
for (const [start, end] of elements(source, "PopoverContent")) {
|
|
101
|
+
if (/<Checkbox(?![\w.])/.test(source.slice(start, end))) push("filter-menu-hand-rolled", start, "<PopoverContent> … <Checkbox>");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// filter-chip-clear-button: </Chip> then, before the next tag, a Clear/Remove button.
|
|
105
|
+
for (const m of source.matchAll(/<\/Chip>\s*(?:\{[^{}<]*?&&\s*\(?\s*)?<(?:Button|IconButton|button)\b[^>]*?aria-label=["'{`](?:Clear|Remove)\b/g)) {
|
|
106
|
+
push("filter-chip-clear-button", m.index, m[0]);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// script-character-limit: "{n} / {max} chars", "/ 2,000,000 chars".
|
|
110
|
+
for (const m of source.matchAll(/\}\s*\/\s*(?:\{[^{}]*\}|[\d,.]+[kKmM]?)\s*(?:chars|characters)\b/g)) {
|
|
111
|
+
push("script-character-limit", m.index, m[0]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// script-opening-line-hand-rolled: an "Opening line" label without ScriptOpeningLine.
|
|
115
|
+
if (!/<ScriptOpeningLine(?![\w.])/.test(source)) {
|
|
116
|
+
const m = /(?:>\s*Opening line\s*<|label=["'{`]Opening line["'`])/.exec(source);
|
|
117
|
+
if (m) push("script-opening-line-hand-rolled", m.index, m[0]);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return findings;
|
|
121
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Selection-edge rule (user-mandated 2026-11-27).
|
|
2
|
+
//
|
|
3
|
+
// A selected / current / highlighted item is marked by the subtle T5 edge
|
|
4
|
+
// (`border-border-selected`) plus a pale wash — never an action-primary or a
|
|
5
|
+
// strong teal outline, which read too stark. Focus rings, checked controls,
|
|
6
|
+
// tab underlines and buttons are not selection edges and are not matched.
|
|
7
|
+
|
|
8
|
+
import { matchesAny } from "../config.mjs";
|
|
9
|
+
|
|
10
|
+
export const SELECTION_RULES = [
|
|
11
|
+
{
|
|
12
|
+
name: "selected-edge-action",
|
|
13
|
+
severity: "error",
|
|
14
|
+
guidance:
|
|
15
|
+
"Mark a selected, current or highlighted item with border-border-selected (the subtle T5 edge) plus a pale wash — never an action-primary or strong teal outline.",
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const RULE = Object.fromEntries(SELECTION_RULES.map((r) => [r.name, r]));
|
|
20
|
+
|
|
21
|
+
// The strong colours a selection edge must not use: action-primary, brand,
|
|
22
|
+
// the T9–T12 steps, and their CSS-variable forms (`border-(--action-primary)`).
|
|
23
|
+
const STRONG = String.raw`(?:action-primary|brand|t(?:9|1[0-2])|\(--(?:color-)?(?:action-primary|brand|t(?:9|1[0-2]))\))(?![\w-])`;
|
|
24
|
+
const EDGE = String.raw`(?:border|ring|outline)(?:-[trblxy])?-`;
|
|
25
|
+
|
|
26
|
+
// Selection state prefixes: data-[selected=true]: / data-selected: /
|
|
27
|
+
// aria-[pressed=true]: / aria-pressed: / aria-[current…]: / aria-current: /
|
|
28
|
+
// aria-selected: / aria-[selected=true]: / data-[state=on|active]: /
|
|
29
|
+
// data-active: — then a strong border, ring or outline (stacked variants,
|
|
30
|
+
// opacity and `!` included). Checked Checkbox/Radio/Switch keep their own
|
|
31
|
+
// treatment, so data-[state=checked] is not a selection prefix.
|
|
32
|
+
const PATTERN = new RegExp(
|
|
33
|
+
String.raw`(?:data-\[selected(?:=true)?\]|data-selected|aria-\[pressed(?:=true)?\]|aria-pressed|aria-\[current[^\]]*\]|aria-current|aria-\[selected(?:=true)?\]|aria-selected|data-\[state=(?:on|active)\]|data-\[active(?:=true)?\]|data-active):(?:[\w-]+:|\[[^\]]*\]:)*!?${EDGE}${STRONG}`,
|
|
34
|
+
"g",
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// A conditional class: `selected ? "border-action-primary" : …` or
|
|
38
|
+
// `isActive && "ring-brand"` — a state-named condition whose truthy string
|
|
39
|
+
// carries an unprefixed strong edge.
|
|
40
|
+
const CONDITIONAL = new RegExp(
|
|
41
|
+
String.raw`\b\w*(?:selected|active|current|pressed|chosen|checked(?=Item|Row|Card))\w*\s*(?:\?|&&)\s*(["'\x60])([^"'\x60]*)\1`,
|
|
42
|
+
"gi",
|
|
43
|
+
);
|
|
44
|
+
const STRONG_EDGE = new RegExp(String.raw`^!?${EDGE}${STRONG}!?$`);
|
|
45
|
+
|
|
46
|
+
/** The first strong edge in a class string that is not a focus/hover/disabled treatment. */
|
|
47
|
+
function strongEdge(classes) {
|
|
48
|
+
for (const token of classes.split(/\s+/)) {
|
|
49
|
+
const cut = token.lastIndexOf(":", token.endsWith("]") ? token.lastIndexOf("[") : token.length);
|
|
50
|
+
const prefix = cut < 0 ? "" : token.slice(0, cut);
|
|
51
|
+
const utility = cut < 0 ? token : token.slice(cut + 1);
|
|
52
|
+
if (STRONG_EDGE.test(utility) && !/focus|hover|disabled/.test(prefix)) return token;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function lintSelection(relPath, source, cfg) {
|
|
58
|
+
if (cfg.selection?.enabled === false) return [];
|
|
59
|
+
if (matchesAny(relPath, cfg.selection?.allow ?? [])) return [];
|
|
60
|
+
if (!/\.(tsx|jsx|ts)$/.test(relPath)) return [];
|
|
61
|
+
const findings = [];
|
|
62
|
+
const push = (index, match) =>
|
|
63
|
+
findings.push({
|
|
64
|
+
line: source.slice(0, index).split("\n").length,
|
|
65
|
+
rule: "selected-edge-action",
|
|
66
|
+
severity: RULE["selected-edge-action"].severity,
|
|
67
|
+
match,
|
|
68
|
+
guidance: RULE["selected-edge-action"].guidance,
|
|
69
|
+
});
|
|
70
|
+
for (const m of source.matchAll(PATTERN)) push(m.index, m[0]);
|
|
71
|
+
for (const m of source.matchAll(CONDITIONAL)) {
|
|
72
|
+
const hit = strongEdge(m[2]);
|
|
73
|
+
if (hit) push(m.index, `${m[0].split(/\s*(?:\?|&&)/)[0]} … "${hit}"`);
|
|
74
|
+
}
|
|
75
|
+
return findings;
|
|
76
|
+
}
|