<commit_before>/**
 * @fileoverview Rule to flag the use of empty character classes in regular expressions
 * @author <NAME>
 */

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

module.exports = function(context) {

    "use strict";

    return {

        "Literal": function(node) {
            var tokens = context.getTokens(node);
            tokens.forEach(function (token) {
                if (token.type === "RegularExpression") {
                    var open = false,
                        tokenValue = token.value,
                        at,
                        character;

                    for (at = 0; at < tokenValue.length; at++) {
                        character = tokenValue.charAt(at);
                        switch (character) {

                        // Character is escaped, skip it.
                        case "\\":
                            at += 1;
                            break;
                        case "[":

                            // Check for a matching closing bracket indicating
                            // an empty class.
                            if (tokenValue.charAt(at + 1) === "]" && !open) {
                                context.report(node, "Empty class.");
                            }

                            // We are now inside a character class.
                            open = true;
                            break;

                        // We are no longer in a character class, continue
                        // checking for empty class.
                        case "]":
                            open = false;
                            break;
                        }
                    }
                }
            });
        }

    };

};
<commit_msg>simplify no-empty-class rule<commit_after>/**
 * @fileoverview Rule to flag the use of empty character classes in regular expressions
 * @author <NAME>
 */

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

module.exports = function(context) {

    "use strict";

    return {

        "Literal": function(node) {
            var tokens = context.getTokens(node);
            tokens.forEach(function (token) {
                if (token.type === "RegularExpression" && !/^\/([^\\[]|\\.|\[([^\\\]]|\\.)+\])*\/$/.test(token.value)) {
                    context.report(node, "Empty class.");
                }
            });
        }

    };

};

{'fraction_non_alphanumeric': 0.21964886066492342, 'fraction_numerical': 0.0011206574523720584, 'mean_word_length': 0.7618421052631579, 'pattern_counts': {'":': 5, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '745659', 'n_tokens_mistral': 577, 'n_tokens_neox': 533, 'n_words': 143}