<commit_before>const exec = require('shelljs.exec')
const detectCode = require(__dirname + '/../../../frontend/src/components/libs/detectCustomCode')

module.exports = {
  Version: 2,

  run: async (code, game) => {
    if (!code.length) {
      return {}
    }
    if (!game || !game.match(/classic|tbc|bfa|sl/)) {
      game = 'sl'
    }
    const luacheckrc = __dirname + '/../lua/luacheck-' + game + '.lua'
    const checkDir = __dirname + '/../../run-tmp/' + new Date().getTime() + Math.random().toString(36).substring(7)
    await fs.mkdir(checkDir)
    var result = {}
    var fileMap = {}
    for (let i = 0; i < code.length; i++) {
      if (typeof code[i] !== 'object' || !code[i].lua || typeof code[i].lua !== 'string' || code[i].skipLuacheck) {
        continue
      }
      var key = `${code[i].id}: ${code[i].name}`
      code[i].lua = code[i].lua.replace(/-- luacheck:/g, `--`) // don't ignore potential malicous hidings

      if (code[i].lua.match(/^\s*function\s*\(/m)) {
        code[i].lua = code[i].lua.replace(/^\s*function\s*\(/m, `local fn_${key.replace(/[^a-zA-Z0-9]/g, '')} = function(`) // name anonymous function
        code[i].lua += `\nfn_${key.replace(/[^a-zA-Z0-9]/g, '')}()` // and then "call" the function so luacheck recognizes that it's used
      }
      else if (code[i].lua.match(/^{[\s\S]*}$/)) {
        code[i].lua = 'local t = ' + code[i].lua + ';Wago(t)'
      }

      let file = new Date().getTime() + Math.random().toString(36).substring(7) + '.lua'
      fileMap[file] = key
      await fs.writeFile(checkDir + '/' + file, code[i].lua)
    }
    let check = await exec(`luacheck ${checkDir} --config ${luacheckrc}`)<commit_msg>dont change code object by ref<commit_after>const exec = require('shelljs.exec')
const detectCode = require(__dirname + '/../../../frontend/src/components/libs/detectCustomCode')

module.exports = {
  Version: 2,

  run: async (code, game) => {
    if (!code.length) {
      return {}
    }
    if (!game || !game.match(/classic|tbc|bfa|sl/)) {
      game = 'sl'
    }
    const luacheckrc = __dirname + '/../lua/luacheck-' + game + '.lua'
    const checkDir = __dirname + '/../../run-tmp/' + new Date().getTime() + Math.random().toString(36).substring(7)
    await fs.mkdir(checkDir)
    var result = {}
    var fileMap = {}
    for (let i = 0; i < code.length; i++) {
      if (typeof code[i] !== 'object' || !code[i].lua || typeof code[i].lua !== 'string' || code[i].skipLuacheck) {
        continue
      }
      var key = code[i].name
      let lua = code[i].lua.replace(/-- luacheck:/g, `--`) // don't ignore potential malicous hidings

      if (lua.match(/^\s*function\s*\(/m)) {
        lua = lua.replace(/^\s*function\s*\(/m, `local fn_${key.replace(/[^a-zA-Z0-9]/g, '')} = function(`) // name anonymous function
        lua += `\nfn_${key.replace(/[^a-zA-Z0-9]/g, '')}()` // and then "call" the function so luacheck recognizes that it's used
      }
      else if (lua.match(/^{[\s\S]*}$/)) {
        lua = 'local t = ' + lua + ';Wago(t)'
      }

      let file = new Date().getTime() + Math.random().toString(36).substring(7) + '.lua'
      fileMap[file] = key
      await fs.writeFile(checkDir + '/' + file, lua)
    }

    let check = await exec(`luacheck ${checkDir} --config ${luacheckrc}`)
{'fraction_non_alphanumeric': 0.22137637028014617, 'fraction_numerical': 0.007308160779537149, 'mean_word_length': 2.5901639344262297, 'pattern_counts': {'":': 0, '<': 5, '<?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': '221499', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1160, 'n_words': 244}