jsx-no-literals
Configuration
Rule Details
This rule prevents the use of unwrapped string literals as direct children of JSX elements. By default, JSX text such as <div>foo</div> must be wrapped in an expression container (<div>{'foo'}</div>). When the noStrings option is enabled, even wrapped string literals are forbidden — the rule then expects values to come from translation helpers, identifiers, or other non-literal sources.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
noStrings
When true, also forbids wrapped string literals ({'foo'}, {`foo`}) inside JSX. Defaults to false.
Examples of incorrect code for this rule with { "noStrings": true }:
allowedStrings
An array of literal strings that are exempt from the rule. Surrounding whitespace on each entry is trimmed before matching, and matching is performed against the raw and cooked text of the literal.
Examples of correct code for this rule with { "noStrings": true, "allowedStrings": [" "] }:
ignoreProps
When true, attribute values are exempt from noStrings. Defaults to false.
noAttributeStrings
When true, string literals used as attribute values are reported. Defaults to false.
Examples of incorrect code for this rule with { "noAttributeStrings": true }:
restrictedAttributes
An array of attribute names. Listed attributes report on any string literal value, regardless of noStrings or noAttributeStrings.
Examples of incorrect code for this rule with { "restrictedAttributes": ["className"] }:
elementOverrides
A map from component name to a per-element override config. The element name must match the regex ^[A-Z][\w.]*$ — HTML element tag names are not supported and silently ignored. The override accepts the same keys as the top-level config plus:
allowElement— whentrue, suppress all reports inside the element.applyToNestedElements— whenfalse, only the closest matching JSX ancestor uses the override; descendant elements fall back to the base config. Defaults totrue.
When the JSX tag is renamed at import time (import { T as U } from 'foo' or const { T: U } = require('foo')), the override looks up by the imported name, not the local alias.
Examples of correct code for this rule with { "elementOverrides": { "Trans": { "allowElement": true } } }:
When Not To Use It
If your project does not need to enforce wrapping JSX text in expressions or has no localization workflow, this rule is unnecessary.