useNamedCaptureGroup
Цей контент ще не доступний вашою мовою.
Summary
Section titled “Summary”- Rule available since:
v2.4.5 - Diagnostic Category:
lint/nursery/useNamedCaptureGroup - This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
prefer-named-capture-group
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useNamedCaptureGroup": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”/(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);Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.