{"record":{"id":"9678b4654e3a2335","repo":"oxc-project/oxc","slug":"disallow-string-literals-in-jsx-attributes","errorCode":null,"errorMessage":"Disallow string literals in JSX attributes","messagePattern":"Disallow string literals in JSX attributes","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/react/jsx_no_literals.rs","lineNumber":35,"sourceCode":"use oxc_semantic::SymbolId;\nuse oxc_span::Span;\nuse oxc_str::CompactStr;\n\nuse crate::{\n    AstNode,\n    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>,","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/jsx_no_literals.rs#L17-L53","documentation":"Attribute-case diagnostic of react/jsx-no-literals. It fires when noAttributeStrings is true (default false) and a JSX attribute is assigned a plain string literal, e.g. <input placeholder=\"Search\" />. Like the children case, the goal is i18n and auditability: attribute values that users see should come from an expression (such as a translation function) rather than a hard-coded string. The help text says to replace the literal with a non-literal expression.","triggerScenarios":"Config { \"noAttributeStrings\": true } plus any attribute with a StringLiteral value: <img alt=\"Logo\"/>, <input placeholder=\"Email\"/>, <Button label=\"Save\"/>. Values in allowedStrings are exempt; elementOverrides can relax specific elements.","commonSituations":"Extending a no-literals i18n policy from children to attributes; UI libraries whose visible labels (aria-label, title, placeholder) must be translated; migrating from eslint-plugin-react configs where this was the noStrings+ignoreProps interplay — here it is a dedicated noAttributeStrings flag.","solutions":["Replace the literal attribute value with an expression: placeholder={t('search.placeholder')}","Whitelist genuinely local literals (symbols, constants) via allowedStrings","Relax specific components with elementOverrides (e.g. allow a design-system Button's label)","Turn the option off (noAttributeStrings defaults to false) if attribute strings are acceptable"],"exampleFix":"// before (noAttributeStrings: true)\n<input placeholder=\"Search\" />\n\n// after\n<input placeholder={t('search.placeholder')} />","handlingStrategy":"validation","validationCode":"npx oxlint -D react/jsx-no-literals src/  # with noAttributeStrings: true","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep user-visible attribute values (placeholder, alt, title, labels) sourced from the i18n layer","Set allowedStrings for stable literals like units and symbols to avoid noise","Remember ignoreProps and noAttributeStrings are separate switches — decide once, in config, which side each attribute class falls on"],"tags":["react","jsx","i18n","string-literals","attributes","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"}