Skip to content

Commit bb25c9b

Browse files
committed
wip(lint): cancelText translation under a dialog-less action is translation-target-unknown
Claude-Session: https://claude.ai/code/session_01ADHkmNhdF5oapRdMKNBctQ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9db11f1 commit bb25c9b

2 files changed

Lines changed: 78 additions & 2 deletions

File tree

‎packages/lint/src/validate-translation-references.test.ts‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4039,6 +4039,40 @@ describe('validateTranslationReferences — keyed children of an action entry (#
40394039
});
40404040
});
40414041

4042+
describe('cancelText — the dismiss button of either pre-run dialog (#28519)', () => {
4043+
// `actionStack` declares no `confirmText` anywhere, so the confirm
4044+
// dialog's host is added here: a param-less action that asks first.
4045+
const withConfirmHost = (bundle: Record<string, unknown>) => {
4046+
const stack = actionStack(bundle);
4047+
(stack.actions as Array<Record<string, unknown>>).push({
4048+
name: 'retire_env',
4049+
label: 'Retire',
4050+
objectName: 'crm_env',
4051+
type: 'script',
4052+
target: 'retireEnv',
4053+
confirmText: 'Retire this environment?',
4054+
});
4055+
return stack;
4056+
};
4057+
4058+
it('errors on a `cancelText` under an action that declares neither confirmText nor params, at both addresses', () => {
4059+
const findings = validateTranslationReferences(
4060+
withConfirmHost({ ...onEnv({ plain_env: { cancelText: '保留' } }), globalActions: { mint_token: { cancelText: '保留' } } }),
4061+
);
4062+
expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([
4063+
[TRANSLATION_TARGET_UNKNOWN, 'error', `${ENV}.plain_env.cancelText`],
4064+
[TRANSLATION_TARGET_UNKNOWN, 'error', `${GLOBAL}.mint_token.cancelText`],
4065+
]);
4066+
expect(findings[0].message).toMatch(/^Translations carry a dialog `cancelText`, but action "plain_env" declares neither `confirmText` nor `params`/);
4067+
});
4068+
4069+
it('accepts it under the confirm dialog\'s host and under the param dialog\'s host (the controls)', () => {
4070+
expect(
4071+
validateTranslationReferences(withConfirmHost(onEnv({ retire_env: { cancelText: '保留' }, archive_env: { cancelText: '不归档' } }))),
4072+
).toEqual([]);
4073+
});
4074+
});
4075+
40424076
describe('params.<name>.options.<value>', () => {
40434077
it('warns on an option key a declared param does not declare, as the field `options` leg does', () => {
40444078
const findings = validateTranslationReferences(
@@ -4115,7 +4149,7 @@ describe('validateTranslationReferences — keyed children of an action entry (#
41154149
};
41164150

41174151
type Address = 'bound' | 'global';
4118-
type Host = 'outcome' | 'dialog' | 'noDialog' | 'noParams';
4152+
type Host = 'outcome' | 'dialog' | 'noDialog' | 'noParams' | 'noPreRunDialog';
41194153
/**
41204154
* Which declared action a ghost is written under, per address. `noDialog`
41214155
* names an action that declares no `resultDialog`: the dialog's leaves
@@ -4129,6 +4163,9 @@ describe('validateTranslationReferences — keyed children of an action entry (#
41294163
// `submitText` has no button to land on (`coverageStack` gives
41304164
// `check_updates` params, so the global host is `mint_token`).
41314165
noParams: { bound: 'plain_env', global: 'mint_token' },
4166+
// [#28519] An action with neither `confirmText` nor `params` opens no
4167+
// dialog before it runs, so its `cancelText` has no button to land on.
4168+
noPreRunDialog: { bound: 'plain_env', global: 'mint_token' },
41324169
};
41334170
type Coverage =
41344171
| { kind: 'reference-checked'; host: Host; ghost: Record<string, unknown>; suffix: string; rule: string }
@@ -4147,6 +4184,13 @@ describe('validateTranslationReferences — keyed children of an action entry (#
41474184
suffix: '.submitText',
41484185
rule: TRANSLATION_TARGET_UNKNOWN,
41494186
},
4187+
cancelText: {
4188+
kind: 'reference-checked',
4189+
host: 'noPreRunDialog',
4190+
ghost: { cancelText: 'x' },
4191+
suffix: '.cancelText',
4192+
rule: TRANSLATION_TARGET_UNKNOWN,
4193+
},
41504194
outcomeMessages: {
41514195
kind: 'reference-checked',
41524196
host: 'outcome',
@@ -4250,6 +4294,7 @@ describe('validateTranslationReferences — keyed children of an action entry (#
42504294
confirmText: 'x',
42514295
successMessage: 'x',
42524296
submitText: 'x',
4297+
cancelText: 'x',
42534298
outcomeMessages: address === 'bound' ? { archived: 'x' } : { up_to_date: 'x' },
42544299
params: { mode: { label: 'x', helpText: 'x', placeholder: 'x', options: { soft: 'x' } } },
42554300
},

‎packages/lint/src/validate-translation-references.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2660,14 +2660,18 @@ interface ActionEntryContext {
26602660
* | `resultDialog.fields.<path>` | `resultDialog.fields[].path` | `resolveActionResultDialog` |
26612661
* | `resultDialog.title` / `.description` / `.acknowledge` | the action's `resultDialog`, present at all | `resolveActionResultDialog` |
26622662
* | `submitText` | a non-empty `params` (the param dialog) | `translateAction` |
2663+
* | `cancelText` | `confirmText` or a non-empty `params` (either dialog) | `translateAction` |
26632664
*
26642665
* A dialog leaf under a DECLARED dialog is read whether or not the dialog
26652666
* authors that leaf itself — the resolver overlays a translated `title` onto a
26662667
* dialog that declares none — so declaring the dialog is the whole condition.
26672668
*
26682669
* `submitText` is the param dialog's button, the one leaf with a host of its
26692670
* own: the dialog opens only for a non-empty `params`, and `translateAction`
2670-
* overlays the key only then (#27944). The leaf keys beside them (`label`,
2671+
* overlays the key only then (#27944). `cancelText` is the dismiss button both
2672+
* pre-run dialogs carry, so its host is either one: a declared `confirmText`
2673+
* (the confirm dialog) or a non-empty `params` (the param dialog) (#28519).
2674+
* The leaf keys beside them (`label`,
26712675
* `description`, `confirmText`, `successMessage`, `disabledReason`) are prose
26722676
* on a node that resolved, read whenever the action is, as on the object
26732677
* branch.
@@ -2684,6 +2688,7 @@ function checkActionEntry(findings: TranslationRefFinding[], ctx: ActionEntryCon
26842688
checkActionResultDialogLeaves(findings, ctx);
26852689
checkActionResultDialogFields(findings, ctx);
26862690
checkActionSubmitText(findings, ctx);
2691+
checkActionCancelText(findings, ctx);
26872692
}
26882693

26892694
/**
@@ -2711,6 +2716,32 @@ function checkActionSubmitText(findings: TranslationRefFinding[], ctx: ActionEnt
27112716
});
27122717
}
27132718

2719+
/**
2720+
* [#28519] `cancelText` — the label of the dismiss button on the dialog an
2721+
* action opens before it runs. Two dialogs carry that button: the confirm
2722+
* dialog of a declared `confirmText` and the param dialog of a non-empty
2723+
* `params`; `translateAction` overlays the key only for an action that opens
2724+
* one of them, so under any other action the translation is read by nothing —
2725+
* {@link checkActionSubmitText}'s rule, with either declaration as the host.
2726+
*/
2727+
function checkActionCancelText(findings: TranslationRefFinding[], ctx: ActionEntryContext): void {
2728+
if (!isRec(ctx.rawAction) || ctx.rawAction.cancelText === undefined) return;
2729+
if (ctx.action.confirmText != null) return;
2730+
if (Array.isArray(ctx.action.params) && ctx.action.params.length > 0) return;
2731+
findings.push({
2732+
severity: TRANSLATION_TARGET_UNKNOWN_SEVERITY,
2733+
rule: TRANSLATION_TARGET_UNKNOWN,
2734+
where: `${ctx.where} · dismiss button`,
2735+
path: `${ctx.path}.cancelText`,
2736+
message:
2737+
`Translations carry a dialog \`cancelText\`, but ${ctx.subject} declares neither ` +
2738+
`\`confirmText\` nor \`params\`, so it opens no confirm or param dialog and nothing reads this label.`,
2739+
hint:
2740+
`Move the \`cancelText\` translation under the action whose dialog it dismisses, declare the ` +
2741+
`\`confirmText\` or \`params\` that opens the dialog on this action first, or drop it.`,
2742+
});
2743+
}
2744+
27142745
/** Action-parameter translations are keyed by the param's `name`. */
27152746
function checkActionParams(findings: TranslationRefFinding[], ctx: ActionEntryContext): void {
27162747
const rawParams = asRecord(isRec(ctx.rawAction) ? ctx.rawAction.params : undefined);

0 commit comments

Comments
 (0)