Repository: eslint/eslint
File: lib/rule-tester/rule-tester.js (JavaScript)

Code before:

                /*
                 * Create the config object from the tester config and this item
                 * specific configurations.
                 */
                configs.push(itemConfig);
            }

            if (hasOwnProperty(item, "only")) {
                assert.ok(typeof item.only === "boolean", "Optional test case property 'only' must be a boolean");
            }
            if (hasOwnProperty(item, "filename")) {
                assert.ok(typeof item.filename === "string", "Optional test case property 'filename' must be a string");
                filename = item.filename;
            }

            let ruleConfig = 1;

            if (hasOwnProperty(item, "options")) {
                assert(Array.isArray(item.options), "options must be an array");
                ruleConfig = [1, ...item.options];
            }
            if (hasOwnProperty(item, "setup")) {
                assert.ok(typeof item.setup === "function", "Optional test case property 'setup' must be a function");
                item.setup();
            }

            configs.push({
                rules: {
                    [ruleId]: ruleConfig
                }
            });

            let schema;

            try {
                schema = getRuleOptionsSchema(rule);
            } catch (err) {
                err.message += metaSchemaDescription;
                throw err;
            }

            /*
             * Check and throw an error if the schema is an empty object (`schema:{}`), because such schema
             * doesn't validate or enforce anything and is therefore considered a possible error. If the intent
             * was to skip options validation, `schema:false` should be set instead (explicit opt-out).
             *
             * For this purpose, a schema object is considered empty if it doesn't have any own enumerable string-keyed
             * properties. While `ajv.compile()` does use enumerable properties from the prototype chain as well,
             * it caches compiled schemas by serializing only own enumerable properties, so it's generally not a good idea
             * to use inherited properties in schemas because schemas that differ only in inherited properties would end up

Review comment (suggestion):
```suggestion
            if (hasOwnProperty(item, "before")) {
                assert.ok(typeof item.before === "function", "Optional test case property 'before' must be a function");
                item.before();
            }
```

Code after:
                 * parameters used by this tester
                 */
                const itemConfig = { ...item };

                for (const parameter of RuleTesterParameters) {
                    delete itemConfig[parameter];
                }

                // wrap any parsers
                if (itemConfig.languageOptions && itemConfig.languageOptions.parser) {

                    const parser = itemConfig.languageOptions.parser;

                    if (parser && typeof parser !== "object") {
                        throw new Error("Parser must be an object with a parse() or parseForESLint() method.");
                    }

                }

                /*
                 * Create the config object from the tester config and this item
                 * specific configurations.
                 */
                configs.push(itemConfig);
            }

            if (hasOwnProperty(item, "only")) {
                assert.ok(typeof item.only === "boolean", "Optional test case property 'only' must be a boolean");
            }
            if (hasOwnProperty(item, "filename")) {
                assert.ok(typeof item.filename === "string", "Optional test case property 'filename' must be a string");
                filename = item.filename;
            }

            let ruleConfig = 1;

            if (hasOwnProperty(item, "options")) {
                assert(Array.isArray(item.options), "options must be an array");
                ruleConfig = [1, ...item.options];
            }

            configs.push({
                rules: {
                    [ruleId]: ruleConfig
                }
            });

            let schema;

            try {
                schema = getRuleOptionsSchema(rule);