/usr/share/lua/5.1/luacheck/init.lua is in lua-check 0.21.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | local check = require "luacheck.check"
local filter = require "luacheck.filter"
local options = require "luacheck.options"
local format = require "luacheck.format"
local utils = require "luacheck.utils"
local luacheck = {
_VERSION = "0.21.1"
}
local function raw_validate_options(fname, opts)
assert(opts == nil or type(opts) == "table",
("bad argument #2 to '%s' (table or nil expected, got %s)"):format(fname, type(opts))
)
local ok, invalid_field = options.validate(options.all_options, opts)
if not ok then
if invalid_field then
error(("bad argument #2 to '%s' (invalid value of option '%s')"):format(fname, invalid_field))
else
error(("bad argument #2 to '%s'"):format(fname))
end
end
end
local function validate_options(fname, items, opts)
raw_validate_options(fname, opts)
if opts ~= nil then
for i in ipairs(items) do
raw_validate_options(fname, opts[i])
if opts[i] ~= nil then
for _, nested_opts in ipairs(opts[i]) do
raw_validate_options(fname, nested_opts)
end
end
end
end
end
-- Returns report for a string.
function luacheck.get_report(src)
local msg = ("bad argument #1 to 'luacheck.get_report' (string expected, got %s)"):format(type(src))
assert(type(src) == "string", msg)
return check(src)
end
-- Applies options to reports. Reports with .fatal field are unchanged.
-- Options are applied to reports[i] in order: options, options[i], options[i][1], options[i][2], ...
-- Returns new array of reports, adds .warnings, .errors and .fatals fields to this array.
function luacheck.process_reports(reports, opts)
local msg = ("bad argument #1 to 'luacheck.process_reports' (table expected, got %s)"):format(type(reports))
assert(type(reports) == "table", msg)
validate_options("luacheck.process_reports", reports, opts)
local report = filter.filter(reports, opts)
report.warnings = 0
report.errors = 0
report.fatals = 0
for _, file_report in ipairs(report) do
if file_report.fatal then
report.fatals = report.fatals + 1
else
for _, event in ipairs(file_report) do
if event.code:sub(1, 1) == "0" then
report.errors = report.errors + 1
else
report.warnings = report.warnings + 1
end
end
end
end
return report
end
-- Checks strings with options, returns report.
-- Tables with .fatal field are unchanged.
function luacheck.check_strings(srcs, opts)
local msg = ("bad argument #1 to 'luacheck.check_strings' (table expected, got %s)"):format(type(srcs))
assert(type(srcs) == "table", msg)
for _, item in ipairs(srcs) do
msg = ("bad argument #1 to 'luacheck.check_strings' (array of strings or tables expected, got %s)"):format(
type(item))
assert(type(item) == "string" or type(item) == "table", msg)
end
validate_options("luacheck.check_strings", srcs, opts)
local reports = {}
for i, src in ipairs(srcs) do
if type(src) == "table" and src.fatal then
reports[i] = src
else
reports[i] = luacheck.get_report(src)
end
end
return luacheck.process_reports(reports, opts)
end
function luacheck.check_files(files, opts)
local msg = ("bad argument #1 to 'luacheck.check_files' (table expected, got %s)"):format(type(files))
assert(type(files) == "table", msg)
for _, item in ipairs(files) do
msg = ("bad argument #1 to 'luacheck.check_files' (array of paths or file handles expected, got %s)"):format(
type(item))
assert(type(item) == "string" or io.type(item) == "file", msg
)
end
validate_options("luacheck.check_files", files, opts)
local srcs = {}
for i, file in ipairs(files) do
local src, err = utils.read_file(file)
srcs[i] = src or {fatal = "I/O", msg = err}
end
return luacheck.check_strings(srcs, opts)
end
function luacheck.get_message(issue)
local msg = ("bad argument #1 to 'luacheck.get_message' (table expected, got %s)"):format(type(issue))
assert(type(issue) == "table", msg)
return format.get_message(issue)
end
setmetatable(luacheck, {__call = function(_, ...)
return luacheck.check_files(...)
end})
return luacheck
|