Repository: eslint/eslint
File: tools/check-rule-examples.js (JavaScript)

Code before:
                    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
                    });
                }
            }

            const { ast, error } = tryParseForPlayground(code, parserOptions);

            if (ast) {
                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 { directiveValue } = commentParser.parseDirective(comment);
                    const parseResult = commentParser.parseJsonConfig(directiveValue, comment.loc);
                    const parseError = parseResult.error;

                    if (parseError) {
                        parseError.line += codeBlockToken.map[0] + 1;
                        problems.push(parseError);
                    } else if (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.`,

Review comment (suggestion):
```suggestion
                    if (comment.type === "Block" && /^\s*eslint-env(?!\S)/u.test(comment.value)) {
```

To match also empty `/*eslint-env*/` comments.

Code after:
                    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
                    });
                }
            }

            const { ast, error } = tryParseForPlayground(code, parserOptions);

            if (ast) {
                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 { directiveValue } = commentParser.parseDirective(comment);
                    const parseResult = commentParser.parseJsonConfig(directiveValue, comment.loc);
                    const parseError = parseResult.error;

                    if (parseError) {
                        parseError.line += codeBlockToken.map[0] + 1;
                        problems.push(parseError);
                    } else if (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.`,