async function findProblems(filename) {
	const text = await readFile(filename, "UTF-8");
	const { title } = matter(text).data;
	const isRuleRemoved = !rules.has(title);
	const problems = [];
	const ruleExampleOptions = markdownItRuleExample({
		open({ code, type, languageOptions = {}, codeBlockToken }) {
			const languageTag = codeBlockToken.info;

			if (!STANDARD_LANGUAGE_TAGS.has(languageTag)) {
				/*
				 * Missing language tags are also reported by Markdownlint rule MD040 for all code blocks,
				 * but the message we output here is more specific.
				 */
				const message = `${
					languageTag
						? `Nonstandard language tag '${languageTag}'`
						: "Missing language tag"
				}: use one of 'javascript', 'js', 'jsx', 'ts', or 'tsx'`;

				problems.push({
					fatal: false,
					severity: 2,
					message,
					line: codeBlockToken.map[0] + 1,
					column: codeBlockToken.markup.length + 1,
				});
			}

			if (typeof languageOptions?.ecmaVersion !== "undefined") {
				const { ecmaVersion } = languageOptions;
				let ecmaVersionErrorMessage;

				if (ecmaVersion === "latest") {
					ecmaVersionErrorMessage =
						'Remove unnecessary "ecmaVersion":"latest".';
				} else if (typeof ecmaVersion !== "number") {
					ecmaVersionErrorMessage = '"ecmaVersion" must be a number.';
				} else if (!VALID_ECMA_VERSIONS.has(ecmaVersion)) {
					ecmaVersionErrorMessage = `"ecmaVersion" must be one of ${[...VALID_ECMA_VERSIONS].join(", ")}.`;
				}

				if (ecmaVersionErrorMessage) {
					problems.push({
						fatal: false,
						severity: 2,
						message: ecmaVersionErrorMessage,
						line: codeBlockToken.map[0] - 1,
						column: 1,
					});

					return;
				}
			}

			if (TYPESCRIPT_LANGUAGE_TAGS.has(languageTag)) {
				languageOptions.parser = tsParser;
			}

			const linter = new Linter();
			let lintMessages;

			try {
				lintMessages = linter.verify(code, { languageOptions });
			} catch (error) {
				problems.push({
					fatal: true,
					severity: 2,
					message: `Configuration error: ${error.message}`,
					line: codeBlockToken.map[0] - 1,
					column: 1,
				});

				return;
			}

			// for removed rules, leave only parsing errors
			if (isRuleRemoved) {
				lintMessages = lintMessages.filter(
					lintMessage => lintMessage.fatal,
				);
			} else {
				if (type === "incorrect") {
					const { length } = lintMessages;

					// filter out errors reported by the rule as they are expected in incorrect examples
					lintMessages = lintMessages.filter(
						lintMessage =>
							lintMessage.ruleId !== title ||
							lintMessage.fatal ||
							lintMessage.message.includes(
								`Inline configuration for rule "${title}" is invalid`,
							),
					);

					if (
						lintMessages.length === length &&
						!lintMessages.some(lintMessage => lintMessage.fatal)
					) {
						problems.push({
							fatal: false,
							severity: 2,
							message:
								"Incorrect examples should have at least one error reported by the rule.",
							line: codeBlockToken.map[0] + 2,
							column: 1,
						});
					}
				}
			}

			problems.push(
				...lintMessages.map(lintMessage => ({
					...lintMessage,
					message: `Unexpected lint error found: ${lintMessage.message}`,
					line: codeBlockToken.map[0] + 1 + lintMessage.line,
				})),
			);

			const sourceCode = linter.getSourceCode();

			if (sourceCode) {
				const { ast } = sourceCode;
				let hasRuleConfigComment = false;

				for (const comment of ast.comments) {
					if (
						comment.type === "Block" &&
						/^\s*eslint-env(?!\S)/u.test(comment.value)
					) {
						problems.push({
							fatal: false,
							severity: 2,
							message:
								"/* eslint-env */ comments are no longer supported. Remove the comment.",
							line:
								codeBlockToken.map[0] +
								1 +
								comment.loc.start.line,
							column: comment.loc.start.column + 1,
						});
					}

					if (
						comment.type !== "Block" ||
						!/^\s*eslint(?!\S)/u.test(comment.value)
					) {
						continue;
					}
					const { value } = commentParser.parseDirective(
						comment.value,
					);
					const parseResult =
						commentParser.parseJSONLikeConfig(value);

					if (
						parseResult.ok &&
						Object.hasOwn(parseResult.config, title)
					) {
						if (hasRuleConfigComment) {
							problems.push({
								fatal: false,
								severity: 2,
								message: `Duplicate /* eslint ${title} */ configuration comment. Each example should contain only one. Split this example into multiple examples.`,
								line:
									codeBlockToken.map[0] +
									1 +
									comment.loc.start.line,
								column: comment.loc.start.column + 1,
							});
						}
						hasRuleConfigComment = true;
					}
				}

				if (!isRuleRemoved && !hasRuleConfigComment) {
					const message = `Example code should contain a configuration comment like /* eslint ${title}: "error" */`;

					problems.push({
						fatal: false,
						severity: 2,
						message,
						line: codeBlockToken.map[0] + 2,
						column: 1,
					});
				}
			}
		},
	});

	// Run `markdown-it` to check rule examples in the current file.
	markdownIt({ html: true })
		.use(markdownItContainer, "rule-example", ruleExampleOptions)
		.render(text);
	return problems;
}
Checks the example code blocks in a rule documentation file.
@param {string} filename The file to be checked.
@returns {Promise<LintMessage[]>} A promise of problems found. The promise will be rejected if an error occurs.