<commit_before>(function(mod) {
  if (typeof exports == "object" && typeof module == "object") // CommonJS
    return mod(require("tern/lib/infer"), require("tern/lib/tern"), require);
  if (typeof define == "function" && define.amd) // AMD
    return define([ "tern/lib/infer", "tern/lib/tern" ], mod);
  mod(tern, tern);
})(function(infer, tern, require) {
  "use strict";
  
  var nodeRequire_lint = function(node, addMessage, getRule) {
    var rule = getRule("UnknownModule");
    if (!rule) return;
    var cx = infer.cx(), server = cx.parent, data = server._node;
    var argNodes = node.arguments;
    if (argNodes && argNodes.length && argNodes[0].type == "Literal" || typeof argNodes[0].value == "string") {
      var currentFile = argNodes[0].sourceFile.name

      var name = argNodes[0].value
      var mod = server.mod.modules.resolveModule(name, currentFile)
      if (!(mod && (mod.getFunctionType() || mod.getType()))) addMessage(argNodes[0], "Unknown module '" + argNodes[0].value + "'", rule.severity);
    }
  };
  
  var nodeRequire_guessType = function(arg, i, file, setType, addValueType) {
    var cx = infer.cx(), server = cx.parent, data = server._node;
    //var currentFile = data.currentFile || data.resolveProjectPath(server, file.name);

    function addModules(modules, addValueType) {
      for (var name in modules) {
        //if (name == currentFile) continue;
        //var moduleName = data.resolveModulePath(name, currentFile);
        //addValueType("requiredModule", '"' + moduleName + '"');
        addValueType("requiredModule", '"' + name + '"');
      }
    }
    if (i == 0) {
      setType("requiredModule");
      addModules(cx.definitions.node, addValueType);
      addModules(data.modules, addValueType);
      return true;
    }
  };
  
  tern.registerPlugin("node-extension", function(server, options) {
    return {
      passes: {postLoadDef: postLoadDef}  
    };
  });
  
  function postLoadDef(json) {
    var cx = infer.cx(), defName = json["!name"];
    if (defName === 'commonjs') {
      var require = cx.definitions.commonjs.require;
      require.lint = nodeRequire_lint;
      require.guessType = nodeRequire_guessType;
    }
  }
  
});
<commit_msg>Use getModType<commit_after>(function(mod) {
  if (typeof exports == "object" && typeof module == "object") // CommonJS
    return mod(require("tern/lib/infer"), require("tern/lib/tern"), require);
  if (typeof define == "function" && define.amd) // AMD
    return define([ "tern/lib/infer", "tern/lib/tern" ], mod);
  mod(tern, tern);
})(function(infer, tern, require) {
  "use strict";
  
  
  // TODO : remove this function when PR https://github.com/marijnh/tern/pull/621 will be accepted
  function getModType(node, me) {
    var modName = me.isModName(node), imp, prop
    if (imp = me.isImport(node)) {
      modName = imp.name
      prop = imp.prop
    }
    if (!modName) return

    var modType = me.resolveModule(modName, node.sourceFile.name)
    return (prop ? modType.getProp(prop) : modType).getType()
  }
  
  var nodeRequire_lint = function(node, addMessage, getRule) {
    var rule = getRule("UnknownModule");
    if (!rule) return;
    var cx = infer.cx(), server = cx.parent, data = server._node;
    var argNodes = node.arguments;
    if (argNodes && argNodes.length && argNodes[0].type == "Literal" || typeof argNodes[0].value == "string") {
      var me = infer.cx().parent.mod.modules
      var modType = getModType(argNodes[0], me);
      if (!modType) addMessage(argNodes[0], "Unknown module '" + argNodes[0].value + "'", rule.severity);
    }
  };
  
  var nodeRequire_guessType = function(arg, i, file, setType, addValueType) {
    var cx = infer.cx(), server = cx.parent, data = server._node;
    //var currentFile = data.currentFile || data.resolveProjectPath(server, file.name);

    function addModules(modules, addValueType) {
      for (var name in modules) {
        //if (name == currentFile) continue;
        //var moduleName = data.resolveModulePath(name, currentFile);
        //addValueType("requiredModule", '"' + moduleName + '"');
        addValueType("requiredModule", '"' + name + '"');
      }
    }
    if (i == 0) {
      setType("requiredModule");
      addModules(cx.definitions.node, addValueType);
      addModules(data.modules, addValueType);
      return true;
    }
  };
  
  tern.registerPlugin("node-extension", function(server, options) {
    return {
      passes: {postLoadDef: postLoadDef}  
    };
  });
  
  function postLoadDef(json) {
    var cx = infer.cx(), defName = json["!name"];
    if (defName === 'commonjs') {
      var require = cx.definitions.commonjs.require;
      require.lint = nodeRequire_lint;
      require.guessType = nodeRequire_guessType;
    }
  }
  
});

{'fraction_non_alphanumeric': 0.1581160639192599, 'fraction_numerical': 0.00336417157275021, 'mean_word_length': 3.1985878199470434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '3553074', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1500, 'n_words': 336}