<commit_before>var GetTextContentsComponent = require('GetTextContentsComponent');
var TextSelectorComponent = require('TextSelectorComponent');
var Case = require('Case');
const DOM = require('DOM');
var LanguageComponent = require('LanguageComponent');
var TextNodeFilterComponent = require('TextNodeFilterComponent');
var guessLanguage = require('guessLanguage/lib/guessLanguage');
var LanguageChangesAreIdentified = {
  run: function (test) {
    var scope = test.get('scope');
    var currentLanguage = LanguageComponent.getDocumentLanguage(scope, true);
    var text, matches, $element, failed;

    var noCharactersMatch = function ($element, language, matches, regularExpression) {
      var $children = DOM.scry('[lang=' + language + ']', $element);
      var childMatches;
      if ($children.length === 0) {
        return true;
      }
      matches = matches.length;
      $children.each(function () {
        childMatches = GetTextContentsComponent($(this)).match(regularExpression);
        if (childMatches) {
          matches -= childMatches.length;
        }
      });
      return matches > 0;
    };

    var findCurrentLanguage = function ($element) {
      if ($element.attr('lang')) {
        return $element.attr('lang').trim().toLowerCase().split('-')[0];
      }
      if ($element.parents('[lang]').length) {
        return $element.parents('[lang]:first').attr('lang').trim().toLowerCase().split('-')[0];
      }
      return LanguageComponent.getDocumentLanguage(scope, true);
    };

    DOM.scry(TextSelectorComponent, scope)
      .filter(function (element) {
        return TextNodeFilterComponent(element);
      })
      .forEach(function (element) {
        var self = element;
        $element = $(element);
        currentLanguage = findCurrentLanguage($element);
        text = GetTextContentsComponent($element);
        failed = false;

        var singletons = LanguageComponent.scriptSingletons;
        for (var code in singletons) {
          if (singletons.hasOwnProperty(code)) {
            var regularExpression = singletons[code];
            if (code === currentLanguage) {
              return;
            }
            matches = text.match(regularExpression);
            if (matches && matches.length && noCharactersMatch($element, code, matches, regularExpression)) {
              test.add(Case({
                element: self,
                info: {
                  language: code
                },
                status: 'failed'
              }));
              failed = true;
            }
          }
        }
        var scripts = LanguageComponent.scripts;
        for (var script in scripts) {
          if (scripts.hasOwnProperty(script)) {
            var script = scripts[script];
          }
          if (script.languageindexOf(currentLanguage) !== -1) {
            return;
          }
          matches = text.match(script.regularExpression);
          if (matches && matches.length && noCharactersMatch($element, script, matches, regularExpression)) {
            test.add(Case({
              element: self,
              info: {
                language: script
              },
              status: 'failed'
            }));
            failed = true;
          }
        }
        if (typeof guessLanguage !== 'undefined' && !DOM.scry('[lang]', $element).length && $element.text().trim().length > 400) {
          guessLanguage.info($element.text(), function (info) {
            if (info[0] !== currentLanguage) {
              test.add(Case({
                element: self,
                info: {
                  language: info[0]
                },
                status: 'failed'
              }));
              failed = true;
            }
          });
        }
        // Passes.
        if (!failed) {
          test.add(Case({
            element: self,
            status: 'passed'
          }));
        }
      });
  },

  meta: {<commit_msg>Fixing lint issues<commit_after>var GetTextContentsComponent = require('GetTextContentsComponent');
var TextSelectorComponent = require('TextSelectorComponent');
var Case = require('Case');
const DOM = require('DOM');
var LanguageComponent = require('LanguageComponent');
var TextNodeFilterComponent = require('TextNodeFilterComponent');
var guessLanguage = require('guessLanguage/lib/guessLanguage');
var LanguageChangesAreIdentified = {
  run: function (test) {
    var scope = test.get('scope');
    var currentLanguage = LanguageComponent.getDocumentLanguage(scope, true);
    var text, matches, $element, failed;

    var noCharactersMatch = function ($element, language, matches, regularExpression) {
      var $children = DOM.scry('[lang=' + language + ']', $element);
      var childMatches;
      if ($children.length === 0) {
        return true;
      }
      matches = matches.length;
      $children.each(function () {
        childMatches = GetTextContentsComponent($(this)).match(regularExpression);
        if (childMatches) {
          matches -= childMatches.length;
        }
      });
      return matches > 0;
    };

    var findCurrentLanguage = function ($element) {
      if ($element.attr('lang')) {
        return $element.attr('lang').trim().toLowerCase().split('-')[0];
      }
      if ($element.parents('[lang]').length) {
        return $element.parents('[lang]:first').attr('lang').trim().toLowerCase().split('-')[0];
      }
      return LanguageComponent.getDocumentLanguage(scope, true);
    };

    DOM.scry(TextSelectorComponent, scope)
      .filter(function (element) {
        return TextNodeFilterComponent(element);
      })
      .forEach(function (element) {
        var self = element;
        $element = $(element);
        currentLanguage = findCurrentLanguage($element);
        text = GetTextContentsComponent($element);
        failed = false;

        var singletons = LanguageComponent.scriptSingletons;
        for (var code in singletons) {
          if (singletons.hasOwnProperty(code)) {
            var regularExpression = singletons[code];
            if (code === currentLanguage) {
              return;
            }
            matches = text.match(regularExpression);
            if (matches && matches.length && noCharactersMatch($element, code, matches, regularExpression)) {
              test.add(Case({
                element: self,
                info: {
                  language: code
                },
                status: 'failed'
              }));
              failed = true;
            }
          }
        }
        var scripts = LanguageComponent.scripts;
        for (var name in scripts) {
          if (scripts.hasOwnProperty(name)) {
            var script = scripts[name];
          }
          if (script.languageindexOf(currentLanguage) !== -1) {
            return;
          }
          matches = text.match(script.regularExpression);
          if (matches && matches.length && noCharactersMatch($element, name, matches, regularExpression)) {
            test.add(Case({
              element: self,
              info: {
                language: name
              },
              status: 'failed'
            }));
            failed = true;
          }
        }
        if (typeof guessLanguage !== 'undefined' && !DOM.scry('[lang]', $element).length && $element.text().trim().length > 400) {
          guessLanguage.info($element.text(), function (info) {
            if (info[0] !== currentLanguage) {
              test.add(Case({
                element: self,
                info: {
                  language: info[0]
                },
                status: 'failed'
              }));
              failed = true;
            }
          });
        }
        // Passes.
        if (!failed) {
          test.add(Case({
            element: self,
            status: 'passed'
          }));
        }
      });
  },

  meta: {
{'fraction_non_alphanumeric': 0.1285986049461002, 'fraction_numerical': 0.0025364616360177552, 'mean_word_length': 1.921822897369396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5004397', 'n_tokens_mistral': 1999, 'n_tokens_neox': 1966, 'n_words': 418}