{"record":{"id":"be80d0e81b1b85f4","repo":"oxc-project/oxc","slug":"disallow-literal-text-as-jsx-children","errorCode":null,"errorMessage":"Disallow literal text as JSX children","messagePattern":"Disallow literal text as JSX children","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/react/jsx_no_literals.rs","lineNumber":29,"sourceCode":"        JSXAttributeName, JSXAttributeValue, JSXChild, JSXElement, JSXElementName, JSXExpression,\n        JSXFragment, JSXMemberExpression, JSXMemberExpressionObject, ModuleExportName, PropertyKey,\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse 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)]","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/jsx_no_literals.rs#L11-L47","documentation":"Children-case diagnostic of react/jsx-no-literals (category: restriction). It fires only when noStrings is set to true (default false): string literals used as JSX children — wrapped or unwrapped — are disallowed. The motivation is i18n: user-facing text should flow through an expression such as a translation function instead of being hard-coded as markup text, so strings are auditable in one place.","triggerScenarios":"Config { \"noStrings\": true } plus <div>Hello world</div> (unwrapped) or <div>{'Hello world'}</div> (wrapped literal). Exceptions: strings listed in allowedStrings, and elements opted out via elementOverrides with allowElement: true.","commonSituations":"Enabling the rule on a legacy codebase full of hard-coded copy before an internationalization effort; teams using i18next/Lingua-style t() functions wanting to guarantee no untranslated strings; accidental reports for punctuation/symbols that should go into allowedStrings.","solutions":["Replace the literal with an expression, typically a translation call: <div>{t('hello.world')}</div>","Whitelist intentional literals via allowedStrings: [\"•\", \"—\"]","Permit specific elements to keep raw text via elementOverrides: { \"kbd\": { \"allowElement\": true } }","If the policy is too strict for now, leave noStrings false (the default) and enable it incrementally per directory"],"exampleFix":"// before (noStrings: true)\n<div>Hello world</div>\n\n// after\n<div>{t('hello.world')}</div>","handlingStrategy":"validation","validationCode":"npx oxlint -D react/jsx-no-literals src/  # with noStrings: true in .oxlintrc.json","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Route all user-facing copy through a translation function from the start; retrofitting is far more expensive","Whitelist punctuation/symbols in allowedStrings early so the rule's signal stays clean","Roll out noStrings per directory or use elementOverrides for elements that legitimately hold raw text"],"tags":["react","jsx","i18n","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"}