Aller au contenu

noJsxLiterals

Ce contenu n’est pas encore disponible dans votre langue.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noJsxLiterals": "error"
}
}
}
}

Disallow string literals inside JSX elements.

This rule discourages the use of string literals directly within JSX elements. String literals in JSX can make code harder to maintain, especially in applications that require internationalization or dynamic content.

<div>Hello World</div>
code-block.jsx:1:6 lint/nursery/noJsxLiterals ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Incorrect use of string literal detected.

> 1 │ <div>Hello World</div>
^^^^^^^^^^^
2 │

String literals in JSX can make code harder to maintain and internationalize.

Consider avoiding hardcoded strings entirely.

<>Welcome to our site</>
code-block.jsx:1:3 lint/nursery/noJsxLiterals ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Incorrect use of string literal detected.

> 1 │ <>Welcome to our site</>
^^^^^^^^^^^^^^^^^^^
2 │

String literals in JSX can make code harder to maintain and internationalize.

Consider avoiding hardcoded strings entirely.

<span>
Please enter your name
</span>
code-block.jsx:1:7 lint/nursery/noJsxLiterals ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Incorrect use of string literal detected.

> 1 │ <span>

> 2 │ Please enter your name
> 3 │ </span>

4 │

String literals in JSX can make code harder to maintain and internationalize.

Consider avoiding hardcoded strings entirely.

<div>{'Hello World'}</div>
<>{'Welcome to our site'}</>
<span>
{'Please enter your name'}
</span>
<div>{`Hello ${name}`}</div>

When enabled, the rule will also flag string literals inside JSX expressions and attributes.

Default: false

biome.json
{
"linter": {
"rules": {
"nursery": {
"noJsxLiterals": {
"options": {
"noStrings": true
}
}
}
}
}
}
<span>
{'Please enter your name'}
</span>
<Component title="Hello!" />

An array of strings that are allowed as literals. This can be useful for common words or characters that don’t need to be wrapped in expressions.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noJsxLiterals": {
"options": {
"allowedStrings": [
"Hello",
"&nbsp;",
"·"
]
}
}
}
}
}
}
<>
<div>Hello</div>
<div>&nbsp;</div>
<div>·</div>
</>

When enabled, the rule will ignore string literals used as prop values.

Default: false

biome.json
{
"linter": {
"rules": {
"nursery": {
"noJsxLiterals": {
"options": {
"ignoreProps": true
}
}
}
}
}
}
<>
<Component title="Welcome" />
<input placeholder="Enter name" />
</>