{"size": 956, "ext": "js", "max_stars_repo_path": "src/rule.js", "max_stars_repo_name": "dorianmariefr/eslint-simple-rule", "max_stars_repo_stars_event_min_datetime": "2019-09-06T19:43:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T19:32:26.000Z", "max_issues_repo_path": "src/rule.js", "max_issues_repo_name": "dorianmariefr/eslint-simple-rule", "max_issues_repo_issues_event_min_datetime": "2021-05-10T12:43:34.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-10T12:43:34.000Z", "max_forks_repo_path": "src/rule.js", "max_forks_repo_name": "dorianmariefr/eslint-simple-rule", "max_forks_repo_forks_event_min_datetime": "2021-05-11T18:03:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-11T18:03:31.000Z"}
{"max_stars_count": 22, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 26.5555555556, "max_line_length": 78, "alphanum_fraction": 0.5261506276}
/**
 * @fileoverview A utility for creating simple ESLint rules.
 */

/**
 * Creates an ESLint rule that warns when certain esquery selectors are found.
 * @param {Object} config An object whose keys are esquery selectors of nodes
 *      to match and whose values are messages to display when nodes matching
 *      those queries are found.
 * @returns {Object} An ESLint rule. 
 */
export function rule(config) {

    if (typeof config !== "object" || config === null) {
        throw new TypeError("rule() requires an object argument.");
    }

    return {
        meta: {},
        create(context) {
            const ruleConfig = {};

            Object.keys(config).forEach(key => {
                ruleConfig[key] = node => {
                    context.report({
                        node,
                        message: config[key]
                    });
                };
            });

            return ruleConfig;
        }
    };
}
