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];
            }
            runHook(item, "before");

            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):
maybe I should move it closer to `runHook(..., "after")` for better clarity...

Code after:
                    }

                }

                /*
                 * 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);
            } 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
             * having the same cache entry that would be correct for only one of them.