diff --git a/frontend/package.json b/frontend/package.json index dbf34cc8..4f8a131c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -9,7 +9,7 @@ "test": "node --test", "test:browser": "node scripts/settings-browser.mjs", "test:settings-ui": "node scripts/settings-ui-browser.mjs", - "lint": "node scripts/lint.mjs && node scripts/check-font-integrity.mjs && node scripts/check-settings-index.mjs && node scripts/check-theme-tokens.mjs && node scripts/check-frontend-boundaries.mjs && node scripts/check-style-ownership.mjs && node scripts/check-status-one-door.mjs && node scripts/check-shared-fields.mjs && node scripts/check-tables.mjs && node scripts/check-type-scale.mjs && node scripts/check-geometry.mjs && node scripts/check-status-scss.mjs && node scripts/check-i18n-literals.mjs && node scripts/check-intl-door.mjs && node scripts/extract-i18n.mjs --check && node scripts/check-i18n.mjs && node scripts/check-logical-properties.mjs && node scripts/generate-vendor-shims.mjs --check && node ../scripts/check-html-sinks.mjs && node scripts/check-orphan-files.mjs && node scripts/check-label-association.mjs", + "lint": "node scripts/lint.mjs && node scripts/check-font-integrity.mjs && node scripts/check-settings-index.mjs && node scripts/check-theme-tokens.mjs && node scripts/check-frontend-boundaries.mjs && node scripts/check-style-ownership.mjs && node scripts/check-status-one-door.mjs && node scripts/check-shared-fields.mjs && node scripts/check-tables.mjs && node scripts/check-list-chrome.mjs && node scripts/check-type-scale.mjs && node scripts/check-geometry.mjs && node scripts/check-status-scss.mjs && node scripts/check-i18n-literals.mjs && node scripts/check-intl-door.mjs && node scripts/extract-i18n.mjs --check && node scripts/check-i18n.mjs && node scripts/check-logical-properties.mjs && node scripts/generate-vendor-shims.mjs --check && node ../scripts/check-html-sinks.mjs && node scripts/check-orphan-files.mjs && node scripts/check-label-association.mjs", "lint:baseline": "node scripts/lint.mjs --update", "test:layout": "node scripts/layout-screenshots-browser.mjs", "test:controls": "node scripts/controls-browser.mjs", @@ -27,6 +27,7 @@ "lint:fonts": "node scripts/check-font-integrity.mjs", "lint:status": "node scripts/check-status-one-door.mjs", "lint:shared-fields": "node scripts/check-shared-fields.mjs", + "lint:list-chrome": "node scripts/check-list-chrome.mjs", "lint:type-scale": "node scripts/check-type-scale.mjs", "lint:geometry": "node scripts/check-geometry.mjs", "lint:i18n": "node scripts/check-i18n-literals.mjs", diff --git a/frontend/scripts/check-list-chrome.mjs b/frontend/scripts/check-list-chrome.mjs new file mode 100644 index 00000000..6dfb0cff --- /dev/null +++ b/frontend/scripts/check-list-chrome.mjs @@ -0,0 +1,148 @@ +#!/usr/bin/env node +// One list-page shell. Every page with a table puts its controls in the same +// places, so the create button and the search box never move between pages: +// +// top bar [secondary …] [create] [search] (ds/ListActions) +// view selector saved views · filters and fields · copy link / export / +// reset · page extras (GridViewPicker) +// +// Fails when a page: +// +// - renders a filter icon or a "⋮" tools menu of its own (they are entries in +// the view selector's menu: ``), +// - hoists table controls into the top bar with useTopbarChrome, +// - puts a filter button in the top bar, or orders the bar differently +// (create after search, anything after search), +// - adds a KPI strip to a page that is not an overview. +// +// The allowlists are the known exceptions, each with its reason. They may only +// shrink. Extension copies under src/plugins/ are out of scope. + +import { readFileSync, readdirSync, statSync } from 'node:fs'; +import { join, relative, sep } from 'node:path'; + +const SRC = new URL('../src', import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1'); + +// Files that may render / . +const CHROME_OWNERS = new Set([ + // A table with no saved views has no selector to hold them (SDK surface). + 'components/layouts/ResourceListPage.jsx', + // Living documentation of the primitives. + 'pages/StyleGuide.jsx', +]); + +// Files that may call useTopbarChrome. +const TOPBAR_CHROME_USERS = new Set([ + 'hooks/useTopbarActions.js', + // A workspace, not a table: its view switch and path tools ride the bar. + 'pages/FileManager.jsx', +]); + +// Top bars that keep a filter button: card catalogues with no view selector. +const TOPBAR_FILTER_USERS = new Set([ + 'pages/Marketplace.jsx', +]); + +// Overview surfaces: the only places a KPI strip belongs. A list of records +// gets none — its counts are the table footer and the saved views. +const KPI_OWNERS = new Set([ + 'components/ds/KpiBand.jsx', + 'pages/StyleGuide.jsx', + 'components/backups/ProtectionStatusCard.jsx', + 'pages/Monitoring.jsx', + // The agent fleet's Dashboard tab and the FTP server's status block. + 'pages/AgentFleet.jsx', + 'pages/FTPServer.jsx', + // Detail pages; they move to the shared detail header with the rest. + 'pages/MonitorDetail.jsx', + 'pages/QueueDetail.jsx', +]); + +function* walk(dir) { + for (const name of readdirSync(dir)) { + const p = join(dir, name); + if (statSync(p).isDirectory()) { + if (name === 'node_modules' || name === '__tests__' || name === 'plugins') continue; + yield* walk(p); + } else if (/\.jsx?$/.test(name)) { + yield p; + } + } +} + +function stripComments(src) { + return src + .replace(/\{\/\*[\s\S]*?\*\/\}/g, (m) => m.replace(/[^\n]/g, ' ')) + .replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, ' ')) + .replace(/(^|[^:'"`])\/\/.*$/gm, (m, lead) => lead + ' '.repeat(m.length - lead.length)); +} + +// The balanced (...) argument list of the call that starts at `from`. +function callBlock(src, from) { + const start = src.indexOf('(', from); + let depth = 0; + for (let i = start; i < src.length; i += 1) { + if (src[i] === '(') depth += 1; + else if (src[i] === ')') { + depth -= 1; + if (depth === 0) return src.slice(start, i + 1); + } + } + return ''; +} + +const lineOf = (src, index) => src.slice(0, index).split('\n').length; + +const problems = []; +for (const file of walk(SRC)) { + const rel = relative(SRC, file).split(sep).join('/'); + const src = stripComments(readFileSync(file, 'utf8')); + const inGrid = rel.startsWith('components/ds/grid/'); + + if (!inGrid && !CHROME_OWNERS.has(rel)) { + for (const m of src.matchAll(/<(GridFilterButton|GridToolsMenu)\b/g)) { + problems.push(`${rel}:${lineOf(src, m.index)} <${m[1]}> — fold it into the view selector: `); + } + } + + if (!TOPBAR_CHROME_USERS.has(rel)) { + for (const m of src.matchAll(/(? — KPI strips belong to overview surfaces, not list pages`); + } + } + + if (rel === 'hooks/useTopbarActions.js') continue; + for (const m of src.matchAll(/(?').slice(1)) { + const search = part.indexOf('