ronantakizawa/codereview-bench huggingface dataset:
Repository: eslint/eslint
File: lib/linter/vfile.js (JavaScript)

Code before:
     * The raw body of the file, including a BOM if present.
     * @type {string|Uint8Array}
     * @readonly
     */
    rawBody;

    /**
     * Indicates whether the file has a byte order mark (BOM).
     * @type {boolean}
     * @readonly
     */
    bom;

    /**
     * Creates a new instance.
     * @param {string} path The file path.
     * @param {string|Uint8Array} body The file contents.
     * @param {Object} [options] Additional options.
     * @param {string} [options.physicalPath] The file path on disk.
     */
    constructor(path, body, { physicalPath } = {}) {
        this.path = path;
        this.physicalPath = physicalPath ?? path;
        this.bom = hasUnicodeBOM(body);
        this.body = stripUnicodeBOM(body);
        this.rawBody = this.bom ? body : this.body;
    }
}

module.exports = { VFile };


Review comment (suggestion):
Right now, we actually pass the raw file contents to processors, which includes the BOM if present. I added this to make existing tests pass, however, I think it would be better to always strip the BOM before passing to a processor.

This wouldn't be a breaking change because processors must always check for the presence of BOMs right now as they don't know if one will be passed.

Code after:
     * The raw body of the file, including a BOM if present.
     * @type {string|Uint8Array}
     * @readonly
     */
    rawBody;

    /**
     * Indicates whether the file has a byte order mark (BOM).
     * @type {boolean}
     * @readonly
     */
    bom;

    /**
     * Creates a new instance.
     * @param {string} path The file path.
     * @param {string|Uint8Array} body The file contents.
     * @param {Object} [options] Additional options.
     * @param {string} [options.physicalPath] The file path on disk.
     */
    constructor(path, body, { physicalPath } = {}) {
        this.path = path;
        this.physicalPath = physicalPath ?? path;
        this.bom = hasUnicodeBOM(body);
        this.body = stripUnicodeBOM(body);
        this.rawBody = body;
    }
}

module.exports = { VFile };
Repository: eslint/eslint
File: lib/linter/vfile.js (JavaScript)

Code before:
     * The raw body of the file, including a BOM if present.
     * @type {string|Uint8Array}
     * @readonly
     */
    rawBody;

    /**
     * Indicates whether the file has a byte order mark (BOM).
     * @type {boolean}
     * @readonly
     */
    bom;

    /**
     * Creates a new instance.
     * @param {string} path The file path.
     * @param {string|Uint8Array} body The file contents.
     * @param {Object} [options] Additional options.
     * @param {string} [options.physicalPath] The file path on disk.
     */
    constructor(path, body, { physicalPath } = {}) {
        this.path = path;
        this.physicalPath = physicalPath ?? path;
        this.bom = hasUnicodeBOM(body);
        this.body = stripUnicodeBOM(body);
        this.rawBody = this.bom ? body : this.body;
    }
}

module.exports = { VFile };


Review comment (suggestion):
```suggestion
        this.rawBody = body;
```

I think this can be simplified this way.

Code after:
     * The raw body of the file, including a BOM if present.
     * @type {string|Uint8Array}
     * @readonly
     */
    rawBody;

    /**
     * Indicates whether the file has a byte order mark (BOM).
     * @type {boolean}
     * @readonly
     */
    bom;

    /**
     * Creates a new instance.
     * @param {string} path The file path.
     * @param {string|Uint8Array} body The file contents.
     * @param {Object} [options] Additional options.
     * @param {string} [options.physicalPath] The file path on disk.
     */
    constructor(path, body, { physicalPath } = {}) {
        this.path = path;
        this.physicalPath = physicalPath ?? path;
        this.bom = hasUnicodeBOM(body);
        this.body = stripUnicodeBOM(body);
        this.rawBody = body;
    }
}

module.exports = { VFile };
Repository: eslint/eslint
File: lib/services/processor-service.js (JavaScript)

Code before:
                const filePath = path.join(file.path, `${i}_${block.filename}`);

                return new VFile(filePath, block.text, {
                    physicalPath: file.physicalPath
                });
            })
        };

    }

    /**
     * Postprocesses the given messages synchronously.
     * @param {VFile} file The file to postprocess.
     * @param {LintMessage[][]} messages The messages to postprocess.
     * @param {{processor:Processor}} config The configuration to use.
     * @returns {LintMessage[]} The postprocessed messages.
     */
    postprocessSync(file, messages, config) {

        const { processor } = config;

        if (processor.postprocess) {
            return processor.postprocess(messages, file.path);
        }

        return messages;
    }

}

module.exports = { ProcessorService };


Review comment (bug):
```suggestion
        return processor.postprocess(messages, file.path);
```

I think it would be a bug if there's no `postprocess` method here, because `messages` must be flattened.

Code after:
                const filePath = path.join(file.path, `${i}_${block.filename}`);

                return new VFile(filePath, block.text, {
                    physicalPath: file.physicalPath
                });
            })
        };

    }

    /**
     * Postprocesses the given messages synchronously.
     * @param {VFile} file The file to postprocess.
     * @param {LintMessage[][]} messages The messages to postprocess.
     * @param {{processor:Processor}} config The configuration to use.
     * @returns {LintMessage[]} The postprocessed messages.
     */
    postprocessSync(file, messages, config) {

        const { processor } = config;

        return processor.postprocess(messages, file.path);
    }

}

module.exports = { ProcessorService };
Repository: eslint/eslint
File: lib/rules/require-unicode-regexp.js (JavaScript)

Code before:
/** @type {import('../shared/types').Rule} */
module.exports = {
    meta: {
        type: "suggestion",

        docs: {
            description: "Enforce the use of `u` or `v` flag on RegExp",
            recommended: false,
            url: "https://eslint.org/docs/latest/rules/require-unicode-regexp"
        },

        hasSuggestions: true,

        messages: {
            addUFlag: "Add the 'u' flag.",
            addVFlag: "Add the 'v' flag.",
            requireUFlag: "Use the 'u' flag.",
            requireVFlag: "Use the 'v' flag."
        },

        schema: [
            {
                type: "object",
                properties: {
                    requireFlag: {
                        type: "string"
                    }
                },
                additionalProperties: false
            }
        ]
    },

    create(context) {

        const sourceCode = context.sourceCode;

        const {
            requireFlag
        } = context.options[0] ?? {};

        return {
            "Literal[regex]"(node) {
                const flags = node.regex.flags || "";

                const missingFlag = checkFlags(requireFlag, flags);

                if (missingFlag) {
                    context.report({
                        messageId: requireFlag === "v" ? "requireVFlag" : "requireUFlag",
                        node,

Review comment (suggestion):
```suggestion
                        enum: ["u", "v"]
```

To make sure that only these values can be provided.

Code after:
/** @type {import('../shared/types').Rule} */
module.exports = {
    meta: {
        type: "suggestion",

        docs: {
            description: "Enforce the use of `u` or `v` flag on RegExp",
            recommended: false,
            url: "https://eslint.org/docs/latest/rules/require-unicode-regexp"
        },

        hasSuggestions: true,

        messages: {
            addUFlag: "Add the 'u' flag.",
            addVFlag: "Add the 'v' flag.",
            requireUFlag: "Use the 'u' flag.",
            requireVFlag: "Use the 'v' flag."
        },

        schema: [
            {
                type: "object",
                properties: {
                    requireFlag: {
                        enum: ["u", "v"]
                    }
                },
                additionalProperties: false
            }
        ]
    },

    create(context) {

        const sourceCode = context.sourceCode;

        const {
            requireFlag
        } = context.options[0] ?? {};

        return {
            "Literal[regex]"(node) {
                const flags = node.regex.flags || "";

                const missingFlag = checkFlags(requireFlag, flags);

                if (missingFlag) {
                    context.report({
                        messageId: requireFlag === "v" ? "requireVFlag" : "requireUFlag",
                        node,
Repository: eslint/eslint
File: eslint.config.js (JavaScript)

Code before:
            "n/no-restricted-require": ["error", [
                ...createInternalFilesPatterns(INTERNAL_PATHS.SOURCE_CODE_PATTERN),
                "fs",
                resolveAbsolutePath("lib/cli-engine/index.js"),
                resolveAbsolutePath("lib/linter/index.js"),
                resolveAbsolutePath("lib/rule-tester/index.js"),
                resolveAbsolutePath("lib/rules/index.js")
            ]]
        }
    },
    {
        name: "eslint/rule-tester",
        files: [INTERNAL_FILES.RULE_TESTER_PATTERN],
        rules: {
            "n/no-restricted-require": ["error", [
                resolveAbsolutePath("lib/cli-engine/index.js")
            ]]
        }
    },
    ...eslintPluginYml.configs["flat/recommended"].map(config => ({
        ...config,
        files: [ALL_YAML_FILES]
    })),
    {
        name: "eslint/ts-rules",
        files: ["**/*.ts"],
        languageOptions: {
            parser: tsParser,
            parserOptions: {
                project: "tests/lib/types/tsconfig.json"
            }
        },
        plugins: {
            "expect-type": expectType
        },
        rules: {
            "expect-type/expect": "error"
        }
    }
];


Review comment (suggestion):
should this be limited?
```suggestion
        files: ["tests/lib/types/*.ts"],
```

Code after:
        rules: {
            "n/no-restricted-require": ["error", [
                ...createInternalFilesPatterns(INTERNAL_PATHS.SOURCE_CODE_PATTERN),
                "fs",
                resolveAbsolutePath("lib/cli-engine/index.js"),
                resolveAbsolutePath("lib/linter/index.js"),
                resolveAbsolutePath("lib/rule-tester/index.js"),
                resolveAbsolutePath("lib/rules/index.js")
            ]]
        }
    },
    {
        name: "eslint/rule-tester",
        files: [INTERNAL_FILES.RULE_TESTER_PATTERN],
        rules: {
            "n/no-restricted-require": ["error", [
                resolveAbsolutePath("lib/cli-engine/index.js")
            ]]
        }
    },
    ...eslintPluginYml.configs["flat/recommended"].map(config => ({
        ...config,
        files: [ALL_YAML_FILES]
    })),
    {
        name: "eslint/ts-rules",
        files: ["tests/lib/types/*.ts"],
        languageOptions: {
            parser: tsParser,
            parserOptions: {
                project: "tests/lib/types/tsconfig.json"
            }
        },
        plugins: {
            "expect-type": expectType
        },
        rules: {
            "expect-type/expect": "error"
        }
    }
];
Repository: eslint/eslint
File: lib/types/rules/ecmascript-6.d.ts (TypeScript)

Code before:
     * Recommended by ESLint, the rule was enabled in `eslint:recommended`.
     *
     * @since 1.2.0
     * @see https://eslint.org/docs/rules/no-dupe-class-members
     */
    "no-dupe-class-members": Linter.RuleEntry<[]>;

    /**
     * Rule to disallow duplicate module imports.
     *
     * @since 2.5.0
     * @see https://eslint.org/docs/rules/no-duplicate-imports
     */
    "no-duplicate-imports": Linter.RuleEntry<
        [
            Partial<{
                /**
                 * @default false
                 */
                includeExports: boolean;
            }>,
        ]
    >;

    /**
     * Rule to disallow `new` operators with global non-constructor functions
     * 
     * @remarks
     * Recommended by ESLint, the rule was enabled in `eslint:recommended`.
     *
     * @since 8.27.0
     * @see https://eslint.org/docs/rules/no-new-native-nonconstructor
     */
    "no-new-native-nonconstructor": Linter.RuleEntry<[]>;

    /**
     * Rule to disallow specified names in exports.
     *
     * @since 7.0.0-alpha.0
     * @see https://eslint.org/docs/rules/no-restricted-exports
     */
    "no-restricted-exports": Linter.RuleEntry<
        [
            Partial<{
                /**
                 * @default []
                 */
                restrictedNamedExports: string[];
                /**
                 * @since 9.3.0
                 */

Review comment (suggestion):
```suggestion
     * Rule to disallow `new` operator with global non-constructor functions
```

Code after:
     * Recommended by ESLint, the rule was enabled in `eslint:recommended`.
     *
     * @since 1.2.0
     * @see https://eslint.org/docs/rules/no-dupe-class-members
     */
    "no-dupe-class-members": Linter.RuleEntry<[]>;

    /**
     * Rule to disallow duplicate module imports.
     *
     * @since 2.5.0
     * @see https://eslint.org/docs/rules/no-duplicate-imports
     */
    "no-duplicate-imports": Linter.RuleEntry<
        [
            Partial<{
                /**
                 * @default false
                 */
                includeExports: boolean;
            }>,
        ]
    >;

    /**
     * Rule to disallow `new` operator with global non-constructor functions
     * 
     * @remarks
     * Recommended by ESLint, the rule was enabled in `eslint:recommended`.
     *
     * @since 8.27.0
     * @see https://eslint.org/docs/rules/no-new-native-nonconstructor
     */
    "no-new-native-nonconstructor": Linter.RuleEntry<[]>;

    /**
     * Rule to disallow specified names in exports.
     *
     * @since 7.0.0-alpha.0
     * @see https://eslint.org/docs/rules/no-restricted-exports
     */
    "no-restricted-exports": Linter.RuleEntry<
        [
            Partial<{
                /**
                 * @default []
                 */
                restrictedNamedExports: string[];
                /**
                 * @since 9.3.0
                 */
Repository: eslint/eslint
File: packages/eslint-config-eslint/tests/types/types.test-d.mts (TypeScript)

Code before:
import type { Linter } from "eslint";

import * as eslintConfigESLint from "eslint-config-eslint";
import * as eslintConfigESLintBase from "eslint-config-eslint/base";
import * as eslintConfigESLintCJS from "eslint-config-eslint/cjs";
import * as eslintConfigESLintFormatting from "eslint-config-eslint/formatting";

import { rules } from "eslint-config-eslint/formatting";

eslintConfigESLintBase satisfies typeof eslintConfigESLint;
eslintConfigESLintBase satisfies Linter.Config[];
eslintConfigESLintCJS satisfies Linter.Config[];
eslintConfigESLintFormatting satisfies Linter.Config;
eslintConfigESLint satisfies Linter.Config[];
eslintConfigESLintBase satisfies typeof eslintConfigESLintCJS;
eslintConfigESLintBase satisfies (typeof eslintConfigESLintFormatting)[];

const ESLintConfig = [...eslintConfigESLint, rules];

ESLintConfig satisfies Linter.Config[];


Review comment (suggestion):
```suggestion
import eslintConfigESLint from "eslint-config-eslint";
import eslintConfigESLintBase from "eslint-config-eslint/base";
import eslintConfigESLintCJS from "eslint-config-eslint/cjs";
import eslintConfigESLintFormatting from "eslint-config-eslint/formatting";
```

Shouldn't these be default imports? I'm not sure how these tests are passing because, for example, `eslintConfigESLint` evaluates to `{ default: [...] }`.

Code after:
import type { Linter } from "eslint";

import eslintConfigESLint from "eslint-config-eslint";
import eslintConfigESLintBase from "eslint-config-eslint/base";
import eslintConfigESLintCJS from "eslint-config-eslint/cjs";
import eslintConfigESLintFormatting from "eslint-config-eslint/formatting";

eslintConfigESLintBase satisfies typeof eslintConfigESLint;
eslintConfigESLintBase satisfies Linter.Config[];
eslintConfigESLintCJS satisfies Linter.Config[];
eslintConfigESLintFormatting satisfies Linter.Config;
eslintConfigESLint satisfies Linter.Config[];
eslintConfigESLintBase satisfies typeof eslintConfigESLintCJS;

const ESLintConfig = [...eslintConfigESLint, eslintConfigESLintFormatting];

ESLintConfig satisfies Linter.Config[];
Repository: eslint/eslint
File: lib/shared/assert.js (JavaScript)

Code before:
/**
 * @fileoverview Assertion utilities equivalent to the Node.js node:asserts module.
 * @author Josh Goldberg
 */

"use strict";

/**
 * Throws an error if the input is not truthy.
 * @param {unknown} value The input that is checked for being truthy.
 * @param {string} message Message to throw if the input is not truthy.
 * @returns {void}
 * @throws {Error}
 */
function ok(value, message) {
    if (!value) {
        throw new Error(message);
    }
}

/**
 * Throws an error if the input is not strictly equal to expected.
 * @template T
 * @param {T} value The input that is checked for being strictly equal.
 * @param {T} expected The expected value.
 * @param {string} message Message to throw if the input is not strictly equal.
 * @returns {void}
 * @throws {Error}
 */
function strictEqual(value, expected, message) {
    if (value !== expected) {
        throw new Error(message);
    }
}

/**
 * Throws an error if the input is strictly equal to expected.
 * @template T

Review comment (suggestion):
```suggestion
 * @throws {Error} When the condition is not truthy.
```

Code after:
/**
 * @fileoverview Assertion utilities equivalent to the Node.js node:asserts module.
 * @author Josh Goldberg
 */

"use strict";

/**
 * Throws an error if the input is not truthy.
 * @param {unknown} value The input that is checked for being truthy.
 * @param {string} message Message to throw if the input is not truthy.
 * @returns {void}
 * @throws {Error} When the condition is not truthy.
 */
function ok(value, message = "Assertion failed.") {
    if (!value) {
        throw new Error(message);
    }
}


module.exports = ok;
Repository: eslint/eslint
File: lib/shared/assert.js (JavaScript)

Code before:
 * @author Josh Goldberg
 */

"use strict";

/**
 * Throws an error if the input is not truthy.
 * @param {unknown} value The input that is checked for being truthy.
 * @param {string} message Message to throw if the input is not truthy.
 * @returns {void}
 * @throws {Error}
 */
function ok(value, message) {
    if (!value) {
        throw new Error(message);
    }
}

/**
 * Throws an error if the input is not strictly equal to expected.
 * @template T
 * @param {T} value The input that is checked for being strictly equal.
 * @param {T} expected The expected value.
 * @param {string} message Message to throw if the input is not strictly equal.
 * @returns {void}
 * @throws {Error}
 */
function strictEqual(value, expected, message) {
    if (value !== expected) {
        throw new Error(message);
    }
}

/**
 * Throws an error if the input is strictly equal to expected.
 * @template T
 * @param {T} value The input that is checked for being strictly equal.
 * @param {T} expected The expected value.
 * @param {string} message Message to throw if the input is strictly equal.
 * @returns {void}
 * @throws {Error}
 */
function notStrictEqual(value, expected, message) {
    if (value === expected) {
        throw new Error(message);
    }
}

module.exports = {
    ok,
    strictEqual,

Review comment (suggestion):
```suggestion
 * @throws {Error} if the input is not strictly equal to the expected value.
```

Code after:
/**
 * @fileoverview Assertion utilities equivalent to the Node.js node:asserts module.
 * @author Josh Goldberg
 */

"use strict";

/**
 * Throws an error if the input is not truthy.
 * @param {unknown} value The input that is checked for being truthy.
 * @param {string} message Message to throw if the input is not truthy.
 * @returns {void}
 * @throws {Error} When the condition is not truthy.
 */
function ok(value, message = "Assertion failed.") {
    if (!value) {
        throw new Error(message);
    }
}


module.exports = ok;
Repository: eslint/eslint
File: lib/shared/assert.js (JavaScript)

Code before:
    }
}

/**
 * Throws an error if the input is not strictly equal to expected.
 * @template T
 * @param {T} value The input that is checked for being strictly equal.
 * @param {T} expected The expected value.
 * @param {string} message Message to throw if the input is not strictly equal.
 * @returns {void}
 * @throws {Error}
 */
function strictEqual(value, expected, message) {
    if (value !== expected) {
        throw new Error(message);
    }
}

/**
 * Throws an error if the input is strictly equal to expected.
 * @template T
 * @param {T} value The input that is checked for being strictly equal.
 * @param {T} expected The expected value.
 * @param {string} message Message to throw if the input is strictly equal.
 * @returns {void}
 * @throws {Error}
 */
function notStrictEqual(value, expected, message) {
    if (value === expected) {
        throw new Error(message);
    }
}

module.exports = {
    ok,
    strictEqual,
    notStrictEqual,

    /*
     * Intentionally mirroring the node:assert interface, instead of normal Knip CommonJS patterns.
     * https://knip.dev/guides/working-with-commonjs
     */
    __esModule: true
};


Review comment (suggestion):
```suggestion
 * @throws {Error}  if the input is strictly equal to the expected value.
```

Code after:
/**
 * @fileoverview Assertion utilities equivalent to the Node.js node:asserts module.
 * @author Josh Goldberg
 */

"use strict";

/**
 * Throws an error if the input is not truthy.
 * @param {unknown} value The input that is checked for being truthy.
 * @param {string} message Message to throw if the input is not truthy.
 * @returns {void}
 * @throws {Error} When the condition is not truthy.
 */
function ok(value, message = "Assertion failed.") {
    if (!value) {
        throw new Error(message);
    }
}


module.exports = ok;
Repository: eslint/eslint
File: lib/shared/assert.js (JavaScript)

Code before:

"use strict";

/**
 * Throws an error if the input is not truthy.
 * @param {unknown} value The input that is checked for being truthy.
 * @param {string} message Message to throw if the input is not truthy.
 * @returns {void}
 * @throws {Error} When the condition is not truthy.
 */
function ok(value, message) {
    if (!value) {
        throw new Error(message);
    }
}


module.exports = {
    ok,

    /*
     * Intentionally mirroring the node:assert interface, instead of normal Knip CommonJS patterns.
     * https://knip.dev/guides/working-with-commonjs
     */
    __esModule: true
};


Review comment (refactor):
Thoughts about simplifying this to export a function? I think all we need in production code is a simple `assert(value, message)` as a shorthand for `if (!value) { throw new Error(message); }`.

Code after:
/**
 * @fileoverview Assertion utilities equivalent to the Node.js node:asserts module.
 * @author Josh Goldberg
 */

"use strict";

/**
 * Throws an error if the input is not truthy.
 * @param {unknown} value The input that is checked for being truthy.
 * @param {string} message Message to throw if the input is not truthy.
 * @returns {void}
 * @throws {Error} When the condition is not truthy.
 */
function ok(value, message = "Assertion failed.") {
    if (!value) {
        throw new Error(message);
    }
}


module.exports = ok;