Przejdź do głównej zawartości

useNamedCaptureGroup

Ta treść nie jest jeszcze dostępna w Twoim języku.

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

Enforce using named capture groups in regular expression.

Numbered capture groups like (...) can be difficult to work with, as they are matched by their position and not by a descriptive name. Named capture groups ((?<name>...)) associate a descriptive name with each match, making the regular expression more readable and its intent clearer.

/(ba[rz])/;
code-block.js:1:2 lint/nursery/useNamedCaptureGroup ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Capture group is not named.

> 1 │ /(ba[rz])/;
^
2 │

Named capture groups improve readability by associating a descriptive name with each match. Use (?<name>…) instead of (…).

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

/([0-9]{4})/;
code-block.js:1:2 lint/nursery/useNamedCaptureGroup ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Capture group is not named.

> 1 │ /([0-9]{4})/;
^
2 │

Named capture groups improve readability by associating a descriptive name with each match. Use (?<name>…) instead of (…).

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

/(?:ab)(cd)/;
code-block.js:1:8 lint/nursery/useNamedCaptureGroup ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Capture group is not named.

> 1 │ /(?:ab)(cd)/;
^
2 │

Named capture groups improve readability by associating a descriptive name with each match. Use (?<name>…) instead of (…).

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

new RegExp("(foo)");
code-block.js:1:13 lint/nursery/useNamedCaptureGroup ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Capture group is not named.

> 1 │ new RegExp(“(foo)”);
^
2 │

Named capture groups improve readability by associating a descriptive name with each match. Use (?<name>…) instead of (…).

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

RegExp("(foo)");
code-block.js:1:9 lint/nursery/useNamedCaptureGroup ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Capture group is not named.

> 1 │ RegExp(“(foo)”);
^
2 │

Named capture groups improve readability by associating a descriptive name with each match. Use (?<name>…) instead of (…).

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

/(?<id>ba[rz])/;
/(?:ba[rz])/;
/ba[rz]/;
/(?<year>[0-9]{4})-(?<month>[0-9]{2})/;
new RegExp("(?<id>foo)");
new RegExp(pattern);