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

lunarmodules / luacheck / 16640642558

31 Jul 2025 05:25AM UTC coverage: 97.042% (-0.02%) from 97.064%
16640642558

push

github

web-flow
Merge fdccc2ad3 into d1e973c16

19 of 21 new or added lines in 1 file covered. (90.48%)

4 existing lines in 3 files now uncovered.

6299 of 6491 relevant lines covered (97.04%)

19287.34 hits per line

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

91.3
/src/luacheck/core_utils.lua
1
local decoder = require "luacheck.decoder"
584✔
2
local utils = require "luacheck.utils"
584✔
3

4
local core_utils = {}
584✔
5

6
-- Attempts to evaluate a node as a Lua value, without resolving locals.
7
-- Returns Lua value and its string representation on success, nothing on failure.
8
function core_utils.eval_const_node(node)
584✔
9
   if node.tag == "True" then
348✔
10
      return true, "true"
×
11
   elseif node.tag == "False" then
348✔
12
      return false, "false"
×
13
   elseif node.tag == "String" then
348✔
14
      local chars = decoder.decode(node[1])
280✔
15
      return node[1], chars:get_printable_substring(1, chars:get_length())
280✔
16
   else
17
      local is_negative
18

19
      if node.tag == "Op" and node[1] == "unm" then
68✔
20
         is_negative = true
12✔
21
         node = node[2]
12✔
22
      end
23

24
      if node.tag ~= "Number" then
68✔
25
         return
12✔
26
      end
27

28
      local str = node[1]
56✔
29

30
      if str:find("[iIuUlL]") then
56✔
31
         -- Ignore LuaJIT cdata literals.
32
         return
×
33
      end
34

35
      -- On Lua 5.3+ convert to float to get same results as on Lua 5.1 and 5.2.
36
      if (_VERSION == "Lua 5.3" or _VERSION == "Lua 5.4") and not str:find("[%.eEpP]") then
56✔
UNCOV
37
         str = str .. ".0"
22✔
38
      end
39

40
      local number = tonumber(str)
56✔
41

42
      if not number then
56✔
43
         return
×
44
      end
45

46
      if is_negative then
56✔
47
         number = -number
12✔
48
      end
49

50
      if number == number and number < 1/0 and number > -1/0 then
56✔
51
         return number, (is_negative and "-" or "") .. node[1]
56✔
52
      end
53
   end
54
end
55

56
local statement_containing_tags = utils.array_to_set({"Do", "While", "Repeat", "Fornum", "Forin", "If"})
584✔
57

58
-- `items` is an array of nodes or nested item arrays.
59
local function scan_for_statements(chstate, items, tags, callback, ...)
60
   for _, item in ipairs(items) do
51,632✔
61
      if tags[item.tag] then
35,440✔
62
         callback(chstate, item, ...)
3,360✔
63
      end
64

65
      if not item.tag or statement_containing_tags[item.tag] then
35,440✔
66
         scan_for_statements(chstate, item, tags, callback, ...)
9,328✔
67
      end
68
   end
69
end
70

71
-- Calls `callback(chstate, node, ...)` for each statement node within AST with tag in given array.
72
function core_utils.each_statement(chstate, tags_array, callback, ...)
584✔
73
   local tags = utils.array_to_set(tags_array)
3,008✔
74

75
   for _, line in ipairs(chstate.lines) do
9,872✔
76
      scan_for_statements(chstate, line.node[2], tags, callback, ...)
6,864✔
77
   end
78
end
79

80
local function location_comparator(warning1, warning2)
81
   if warning1.line ~= warning2.line then
23,511✔
82
      return warning1.line < warning2.line
19,675✔
83
   elseif warning1.column ~= warning2.column then
3,836✔
84
      return warning1.column < warning2.column
3,093✔
85
   else
86
      return warning1.code < warning2.code
743✔
87
   end
88
end
89

90
-- Sorts an array of warnings by location information as provided in `line` and `column` fields.
91
function core_utils.sort_by_location(warnings)
584✔
92
   table.sort(warnings, location_comparator)
2,084✔
93
end
94

95
return core_utils
584✔
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