<commit_before>local check = require "luacheck.check"
local luacompiler = require "metalua.compiler"
local luaparser = luacompiler.new()

--- Checks a file. 
-- Returns a file report. 
-- See luacheck function. 
local function get_report(file, options)
   local ok, source = pcall(function()
      local handler = io.open(file, "rb")
      local source = assert(handler:read("*a"))
      handler:close()
      return source
   end)

   if not ok then
      return {error = "I/O", file = file}
   end

   local ast
   ok, ast = pcall(function() return luaparser:src_to_ast(source) end)

   if not ok then
      return {error = "syntax", file = file}
   else
      local report = check(ast, options)
      report.file = file
      return report
   end
end

return get_report<commit_msg>Allow checking stdin by passing `-` as filename<commit_after>local check = require "luacheck.check"
local luacompiler = require "metalua.compiler"
local luaparser = luacompiler.new()

--- Checks a file. 
-- Returns a file report. 
-- See luacheck function. 
local function get_report(file, options)
   local filename = file == "-" and "stdin" or file
   local src

   if not pcall(function()
         local handler = file == "-" and io.stdin or io.open(file, "rb")
         src = assert(handler:read("*a"))
         handler:close() end) then
      return {error = "I/O", file = filename}
   end

   local ast

   if not pcall(function()
         ast = luaparser:src_to_ast(src) end) then
      return {error = "syntax", file = filename}
   end

   local report = check(ast, options)
   report.file = filename
   return report
end

return get_report
{'fraction_non_alphanumeric': 0.11029411764705882, 'fraction_numerical': 0.0, 'mean_word_length': 2.925480769230769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4199005', 'n_tokens_mistral': 526, 'n_tokens_neox': 510, 'n_words': 167}