Repository: eslint/eslint
File: lib/rules/prefer-named-capture-group.js (JavaScript)

Code before:
/**
 * @fileoverview Rule to enforce requiring named capture groups in regular expression.
 * @author Pig Fang <https://github.com/g-plane>
 */

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const {
	CALL,
	CONSTRUCT,
	ReferenceTracker,
	getStringIfConstant,
} = require("@eslint-community/eslint-utils");
const regexpp = require("@eslint-community/regexpp");

//------------------------------------------------------------------------------
// Typedefs
//------------------------------------------------------------------------------

/** @typedef {import("../types").Linter.LintSuggestion} SuggestionResult */

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

const parser = new regexpp.RegExpParser();

/**
 * Creates fixer suggestions for the regex, if statically determinable.
 * @param {number} groupStart Starting index of the regex group.
 * @param {string} pattern The regular expression pattern to be checked.
 * @param {string} rawText Source text of the regexNode.
 * @param {ASTNode} regexNode AST node which contains the regular expression.
 * @returns {Array<SuggestionResult>} Fixer suggestions for the regex, if statically determinable.
 */
function suggestIfPossible(groupStart, pattern, rawText, regexNode) {
	switch (regexNode.type) {
		case "Literal":
			if (typeof regexNode.value === "string" && rawText.includes("\\")) {
				return null;
			}
			break;
		case "TemplateLiteral":
			if (
				regexNode.expressions.length ||

Review comment (suggestion):
I think `function suggestIfPossible()`, where this type is used, doesn't return an array of `Linter.LintSuggestion` (which are processed suggestions, where `fix` is `{ range, text }`) but an array of [`SuggestedEdit`](https://github.com/eslint/rewrite/blob/4ec089e5b60d64f695d09a973dbc4eb72026f112/packages/core/src/types.ts#L541C13-L541C26) (where `fix` is a function).

Code after:
/**
 * @fileoverview Rule to enforce requiring named capture groups in regular expression.
 * @author Pig Fang <https://github.com/g-plane>
 */

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const {
	CALL,
	CONSTRUCT,
	ReferenceTracker,
	getStringIfConstant,
} = require("@eslint-community/eslint-utils");
const regexpp = require("@eslint-community/regexpp");

//------------------------------------------------------------------------------
// Typedefs
//------------------------------------------------------------------------------

/** @import { SuggestedEdit } from "@eslint/core"; */

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

const parser = new regexpp.RegExpParser();

/**
 * Creates fixer suggestions for the regex, if statically determinable.
 * @param {number} groupStart Starting index of the regex group.
 * @param {string} pattern The regular expression pattern to be checked.
 * @param {string} rawText Source text of the regexNode.
 * @param {ASTNode} regexNode AST node which contains the regular expression.
 * @returns {Array<SuggestedEdit>} Fixer suggestions for the regex, if statically determinable.
 */
function suggestIfPossible(groupStart, pattern, rawText, regexNode) {
	switch (regexNode.type) {
		case "Literal":
			if (typeof regexNode.value === "string" && rawText.includes("\\")) {
				return null;
			}
			break;
		case "TemplateLiteral":
			if (
				regexNode.expressions.length ||