-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheck-Config.lua
97 lines (88 loc) · 3 KB
/
Check-Config.lua
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
local fs = require "bee.filesystem"
local json = require "json"
local diags = require "proto.diagnostic"
if not DBM_LIBRARIES then
error("Usage: parameter --dbm_libraries is required")
end
local basePath = fs.canonical(CONFIGPATH):parent_path()
local pluginPath = (basePath / "Plugin/Plugin.lua"):string()
local libs = {}
for lib in DBM_LIBRARIES:gmatch("([^,]+)") do
libs[#libs + 1] = lib
end
libs[#libs + 1] = (basePath / "Definitions"):string()
-- Merge global definitions from various places
local globals = {}
local globalsRegex = nil
local ws = fs.path(CHECK or CHECK_WORKER)
-- Handle .luacheckrc
local luacheckCfg = ws / ".luacheckrc"
local luacheck = {}
---@diagnostic disable-next-line: redundant-parameter
local f = loadfile(luacheckCfg:string(), nil, luacheck)
if f then f() end
if luacheck.globals then
for _, v in ipairs(luacheck.globals) do
globals[#globals + 1] = v
end
end
-- Handle .luarc.json
local luarc = ws / ".luarc.json"
local f = io.open(luarc:string())
if f then
local config = json.decode(f:read("*a"))
local luarcGlobals = config["diagnostics.globals"]
if luarcGlobals then
for _, v in ipairs(luarcGlobals) do
globals[#globals + 1] = v
end
end
globalsRegex = config["diagnostics.globalsRegex"]
f:close()
end
local disabledDiagnostics = {
"unused-local", -- Very spammy and low value
"redefined-local", -- Low value
"empty-block", -- Triggers on some locales, generally not very useful
"invisible", -- Slowest diagnostic and we don't use it
"deprecated", -- Second slowest diagnostic and also pretty much unused for us
"duplicate-doc-field" -- Slow to run on mods, likely due to the auto-generated field annotations (which we don't need to check)
}
-- Lightweight check just to replace LuaCheck but without pulling in more noisy/potentially false-positive warnings.
-- Used to gate releases.
if ONLY_CHECK_GLOBALS then
local enabledDiagnostics = {
["undefined-global"] = true,
["lowercase-global"] = true,
["global-element"] = true
}
for diag in pairs(diags.getDiagAndErrNameMap()) do
if not enabledDiagnostics[diag] then
disabledDiagnostics[#disabledDiagnostics + 1] = diag
end
end
-- Config file is run before the plugin that loads these, so they are not yet included above
disabledDiagnostics[#disabledDiagnostics + 1] = "dbm-sync-checker"
disabledDiagnostics[#disabledDiagnostics + 1] = "dbm-event-checker"
end
return {
["Lua.workspace.library"] = libs,
["Lua.runtime.version"] = "Lua 5.1",
["Lua.runtime.plugin"] = pluginPath,
["Lua.diagnostics.globals"] = globals,
["Lua.diagnostics.globalsRegex"] = globalsRegex,
["Lua.diagnostics.disable"] = disabledDiagnostics,
["Lua.diagnostics.neededFileStatus"] = {
["global-element"] = "Any" -- Bans defining global variables, even if they are all uppercase (consistent with LuaCheck)
},
["Lua.diagnostics.severity"] = {
["undefined-global"] = "Error",
["lowercase-global"] = "Error",
},
["Lua.workspace.ignoreDir"] = {
"DBM-Test-Dragonflight",
"DBM-Test-WarWithin",
"DBM-Test-Vanilla",
"DBM-Test-Dungeons"
}
}