<commit_before>/**
 * @fileoverview Rule to flag when any arguments in modules that use ngAnnotate are out of lexigraphical order.
 * @author <NAME> <<EMAIL>>
 * @copyright 2015 Anthropologie. All rights reserved.
 */
'use strict';

// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------

/**
 * Report arguments that are out of lexigraphical order in a function
 * expression that is marked with an ng-annotate block comment.
 *
 * @param {Object} context Contains information and additional functionality that is relevant to the context of the rule.
 * @returns {Object}
 */
module.exports = function ngAnnotateArgOrder (context) {
    return {
        /**
         * Check all AssignmentExpression nodes, and if one matches the
         * signature of a function expression marked with an ng-annotate block
         * comment, ensure that its arguments are in lexigraphical order.
         * @method
         * @param {Object} node Leaf node of the AST for an AssignmentExpression
         */
        AssignmentExpression: function assignmentExpressionRule (node) {
            /**
             * The prefix of the key pattern to search the node source for.
             * @var {String}
             */
            var patternPrefix = 'module\.exports';

            /**
             * The suffix of the key pattern to search the node source for.
             * @var {String}
             */
            var patternSuffix = ' = /*@ngInject*/';

            /**
             * Use to replace string with an escaped version suitable for
             * conversion into a RegExp.
             * @var {RegExp}
             */
            var escapeRE = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g;

            /**
             * The suffix of the key pattern to search the node source for.
             * @var {String}
             */
            var patternEscaped = (patternPrefix + patternSuffix)
                                 .replace(escapeRE, "\\$&");

            /**
             * The escaped RegExp form of the key pattern.
             * @var {RegExp}
             */
            var patternRE = new RegExp(patternEscaped);

            /**
             * A literal string of the JS source of the left side of the
             * assignment, starting at char 0 and ending at char 16.
             * @var {String}
             */
            var source = context.getSource(node.left, 0, patternSuffix.length);

            /**
             * Compare each argument name, and report when any name is out of
             * lexigraphical order with the previous one.
             * @function
             * @param {Object} prev The param from the previous iteration, for comparison with the current param
             * @param {Object} curr The current param
             * @returns {Object}
             */
            var paramsReducer = function paramsReducer (prev, curr) {
                if (prev.name > curr.name) {
                    context.report(node, 'Found argument identifier out of lexigraphical order');
                }
                return curr;
            };

            // Look for the ng-annotate block comment and ensure the right side
            // of the assignment is a function expression
            if (source.match(patternRE) && node.right.type === 'FunctionExpression') {
                // Iterate over all of the function expression's arguments
                node.right.params.reduce(paramsReducer, { name: '' });
            }
        }
    };
};

module.exports.schema = [
];<commit_msg>Revert "Make it easier to specify the desired pattern"<commit_after>/**
 * @fileoverview Rule to flag when any arguments in modules that use ngAnnotate are out of lexigraphical order.
 * @author <NAME> <<EMAIL>>
 * @copyright 2015 Anthropologie. All rights reserved.
 */
'use strict';

// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------

/**
 * Report arguments that are out of lexigraphical order in a function
 * expression that is marked with an ng-annotate block comment.
 *
 * @param {Object} context Contains information and additional functionality that is relevant to the context of the rule.
 * @returns {Object}
 */
module.exports = function ngAnnotateArgOrder (context) {
    return {
        /**
         * Check all AssignmentExpression nodes, and if one matches the
         * signature of a function expression marked with an ng-annotate block
         * comment, ensure that its arguments are in lexigraphical order.
         * @method
         * @param {Object} node Leaf node of the AST for an AssignmentExpression
         */
        AssignmentExpression: function assignmentExpressionRule (node) {
            /**
             * A literal string of the JS source of the left side of the
             * assignment, starting at char 0 and ending at char 16.
             * @type {String}
             */
            var source = context.getSource(node.left, 0, 16);

            /**
             * Compare each argument name, and report when any name is out of
             * lexigraphical order with the previous one.
             * @function
             * @param {Object} prev The param from the previous iteration, for comparison with the current param
             * @param {Object} curr The current param
             * @returns {Object}
             */
            var paramsReducer = function paramsReducer (prev, curr) {
                if (prev.name > curr.name) {
                    context.report(node, 'Found argument identifier out of lexigraphical order');
                }
                return curr;
            };

            // Look for the ng-annotate block comment and ensure the right side
            // of the assignment is a function expression
            if (source.match(/module\.exports = \/\*@ngInject\*\//) && node.right.type === 'FunctionExpression') {
                // Iterate over all of the function expression's arguments
                node.right.params.reduce(paramsReducer, { name: '' });
            }
        }
    };
};

module.exports.schema = [
];
{'fraction_non_alphanumeric': 0.13271947928242578, 'fraction_numerical': 0.002857596443879981, 'mean_word_length': 1.5609756097560976, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6120144', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1416, 'n_words': 581}