From 0b147146ee906160b71eb546fb02afcdba97cabd Mon Sep 17 00:00:00 2001 From: Michael Crawford Date: Fri, 23 Aug 2024 13:55:42 -0400 Subject: [PATCH 1/4] Add support for redis built-ins --- src/luacheck/builtin_standards/init.lua | 6 ++ src/luacheck/builtin_standards/redis5.lua | 68 +++++++++++++++++++++++ src/luacheck/builtin_standards/redis6.lua | 14 +++++ src/luacheck/builtin_standards/redis7.lua | 14 +++++ 4 files changed, 102 insertions(+) create mode 100644 src/luacheck/builtin_standards/redis5.lua create mode 100644 src/luacheck/builtin_standards/redis6.lua create mode 100644 src/luacheck/builtin_standards/redis7.lua diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index 097fee2d..0d06f053 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -2,6 +2,9 @@ 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 standards = require "luacheck.standards" local builtin_standards = {} @@ -264,6 +267,9 @@ 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) for name, def in pairs(lua_defs) do builtin_standards[name] = def_to_std(def) diff --git a/src/luacheck/builtin_standards/redis5.lua b/src/luacheck/builtin_standards/redis5.lua new file mode 100644 index 00000000..4edf0cd4 --- /dev/null +++ b/src/luacheck/builtin_standards/redis5.lua @@ -0,0 +1,68 @@ +local empty = {} + +local redis = { + fields = { + ARGV = { + other_fields = true, + }, + KEYS = { + other_fields = true, + }, + + redis = { + fields = { + call = empty, + pcall = empty, + error_reply = empty, + status_reply = empty, + sha1hex = empty, + log = empty, + set_repl = empty, + replicate_commands = empty, + breakpoint = empty, + debug = 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 diff --git a/src/luacheck/builtin_standards/redis6.lua b/src/luacheck/builtin_standards/redis6.lua new file mode 100644 index 00000000..e145f1bb --- /dev/null +++ b/src/luacheck/builtin_standards/redis6.lua @@ -0,0 +1,14 @@ +local empty = {} + +local redis = { + fields = { + redis = { + fields = { + setresp = empty, + } + + } + } +} + +return redis diff --git a/src/luacheck/builtin_standards/redis7.lua b/src/luacheck/builtin_standards/redis7.lua new file mode 100644 index 00000000..8b453530 --- /dev/null +++ b/src/luacheck/builtin_standards/redis7.lua @@ -0,0 +1,14 @@ +local empty = {} + +local redis = { + fields = { + redis = { + REDIS_VERSION = {}, + REDIS_VERSION_NUM = {}, + acl_check_cmd = empty, + register_function = empty, + } + } +} + +return redis From 5d420db4c2977d38af4c69e1d53a4981d244ea4d Mon Sep 17 00:00:00 2001 From: Michael Crawford Date: Mon, 26 Aug 2024 15:42:38 -0400 Subject: [PATCH 2/4] Add built-in files to rockspec --- luacheck-dev-1.rockspec | 3 +++ 1 file changed, 3 insertions(+) diff --git a/luacheck-dev-1.rockspec b/luacheck-dev-1.rockspec index 0389dd14..deb1a7fc 100644 --- a/luacheck-dev-1.rockspec +++ b/luacheck-dev-1.rockspec @@ -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", From db9c87edba4255821d04bbbca169723c77712788 Mon Sep 17 00:00:00 2001 From: Michael Crawford Date: Thu, 29 Aug 2024 10:58:52 -0400 Subject: [PATCH 3/4] Split scripts/functions exclusive definitions --- src/luacheck/builtin_standards/init.lua | 4 ++++ src/luacheck/builtin_standards/redis5.lua | 9 --------- .../builtin_standards/redis_functions.lua | 13 ++++++++++++ .../builtin_standards/redis_scripts.lua | 20 +++++++++++++++++++ 4 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 src/luacheck/builtin_standards/redis_functions.lua create mode 100644 src/luacheck/builtin_standards/redis_scripts.lua diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index 0d06f053..98cefa3a 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -5,6 +5,8 @@ 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 = {} @@ -270,6 +272,8 @@ lua_defs.max = add_defs(lua_defs.lua51c, lua_defs.lua52c, lua_defs.lua53c, lua_d 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) diff --git a/src/luacheck/builtin_standards/redis5.lua b/src/luacheck/builtin_standards/redis5.lua index 4edf0cd4..f8e16ad5 100644 --- a/src/luacheck/builtin_standards/redis5.lua +++ b/src/luacheck/builtin_standards/redis5.lua @@ -2,13 +2,6 @@ local empty = {} local redis = { fields = { - ARGV = { - other_fields = true, - }, - KEYS = { - other_fields = true, - }, - redis = { fields = { call = empty, @@ -19,8 +12,6 @@ local redis = { log = empty, set_repl = empty, replicate_commands = empty, - breakpoint = empty, - debug = empty, }, }, diff --git a/src/luacheck/builtin_standards/redis_functions.lua b/src/luacheck/builtin_standards/redis_functions.lua new file mode 100644 index 00000000..6aef9f1a --- /dev/null +++ b/src/luacheck/builtin_standards/redis_functions.lua @@ -0,0 +1,13 @@ +local empty = {} + +local redis_functions = { + fields = { + redis = { + fields = { + register_function = empty, + }, + } + } +} + +return redis_functions diff --git a/src/luacheck/builtin_standards/redis_scripts.lua b/src/luacheck/builtin_standards/redis_scripts.lua new file mode 100644 index 00000000..3ba72a77 --- /dev/null +++ b/src/luacheck/builtin_standards/redis_scripts.lua @@ -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 From 0258fd5cf35eba955ef12986d8f728eee87ba9a2 Mon Sep 17 00:00:00 2001 From: Michael Crawford Date: Thu, 29 Aug 2024 11:44:03 -0400 Subject: [PATCH 4/4] Update docs for builtin standards --- docsrc/cli.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docsrc/cli.rst b/docsrc/cli.rst index be222004..923b59da 100644 --- a/docsrc/cli.rst +++ b/docsrc/cli.rst @@ -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 ` 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 [] ...`` Add custom global variables or fields on top of standard ones. See :ref:`fields`