async function updateTypeDeclaration(ruleTypeFile, consideredRuleIds, check) {
	const sourceText = await readFile(ruleTypeFile, "utf-8");
	const textPositionsMap = getTextPositionsMap(sourceText, consideredRuleIds);
	const sortedRuleIds = [...textPositionsMap.keys()].sort();
	const chunks = [];
	let lastPos = 0;

	for (const [
		,
		{ tsDocStart: insertStart, typeEnd: insertEnd },
	] of textPositionsMap) {
		const textBeforeTSDoc = sourceText.slice(lastPos, insertStart);
		const ruleId = sortedRuleIds.shift();
		const { tsDocEnd, typeEnd } = textPositionsMap.get(ruleId);
		const tsDoc = createTSDoc(ruleId);
		const ruleText = sourceText.slice(tsDocEnd, typeEnd);

		chunks.push(textBeforeTSDoc, tsDoc);
		if (sourceText[tsDocEnd] !== "\n") {
			chunks.push("\n    ");
		}
		chunks.push(ruleText);
		lastPos = insertEnd;
	}
	chunks.push(sourceText.slice(Math.max(0, lastPos)));
	const newSourceText = chunks.join("");

	if (newSourceText !== sourceText) {
		if (check) {
			throw new Error(
				"The rule types are not up-to-date. Please, run `node tools/update-rule-type-headers.js` to fix.",
			);
		}
		await writeFile(ruleTypeFile, newSourceText);
	}
	return textPositionsMap.keys();
}
Updates rule header comments in a `.d.ts` file or checks if a `.d.ts` file is up-to-date.
@param {string} ruleTypeFile Pathname of the `.d.ts` file.
@param {Set<string>} consideredRuleIds The names of the rules to be considered for the current run.
@param {boolean} check Whether to throw an error if the `.d.ts` file is not up-to-date.
@returns {Promise<Iterable<string>>} The names of the rules found in the `.d.ts` file.