{"record":{"id":"fa44796ecc4fec67","repo":"oxc-project/oxc","slug":"disallow-string-literals-on-restricted-jsx-attribu","errorCode":null,"errorMessage":"Disallow string literals on restricted JSX attributes","messagePattern":"Disallow string literals on restricted JSX attributes","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/react/jsx_no_literals.rs","lineNumber":41,"sourceCode":"    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::{default_true, is_react_component_name},\n};\n\nfn literal_text_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Disallow literal text as JSX children\")\n        .with_help(\"Wrap this text in a JSX expression container, such as a call to a translation function.\")\n        .with_label(span)\n}\n\nfn literal_attribute_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Disallow string literals in JSX attributes\")\n        .with_help(\"Replace this string literal with a non-literal expression, such as a call to a translation function.\")\n        .with_label(span)\n}\n\nfn restricted_attribute_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Disallow string literals on restricted JSX attributes\")\n        .with_help(\"This attribute is listed in `restrictedAttributes`; replace its string literal value with a non-literal expression.\")\n        .with_label(span)\n}\n\n/// The options shared between the top-level config and each `elementOverrides` entry.\n#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct JsxNoLiteralsOptions {\n    /// (default: false) - Enforces no string literals used as children, wrapped or unwrapped.\n    no_strings: bool,\n    /// An array of unique string values that would otherwise warn, but will be ignored.\n    allowed_strings: Vec<CompactStr>,\n    /// (default: false) - When true the rule ignores literals used in props, wrapped or unwrapped.\n    ignore_props: bool,\n    /// (default: false) - Enforces no string literals used in attributes when set to true.\n    no_attribute_strings: bool,\n    /// 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.\n    restricted_attributes: Vec<CompactStr>,","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/jsx_no_literals.rs#L23-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (restrictedAttributes: [\"aria-label\"])\n<button aria-label=\"Close\" onClick={close} />\n\n// after\n<button aria-label={t('a11y.close')} onClick={close} />","handlingStrategy":"validation","validationCode":"npx oxlint -D react/jsx-no-literals src/  # with restrictedAttributes: [\"aria-label\", ...]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["react","jsx","i18n","accessibility","aria","string-literals","restriction","oxlint","lint"],"backgroundTag":"jsx-no-literals-i18n","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}