WidthBudgetRule class
Warn when a string is too long for the UI slot it renders in.
This is the "size-aware translation" guard. Text expands when
translated — "Edit profile" (12) → "Chỉnh sửa trang cá nhân" (23) — and
a faithful-but-long value silently breaks a tight button. The
LengthRatioRule can't catch that: 23/12 is 1.9×, well inside its
[0.3, 2.5] smell-band. What's missing is a budget tied to the slot.
Opt-in by construction. A key is only checked if its SOURCE @key
block declares a budget. Body copy, legal text, empty-state prose —
anything with room — is never annotated and never policed.
Two ways to declare a budget on the source @key:
"editProfile": "Edit profile",
"@editProfile": { "x-slot": "button" } // policy from dialect.yaml
"statusChip": "Live",
"@statusChip": { "x-max-length": 6 } // hard character cap
Slot policies live once in dialect.yaml:
slots:
button: { max_ratio: 1.4 } # stay within ~1.4× the source ("similar length")
chip: { max_length: 10 } # a real pixel slot → absolute cap
tab: { max_ratio: 1.2, grace: 2 }
A max_ratio budget is max(round(sourceLen × ratio), sourceLen + grace) — the grace floor (default _defaultGrace) keeps the shortest
labels ("Save" → "Lưu") from tripping on a ratio that's meaningless at
3 chars. max_length is absolute and can flag an over-tight source
(English itself busting the slot) as well as a translation.
Severity is warning, and --strict alone does NOT promote it — like
length_ratio, it needs the explicit --strict-length opt-in. A button
that runs a few chars long is a nudge for the next author/agent to
tighten, not a reason to fail the build. It's a convention, enforced
softly (and ack-able), by design.
Length is measured on the literal text (IcuMessage.literalText) in Unicode code points, so ICU placeholder names don't inflate the count. A value with runtime placeholders is inherently fuzzy to budget; put budgets on tight static labels, which is where overflow actually bites.
Constructors
- WidthBudgetRule()
-
const
Properties
- defaultSeverity → IssueSeverity
-
Default severity. May be overridden per-issue.
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
Stable rule identifier (snake_case). Used by the report formatter
to group findings and by users to silence/ack via state file
(post-v1.0).
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
run(
DialectProject project) → List< Issue> -
Inspect
projectand return findings. May return an empty list. Should NOT throw — turn unexpected conditions into Issues so the report surfaces them rather than crashing.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited