oxc-project/oxc · warning · OxcDiagnostic
Disallow string literals on restricted JSX attributes
Error message
Disallow string literals on restricted JSX attributes
What it means
Restricted-attribute diagnostic of react/jsx-no-literals. It fires when a JSX attribute listed in the restrictedAttributes array is given a string literal value — for example with restrictedAttributes: ["aria-label"], writing <button aria-label="Close"/> is reported while other attributes are ignored. This lets teams enforce i18n on specific, user-visible attributes only. Caveat from the option docs: when noAttributeStrings is true, restrictedAttributes is ignored at the root level because all attributes are already checked.
Source
Thrown at crates/oxc_linter/src/rules/react/jsx_no_literals.rs:41
context::LintContext,
rule::{DefaultRuleConfig, Rule},
utils::{default_true, is_react_component_name},
};
fn literal_text_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Disallow literal text as JSX children")
.with_help("Wrap this text in a JSX expression container, such as a call to a translation function.")
.with_label(span)
}
fn literal_attribute_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Disallow string literals in JSX attributes")
.with_help("Replace this string literal with a non-literal expression, such as a call to a translation function.")
.with_label(span)
}
fn restricted_attribute_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Disallow string literals on restricted JSX attributes")
.with_help("This attribute is listed in `restrictedAttributes`; replace its string literal value with a non-literal expression.")
.with_label(span)
}
/// The options shared between the top-level config and each `elementOverrides` entry.
#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct JsxNoLiteralsOptions {
/// (default: false) - Enforces no string literals used as children, wrapped or unwrapped.
no_strings: bool,
/// An array of unique string values that would otherwise warn, but will be ignored.
allowed_strings: Vec<CompactStr>,
/// (default: false) - When true the rule ignores literals used in props, wrapped or unwrapped.
ignore_props: bool,
/// (default: false) - Enforces no string literals used in attributes when set to true.
no_attribute_strings: bool,
/// An array of unique attribute names where string literals should be restricted. Only the specified attributes will be checked for string literals when this option is used. Note: When noAttributeStrings is true, this option is ignored at the root level.
restricted_attributes: Vec<CompactStr>,View on GitHub (pinned to e1e7af627c)
Solutions
- Replace the literal with an expression: aria-label={t('close')}
- Remove the attribute from restrictedAttributes if literal values are acceptable there
- Remember the precedence: with noAttributeStrings: true at the root, restrictedAttributes has no effect — drop noAttributeStrings to scope checks
- Scope restrictions per element with elementOverrides instead of globally when only some components need it
Example fix
// before (restrictedAttributes: ["aria-label"])
<button aria-label="Close" onClick={close} />
// after
<button aria-label={t('a11y.close')} onClick={close} /> Defensive patterns
Strategy: validation
Validate before calling
npx oxlint -D react/jsx-no-literals src/ # with restrictedAttributes: ["aria-label", ...]
Prevention
- List only genuinely user-visible attributes in restrictedAttributes (aria-label, title, alt) to keep the policy targeted
- Note the precedence rule: with noAttributeStrings: true at the root, restrictedAttributes is ignored
- Scope restrictions to specific components with elementOverrides instead of global lists where possible
When it happens
Trigger: Config { "restrictedAttributes": ["aria-label", "title"] } plus <button aria-label="Close"/>, <div title="Details"/>, or a component override carrying its own restrictedAttributes list receiving a string literal on one of those props.
Common situations: Accessibility-driven i18n policies (aria-label, alt, title are screen-reader visible); design systems restricting label props on specific components via elementOverrides; confusion when restrictedAttributes seems inert because noAttributeStrings: true overrides it.
Related errors
- Disallow literal text as JSX children
- Disallow string literals in JSX attributes
- Missing value for `aria-label` attribute.
- Missing value for `aria-labelledby` attribute.
- ARIA used where native HTML could suffice.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/fa44796ecc4fec67.
Report an issue: GitHub.