ipal-audit, ipal-doctor: the panel's bilingual labels are not hardcoded text
"Hardcoded Polish text in code" (i18n-literals) grepped every string, so adminText() and { en, pl }
labels in schema files were reported, though AGENT.md 6.5a asks for them. polish-literals.mjs reads
the syntax tree with the project's TypeScript (a plain grep without it) and spares those forms in
schema files only; every .tsx file, Polish-only labels, other keys and defaultValue still fail.
Reported by Niezly Dandys (1.15.2).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
36b27ed323
commit
f73465c3bb
@@ -8,6 +8,20 @@ versions at once, go through every "Requires project changes" section in order,
|
||||
version you have. A new release = a new section at the top; we remove the oldest ones only
|
||||
once there are more than 20.
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Fixed
|
||||
- **ipal-audit and ipal-doctor no longer report the panel's own bilingual labels as hardcoded text.** "Hardcoded Polish
|
||||
text in code" (`i18n-literals` in the doctor) flagged `adminText('Title', 'Tytuł')` and `{ en: 'Title', pl: 'Tytuł' }`,
|
||||
the labels AGENT.md §6.5a asks for. The check now reads the syntax tree (`polish-literals.mjs`, with the project's
|
||||
TypeScript; a plain grep without it). In a schema file — a `.ts` file under `collections/`, `globals/`, `fields/` or
|
||||
`blocks/`, or one importing Payload's schema types — it accepts `adminText()`, `{ en, pl }` as `label`, `singular`,
|
||||
`plural`, `description`, `placeholder` or `group`, a `rowLabel()` fallback and a `const x: AdminText`, also over several
|
||||
lines. Still reported: every `.tsx` file, a Polish-only label, other keys, anything under `defaultValue`.
|
||||
|
||||
### What projects must update
|
||||
- `pnpm exec ipal-skills` after upgrading: `pnpm audit:code` runs the project's copy of the script. Nothing else.
|
||||
|
||||
## 1.15.2
|
||||
|
||||
### Fixed
|
||||
|
||||
+2
-1
@@ -748,7 +748,8 @@ empty fields, without guessing, without numbered slots. You design the schema fo
|
||||
(`ctaUrl` → "Cta Url"). Label 1–3 words, ≤ 30 characters.
|
||||
- Texts are `{ en: '…', pl: '…' }` (one key per admin language of the project):
|
||||
`label`, `admin.description`, option `label`, tab `label`, `labels.singular/plural`,
|
||||
`admin.group`. Type: `AdminText` from `@intecion/ipal-kit`.
|
||||
`admin.group`. Type: `AdminText` from `@intecion/ipal-kit`; shorthand `adminText('Title', 'Tytuł')` from
|
||||
`@intecion/ipal-kit/blocks`. In a schema file `ipal-audit` accepts both; the same words in a component are an error.
|
||||
- `admin.description` only when the label is not enough — one sentence ≤ 120 characters:
|
||||
what it does / where it shows, with a format example (`'Section id for #links, e.g. "pricing".'`),
|
||||
never how the code works (no component, function, env-var or package names).
|
||||
|
||||
@@ -30,6 +30,12 @@ following the hint (PROGRAMISTA §2) — do not ask whether it is needed. The on
|
||||
a client decision recorded in `AGENTS.md` as `ipal-audit-skip: <keys> — <reason>` (keys
|
||||
in AGENT.md §0b). Never add that line yourself just to make the audit pass.
|
||||
|
||||
## Polish text and panel labels (AGENT.md §2, §6.5a)
|
||||
`hardcoded Polish text in code` covers public text. In a schema file (a `.ts` file under `collections/`, `globals/`,
|
||||
`fields/` or `blocks/`, or one importing Payload's schema types) the panel's own labels are fine: `adminText('Title', 'Tytuł')`,
|
||||
`{ en, pl }` as `label`, `singular`, `plural`, `description`, `placeholder` or `group`, a `rowLabel()` fallback, a
|
||||
`const x: AdminText`. Still an error: any `.tsx` file, a Polish-only label, other keys, anything under `defaultValue`.
|
||||
|
||||
## Design tokens (AGENT.md §6.11)
|
||||
The script checks: hex in classes and inline styles (error), `dark:` on colour utilities and `var(--color-…)` in
|
||||
classes (warnings), `styles.css` without `@intecion/ipal-kit/tokens.css` (warning — a site not yet migrated),
|
||||
|
||||
@@ -238,8 +238,10 @@ fi
|
||||
if [ -n "$FRONT" ]; then
|
||||
report ERROR "logic keyed on content text" "§2 the editor can rename it any time — a style/flag is a panel field (e.g. buildLinkField({ appearances: [...] }))" \
|
||||
"$(g "\.(label|title|heading|name|text)\??\.(toLowerCase|toUpperCase|trim)\(\) *[!=]==? *['\"]|\.(label|title|heading)\?? *[!=]==? *['\"][^'\"]+['\"]" $FRONT --include=*.ts --include=*.tsx | grep -v '/(payload)/' | nc '==')"
|
||||
report ERROR "hardcoded Polish text in code" "§2 every visible text comes from the panel — legal links: getSystemLinks(locale) (page titles), labels: localized fields" \
|
||||
"$(g "['\"\`][^'\"\`]*[ąćęłńóśźżĄĆĘŁŃÓŚŹŻ][^'\"\`]*['\"\`]" $FRONT --include=*.ts --include=*.tsx | grep -v '/(payload)/' | nc '[ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]')"
|
||||
# The panel's own { en, pl } / adminText() labels in schema files are not public text (polish-literals.mjs); without TypeScript, a plain grep.
|
||||
POLISH=$(node "$(dirname "$0")/polish-literals.mjs" $FRONT 2>/dev/null) || \
|
||||
POLISH=$(g "['\"\`][^'\"\`]*[ąćęłńóśźżĄĆĘŁŃÓŚŹŻ][^'\"\`]*['\"\`]" $FRONT --include=*.ts --include=*.tsx | grep -v '/(payload)/' | nc '[ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]')
|
||||
report ERROR "hardcoded Polish text in code" "§2 every visible text comes from the panel — legal links: getSystemLinks(locale) (page titles), labels: localized fields; panel labels: adminText() or { en, pl } in a schema file" "$POLISH"
|
||||
fi
|
||||
GLOBALS=$(dirs src/globals)
|
||||
if [ -n "$GLOBALS" ]; then
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env node
|
||||
// Polish text hardcoded in code (AGENT.md §2) — prints "file:line: source line" per finding, exit 0.
|
||||
// node polish-literals.mjs <dir> [<dir> …]
|
||||
// Reads the syntax tree (the project's TypeScript), so comments never count and multi-line forms work.
|
||||
// Not reported: the panel's own labels (AGENT.md §6.5a), only in a schema file — a .ts file under
|
||||
// collections/, globals/, fields/ or blocks/, or one importing Payload's schema types; never a .tsx file:
|
||||
// - adminText('Title', 'Tytuł') from @intecion/ipal-kit
|
||||
// - { en: 'Title', pl: 'Tytuł' } as the value of label, singular, plural, description, placeholder or group
|
||||
// - rowLabel('title', { en: 'Item', pl: 'Pozycja' }) from @intecion/ipal-kit
|
||||
// - const TITLE: AdminText = { en: 'Title', pl: 'Tytuł' }
|
||||
// Anything under defaultValue is public content, so it is reported. So is a Polish-only label.
|
||||
// Exit 3 = TypeScript not found (audit.sh falls back to a plain grep).
|
||||
import { readFileSync, readdirSync, statSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const load = (from) => {
|
||||
try {
|
||||
return createRequire(from)('typescript')
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
const ts = load(join(process.cwd(), 'package.json')) ?? load(import.meta.url)
|
||||
if (!ts) process.exit(3)
|
||||
|
||||
const POLISH = /[ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]/
|
||||
const SCHEMA_KEYS = new Set(['label', 'singular', 'plural', 'description', 'placeholder', 'group'])
|
||||
const SCHEMA_DIR = /(?:^|\/)(?:collections|globals|fields|blocks)\//
|
||||
const SCHEMA_TYPES = /import\s+type\s*\{[^}]*\b(?:Block|CollectionConfig|Field|GlobalConfig|Tab)\b[^}]*\}\s*from\s*['"]payload['"]/
|
||||
const IPAL = /^@intecion\/ipal-kit(?:\/|$)/
|
||||
|
||||
const files = []
|
||||
const walk = (p) => {
|
||||
let st
|
||||
try { st = statSync(p) } catch { return }
|
||||
if (st.isDirectory()) for (const n of readdirSync(p)) walk(join(p, n))
|
||||
else if (/\.tsx?$/.test(p) && !/\.d\.ts$|\/\(payload\)\//.test(p)) files.push(p)
|
||||
}
|
||||
process.argv.slice(2).forEach(walk)
|
||||
|
||||
const keyName = (node) => (ts.isPropertyAssignment(node) && (ts.isIdentifier(node.name) || ts.isStringLiteralLike(node.name)) ? node.name.text : null)
|
||||
|
||||
for (const file of files) {
|
||||
const text = readFileSync(file, 'utf8')
|
||||
if (!POLISH.test(text)) continue
|
||||
const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, file.endsWith('x') ? ts.ScriptKind.TSX : ts.ScriptKind.TS)
|
||||
const schemaFile = !file.endsWith('x') && !/^['"]use client['"]/m.test(text) && (SCHEMA_DIR.test(file) || SCHEMA_TYPES.test(text))
|
||||
|
||||
// Local names of the plugin's helpers (`import { adminText as t } …`); a lookalike of your own does not count.
|
||||
const helpers = new Map()
|
||||
for (const st of source.statements) {
|
||||
if (!ts.isImportDeclaration(st) || !IPAL.test(st.moduleSpecifier.text)) continue
|
||||
const named = st.importClause?.namedBindings
|
||||
if (!named || !ts.isNamedImports(named)) continue
|
||||
for (const el of named.elements) {
|
||||
const name = (el.propertyName ?? el.name).text
|
||||
if (name === 'adminText' || name === 'rowLabel') helpers.set(el.name.text, name)
|
||||
}
|
||||
}
|
||||
|
||||
const isBilingual = (node) =>
|
||||
ts.isObjectLiteralExpression(node) && ['en', 'pl'].every((k) => node.properties.some((p) => keyName(p) === k))
|
||||
|
||||
// Is this literal one of the panel's own labels? Walks up from the literal.
|
||||
const isAdminLabel = (literal) => {
|
||||
let inside = false
|
||||
for (let node = literal; node.parent; node = node.parent) {
|
||||
const parent = node.parent
|
||||
if (keyName(parent) === 'defaultValue') return false
|
||||
if (inside) continue
|
||||
if (ts.isCallExpression(parent) && parent.arguments.includes(node) && ts.isIdentifier(parent.expression)) {
|
||||
const helper = helpers.get(parent.expression.text)
|
||||
if (helper === 'adminText') inside = true
|
||||
// rowLabel(fields, fallback): the fallback only, as { en, pl }
|
||||
if (helper === 'rowLabel' && node === parent.arguments[1] && isBilingual(node)) inside = true
|
||||
}
|
||||
if (ts.isPropertyAssignment(parent) && parent.initializer === node && SCHEMA_KEYS.has(keyName(parent)) && isBilingual(node)) inside = true
|
||||
if (ts.isVariableDeclaration(parent) && parent.initializer === node && parent.type?.getText(source) === 'AdminText' && isBilingual(node)) inside = true
|
||||
}
|
||||
return inside
|
||||
}
|
||||
|
||||
const seen = new Set()
|
||||
const visit = (node) => {
|
||||
if (ts.isImportDeclaration(node)) return
|
||||
const literal = ts.isStringLiteralLike(node) || ts.isTemplateHead(node) || ts.isTemplateMiddle(node) || ts.isTemplateTail(node)
|
||||
if (literal && POLISH.test(node.text) && !(schemaFile && isAdminLabel(node))) {
|
||||
const line = source.getLineAndCharacterOfPosition(node.getStart(source)).line
|
||||
if (!seen.has(line)) {
|
||||
seen.add(line)
|
||||
console.log(`${file}:${line + 1}:${text.split('\n')[line]}`)
|
||||
}
|
||||
}
|
||||
ts.forEachChild(node, visit)
|
||||
}
|
||||
visit(source)
|
||||
}
|
||||
+1
-1
@@ -110,7 +110,7 @@ Turn off: `ipalKit({ doctor: false })`. Adapt: `ipalKit({ doctor: { tokenVar: 'M
|
||||
| | `blocks-duplicate` | warning | a project block whose `slug` (or `interfaceName`) matches a library block — also a slug renamed through the block's `slug` option — unless it is an override in `createBlockRegistry({ components })` |
|
||||
| | `blocks-helper-copy` | warning | no local copy of a plugin field builder (`blockLibraryManifest.fieldBuilders`), `ctaHref`, `buildActionButtonsField` |
|
||||
| | `blocks-tokens` | error / warning | from `ipal-audit`: hex colours, the token standard not wired, `ipal-tokens --check` |
|
||||
| audit | `i18n-literals` | error / warning | from `ipal-audit`: hardcoded text in blocks (error) and components (warning), Polish literals in code |
|
||||
| audit | `i18n-literals` | error / warning | from `ipal-audit`: hardcoded text in blocks (error) and components (warning), Polish literals in code (not the panel's `adminText()` / `{ en, pl }` labels in a schema file — the `ipal-audit` skill) |
|
||||
| | `audit:<title>` | as reported | every other `ipal-audit --quick` finding, one per file |
|
||||
| live | `live-reachable`, `live-health`, `live-noindex`, `live-seo` | error / warning | the URL answers; `/api/health` 200; production not noindex (staging must be); every `ipal-seo-check` error and warning |
|
||||
| deep | `deep-status` | error | the deep check could not finish |
|
||||
|
||||
Reference in New Issue
Block a user