Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for redis built-ins #114

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docsrc/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ Option Meaning
* ``luacheckrc`` - globals allowed in Luacheck configs, by default added for files ending with ``.luacheckrc``;
* ``ldoc`` - globals allowed in LDoc config, by default added for files named ``config.ld``;
* ``sile`` - globals allowed in The SILE Typesetter and its package ecosystem;
* ``redis5`` - globals available in `redis lua <https://redis.io/docs/latest/develop/interact/programmability/lua-api/>` v5, including standard Lua 5.1 globals;
* ``redis6`` - globals available in redis lua v6, including standard Lua 5.1 globals;
* ``redis7`` - globals available in redis lua v7, including standard Lua 5.1 globals;
* ``redis_scripting`` - globals added by redis scripting;
* ``redis_functions`` - globals added by redis functions;
* ``none`` - no standard globals.


See :ref:`stds`
``--globals [<name>] ...`` Add custom global variables or fields on top of standard ones. See :ref:`fields`
Expand Down
3 changes: 3 additions & 0 deletions luacheck-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ build = {
["luacheck.builtin_standards.minetest"] = "src/luacheck/builtin_standards/minetest.lua",
["luacheck.builtin_standards.playdate"] = "src/luacheck/builtin_standards/playdate.lua",
["luacheck.builtin_standards.ngx"] = "src/luacheck/builtin_standards/ngx.lua",
["luacheck.builtin_standards.redis5"] = "src/luacheck/builtin_standards/redis5.lua",
["luacheck.builtin_standards.redis6"] = "src/luacheck/builtin_standards/redis6.lua",
["luacheck.builtin_standards.redis7"] = "src/luacheck/builtin_standards/redis7.lua",
["luacheck.cache"] = "src/luacheck/cache.lua",
["luacheck.check"] = "src/luacheck/check.lua",
["luacheck.check_state"] = "src/luacheck/check_state.lua",
Expand Down
10 changes: 10 additions & 0 deletions src/luacheck/builtin_standards/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ local love = require "luacheck.builtin_standards.love"
local minetest = require "luacheck.builtin_standards.minetest"
local playdate = require "luacheck.builtin_standards.playdate"
local ngx = require "luacheck.builtin_standards.ngx"
local redis5 = require "luacheck.builtin_standards.redis5"
local redis6 = require "luacheck.builtin_standards.redis6"
local redis7 = require "luacheck.builtin_standards.redis7"
local redis_scripts = require "luacheck.builtin_standards.redis_scripts"
local redis_functions = require "luacheck.builtin_standards.redis_functions"
local standards = require "luacheck.standards"

local builtin_standards = {}
Expand Down Expand Up @@ -264,6 +269,11 @@ lua_defs.luajit = add_defs(make_min_def("luajit"), {
})
lua_defs.ngx_lua = add_defs(lua_defs.luajit, ngx)
lua_defs.max = add_defs(lua_defs.lua51c, lua_defs.lua52c, lua_defs.lua53c, lua_defs.lua54c, lua_defs.luajit)
lua_defs.redis5 = add_defs(lua_defs.lua51, redis5)
lua_defs.redis6 = add_defs(lua_defs.redis5, redis6)
lua_defs.redis7 = add_defs(lua_defs.redis6, redis7)
lua_defs.redis_scripts = redis_scripts
lua_defs.redis_functions = redis_functions

for name, def in pairs(lua_defs) do
builtin_standards[name] = def_to_std(def)
Expand Down
59 changes: 59 additions & 0 deletions src/luacheck/builtin_standards/redis5.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
local empty = {}

local redis = {
fields = {
redis = {
fields = {
call = empty,
pcall = empty,
error_reply = empty,
status_reply = empty,
sha1hex = empty,
log = empty,
set_repl = empty,
replicate_commands = empty,
},
},

cjson = {
fields = {
decode = empty,
encode = empty,
},
},

struct = {
fields = {
pack = empty,
unpack = empty,
size = empty,
}
},

cmsgpack = {
fields = {
pack = empty,
unpack = empty,
}
},

bit = {
fields = {
tobit = empty,
tohex = empty,
bnot = empty,
bor = empty,
band = empty,
bxor = empty,
lshift = empty,
rshift = empty,
arshift = empty,
rol = empty,
ror = empty,
bswap = empty,
}
}
}
}

return redis
14 changes: 14 additions & 0 deletions src/luacheck/builtin_standards/redis6.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local empty = {}

local redis = {
fields = {
redis = {
fields = {
setresp = empty,
}

}
}
}

return redis
14 changes: 14 additions & 0 deletions src/luacheck/builtin_standards/redis7.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local empty = {}

local redis = {
fields = {
redis = {
REDIS_VERSION = {},
REDIS_VERSION_NUM = {},
acl_check_cmd = empty,
register_function = empty,
}
}
}

return redis
13 changes: 13 additions & 0 deletions src/luacheck/builtin_standards/redis_functions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local empty = {}

local redis_functions = {
fields = {
redis = {
fields = {
register_function = empty,
},
}
}
}

return redis_functions
20 changes: 20 additions & 0 deletions src/luacheck/builtin_standards/redis_scripts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local empty = {}

local redis_scripts = {
fields = {
ARGV = {
other_fields = true,
},
KEYS = {
other_fields = true,
},
redis = {
fields = {
breakpoint = empty,
debug = empty,
},
}
}
}

return redis_scripts
Loading