Skip to content

Latest commit

 

History

History
69 lines (49 loc) · 1.97 KB

prefer-result-array-groups.md

File metadata and controls

69 lines (49 loc) · 1.97 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/prefer-result-array-groups
enforce using result array `groups`
v1.4.0

regexp/prefer-result-array-groups

🔧 This rule is automatically fixable by the --fix CLI option.

enforce using result array groups

📖 Rule Details

This rule reports and fixes regexp result arrays where named capturing groups are accessed by index instead of using groups.

/* eslint regexp/prefer-result-array-groups: "error" */

const regex = /(?<foo>a)(b)c/g
let match
while (match = regex.exec(str)) {
    /* ✓ GOOD */
    var p1 = match.groups.foo
    var p2 = match[2]

    /* ✗ BAD */
    var p1 = match[1]
}

🔧 Options

{
  "regexp/prefer-result-array-groups": ["error", {
    "strictTypes": true
  }]
}
  • strictTypes ... If true, strictly check the type of object to determine if the string instance was used in match() and matchAll(). Default is true.
    This option is always on when using TypeScript.

👫 Related rules

🚀 Version

This rule was introduced in eslint-plugin-regexp v1.4.0

🔍 Implementation