• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lunarmodules / luacheck / 24662353255

20 Apr 2026 10:48AM UTC coverage: 97.095% (+0.07%) from 97.027%
24662353255

push

github

web-flow
fix(ci): build LuaJIT using system malloc for lualanes tests (#144)

6318 of 6507 relevant lines covered (97.1%)

26928.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/luacheck/init.lua
1
local check = require "luacheck.check"
774✔
2
local filter = require "luacheck.filter"
774✔
3
local options = require "luacheck.options"
774✔
4
local format = require "luacheck.format"
774✔
5
local utils = require "luacheck.utils"
774✔
6

7
local luacheck = {
774✔
8
   _VERSION = "1.2.0"
516✔
9
}
10

11
local function raw_validate_options(fname, opts, stds, context)
12
   local ok, err = options.validate(options.all_options, opts, stds)
5,886✔
13

14
   if not ok then
5,886✔
15
      if context then
60✔
16
         error(("bad argument #2 to '%s' (%s: %s)"):format(fname, context, err))
24✔
17
      else
18
         error(("bad argument #2 to '%s' (%s)"):format(fname, err))
36✔
19
      end
20
   end
21
end
22

23
local function validate_options(fname, items, opts, stds)
24
   raw_validate_options(fname, opts)
978✔
25

26
   if opts ~= nil then
942✔
27
      for i in ipairs(items) do
2,496✔
28
         raw_validate_options(fname, opts[i], stds, ("invalid options at index [%d]"):format(i))
1,740✔
29

30
         if opts[i] ~= nil then
1,722✔
31
            for j, nested_opts in ipairs(opts[i]) do
4,698✔
32
               raw_validate_options(fname, nested_opts, stds, ("invalid options at index [%d][%d]"):format(i, j))
3,168✔
33
            end
34
         end
35
      end
36
   end
37
end
38

39
-- Returns report for a string.
40
function luacheck.get_report(src)
774✔
41
   local msg = ("bad argument #1 to 'luacheck.get_report' (string expected, got %s)"):format(type(src))
672✔
42
   assert(type(src) == "string", msg)
672✔
43
   return check(src)
666✔
44
end
45

46
-- Applies options to reports. Reports with .fatal field are unchanged.
47
-- Options are applied to reports[i] in order: options, options[i], options[i][1], options[i][2], ...
48
-- Returns new array of reports, adds .warnings, .errors and .fatals fields to this array.
49
function luacheck.process_reports(reports, opts, stds)
774✔
50
   local msg = ("bad argument #1 to 'luacheck.process_reports' (table expected, got %s)"):format(type(reports))
822✔
51
   assert(type(reports) == "table", msg)
822✔
52
   validate_options("luacheck.process_reports", reports, opts, stds)
816✔
53
   local report = filter.filter(reports, opts, stds)
798✔
54
   report.warnings = 0
792✔
55
   report.errors = 0
792✔
56
   report.fatals = 0
792✔
57

58
   for _, file_report in ipairs(report) do
2,562✔
59
      if file_report.fatal then
1,770✔
60
         report.fatals = report.fatals + 1
66✔
61
      else
62
         for _, event in ipairs(file_report) do
6,852✔
63
            if event.code:sub(1, 1) == "0" then
6,864✔
64
               report.errors = report.errors + 1
462✔
65
            else
66
               report.warnings = report.warnings + 1
4,686✔
67
            end
68
         end
69
      end
70
   end
71

72
   return report
792✔
73
end
74

75
-- Checks strings with options, returns report.
76
-- Tables with .fatal field are unchanged.
77
function luacheck.check_strings(srcs, opts)
774✔
78
   local msg = ("bad argument #1 to 'luacheck.check_strings' (table expected, got %s)"):format(type(srcs))
114✔
79
   assert(type(srcs) == "table", msg)
114✔
80

81
   for _, item in ipairs(srcs) do
306✔
82
      msg = ("bad argument #1 to 'luacheck.check_strings' (array of strings or tables expected, got %s)"):format(
408✔
83
         type(item))
408✔
84
      assert(type(item) == "string" or type(item) == "table", msg)
204✔
85
   end
86

87
   validate_options("luacheck.check_strings", srcs, opts)
102✔
88

89
   local reports = {}
84✔
90

91
   for i, src in ipairs(srcs) do
264✔
92
      if type(src) == "table" and src.fatal then
180✔
93
         reports[i] = src
6✔
94
      else
95
         reports[i] = luacheck.get_report(src)
232✔
96
      end
97
   end
98

99
   return luacheck.process_reports(reports, opts)
84✔
100
end
101

102
function luacheck.check_files(files, opts)
774✔
103
   local msg = ("bad argument #1 to 'luacheck.check_files' (table expected, got %s)"):format(type(files))
72✔
104
   assert(type(files) == "table", msg)
72✔
105

106
   for _, item in ipairs(files) do
180✔
107
      msg = ("bad argument #1 to 'luacheck.check_files' (array of paths or file handles expected, got %s)"):format(
240✔
108
         type(item))
240✔
109
      assert(type(item) == "string" or io.type(item) == "file", msg
240✔
110
      )
120✔
111
   end
112

113
   validate_options("luacheck.check_files", files, opts)
60✔
114

115
   local srcs = {}
36✔
116

117
   for i, file in ipairs(files) do
126✔
118
      local src, err = utils.read_file(file)
90✔
119
      srcs[i] = src or {fatal = "I/O", msg = err}
90✔
120
   end
121

122
   return luacheck.check_strings(srcs, opts)
36✔
123
end
124

125
function luacheck.get_message(issue)
774✔
126
   local msg = ("bad argument #1 to 'luacheck.get_message' (table expected, got %s)"):format(type(issue))
84✔
127
   assert(type(issue) == "table", msg)
84✔
128
   return format.get_message(issue)
78✔
129
end
130

131
setmetatable(luacheck, {__call = function(_, ...)
1,548✔
132
   return luacheck.check_files(...)
66✔
133
end})
774✔
134

135
return luacheck
774✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc