fix static code analysis warnings, typos

This commit is contained in:
Daniel Poelzleithner 2022-11-10 04:20:54 +01:00
parent e09b58b721
commit 787b2b0015
1 changed files with 34 additions and 16 deletions

View File

@ -25,30 +25,36 @@ then
lsyncd.terminate( -1 ) lsyncd.terminate( -1 )
end end
---@diagnostic disable-next-line: lowercase-global
lsyncd_version = '2.3.1' lsyncd_version = '2.3.1'
-- compatibility with 5.1 -- compatibility with 5.1
if table.unpack == nil then if table.unpack == nil then
--- @diagnostic disable-next-line deprecated
table.unpack = unpack table.unpack = unpack
end end
local lver = string.gmatch(_VERSION, "%w (%d).(%d)") local _LUA_VERSION_MAJOR, _LUA_VERSION_MINOR = string.gmatch(
local _LUA_VERSION_MAJOR, _LUA_VERSION_MINOR = lver() _VERSION, "%w (%d).(%d)")()
---@type any
_LUA_VERSION_MAJOR = tonumber(_LUA_VERSION_MAJOR) _LUA_VERSION_MAJOR = tonumber(_LUA_VERSION_MAJOR)
_LUA_VERSION_MINOR = tonumber(_LUA_VERSION_MINOR) _LUA_VERSION_MINOR = tonumber(_LUA_VERSION_MINOR)
-- --
-- Shortcuts (which user is supposed to be able to use them as well) -- Shortcuts (which user is supposed to be able to use them as well)
-- --
---@diagnostic disable: lowercase-global
log = lsyncd.log log = lsyncd.log
terminate = lsyncd.terminate terminate = lsyncd.terminate
now = lsyncd.now now = lsyncd.now
readdir = lsyncd.readdir readdir = lsyncd.readdir
---@diagnostic enable: lowercase-global
-- --
-- Debug helper. Prints contents of `tbl`, with indentation. -- Debug helper. Prints contents of `tbl`, with indentation.
-- `indent` sets the initial level of indentation. -- `indent` sets the initial level of indentation.
-- --
---@diagnostic disable-next-line: lowercase-global
function dump(tbl, indent) function dump(tbl, indent)
if not indent then indent = 0 end if not indent then indent = 0 end
for k, v in pairs(tbl) do for k, v in pairs(tbl) do
@ -191,7 +197,7 @@ inheritKV =
end end
end end
function alarm2string(a) local function alarm2string(a)
if type(a) == 'userdata' then if type(a) == 'userdata' then
return a.string return a.string
end end
@ -2222,13 +2228,13 @@ local Excludes = ( function
self, -- self self, -- self
file -- filename to load from file -- filename to load from
) )
f, err = io.open( file ) local f, err = io.open( file )
if not f if not f
then then
log( 'Error', 'Cannot open exclude file "', file,'": ', err ) log( 'Error', 'Cannot open exclude file "', file,'": ', err )
terminate( -1 ) return terminate( -1 )
end end
for line in f:lines() for line in f:lines()
@ -2398,13 +2404,13 @@ local Filters = ( function
self, -- self self, -- self
file -- filename to load from file -- filename to load from
) )
f, err = io.open( file ) local f, err = io.open( file )
if not f if not f
then then
log( 'Error', 'Cannot open filter file "', file, '": ', err ) log( 'Error', 'Cannot open filter file "', file, '": ', err )
terminate( -1 ) return terminate( -1 )
end end
for line in f:lines( ) for line in f:lines( )
@ -3437,7 +3443,7 @@ local Sync = ( function
if #cdata then if #cdata then
s.cron = cdata s.cron = cdata
else else
error("Can't parse crontab data: "..cron, 0) error("Can't parse crontab data: "..cdata, 0)
end end
end end
@ -3458,7 +3464,7 @@ local functionWriter = ( function( )
-- --
-- All variables known to layer 3 configs. -- All variables known to layer 3 configs.
-- --
transVars = { local transVars = {
{ '%^pathname', 'event.pathname', 1 }, { '%^pathname', 'event.pathname', 1 },
{ '%^pathdir', 'event.pathdir', 1 }, { '%^pathdir', 'event.pathdir', 1 },
{ '%^path', 'event.path', 1 }, { '%^path', 'event.path', 1 },
@ -4062,6 +4068,7 @@ Tunnel = (function()
'Start tunnel command ', 'Start tunnel command ',
cmd cmd
) )
--- @diagnostic disable-next-line: param-type-mismatch
local pid = lsyncd.exec(bin, table.unpack(cmd, 2)) local pid = lsyncd.exec(bin, table.unpack(cmd, 2))
--local pid = spawn(bin, table.unpack(self.options.command, 2)) --local pid = spawn(bin, table.unpack(self.options.command, 2))
if pid and pid > 0 then if pid and pid > 0 then
@ -4137,7 +4144,7 @@ Tunnel = (function()
local good = false local good = false
if type(self.options.checkExitCodes) == 'table' then if type(self.options.checkExitCodes) == 'table' then
for _,i in iwalk(self.options.checkExitCodes) do for _,i in ipairs(self.options.checkExitCodes) do
if exitcode == i then if exitcode == i then
good = true good = true
end end
@ -4148,7 +4155,7 @@ Tunnel = (function()
end end
end end
if good then if good then
if self.isReady() == false then if self:isReady() == false then
log( log(
'Info', 'Info',
self.options.name, self.options.name,
@ -4297,7 +4304,7 @@ local Tunnels = ( function
( ) ( )
return #tunnelList return #tunnelList
end end
--- @type any
local nextCycle = true local nextCycle = true
-- --
-- Cycle through all tunnels and call their invoke function -- Cycle through all tunnels and call their invoke function
@ -4355,14 +4362,14 @@ local Tunnels = ( function
size = size, size = size,
invoke = invoke, invoke = invoke,
getAlarm = getAlarm, getAlarm = getAlarm,
killAll = killAll, killAll = killAll
statusReport = statusReport
} }
end )( ) end )( )
-- --
-- create a new tunnel from the passed options and registers the tunnel -- create a new tunnel from the passed options and registers the tunnel
--- @diagnostic disable-next-line: lowercase-global
tunnel = function (options) tunnel = function (options)
log( log(
'Debug', 'Debug',
@ -4656,7 +4663,7 @@ local function splitQuotedString
( (
text text
) )
local spat, epat, buf, quoted = [=[^(['"])]=], [=[(['"])$]=] local spat, epat, buf, quoted = [=[^(['"])]=], [=[(['"])$]=], nil, nil
local rv = {} local rv = {}
for str in text:gmatch("%S+") do for str in text:gmatch("%S+") do
local squoted = str:match(spat) local squoted = str:match(spat)
@ -4683,6 +4690,7 @@ end
lsyncd.splitQuotedString = splitQuotedString lsyncd.splitQuotedString = splitQuotedString
--- @diagnostic disable-next-line: lowercase-global
function substitudeCommands(cmd, data) function substitudeCommands(cmd, data)
assert(type(data) == "table") assert(type(data) == "table")
@ -4891,6 +4899,7 @@ local Inotify = ( function
end end
-- looks up the watch descriptor id -- looks up the watch descriptor id
--- @type any
local path = wdpaths[ wd ] local path = wdpaths[ wd ]
if path if path
@ -4898,6 +4907,7 @@ local Inotify = ( function
path = path..filename path = path..filename
end end
--- @type any
local path2 = wd2 and wdpaths[ wd2 ] local path2 = wd2 and wdpaths[ wd2 ]
if path2 and filename2 if path2 and filename2
@ -5598,7 +5608,7 @@ end
-- Called by core if '-help' or '--help' is in -- Called by core if '-help' or '--help' is in
-- the arguments. -- the arguments.
-- --
function runner.help( ) function runner.help(_arg0)
io.stdout:write( io.stdout:write(
'lsyncd version: ' .. lsyncd_version .. 'lsyncd version: ' .. lsyncd_version ..
[[ [[
@ -6094,6 +6104,7 @@ function runner.initialize( firstTime )
local ft = functionWriter.translate( config[ fn ] ) local ft = functionWriter.translate( config[ fn ] )
if _LUA_VERSION_MAJOR <= 5 and _LUA_VERSION_MINOR < 2 then if _LUA_VERSION_MAJOR <= 5 and _LUA_VERSION_MINOR < 2 then
-- lua 5.1 and older -- lua 5.1 and older
--- @diagnostic disable-next-line deprecated
config[ fn ] = assert( loadstring( 'return '..ft ) )( ) config[ fn ] = assert( loadstring( 'return '..ft ) )( )
else else
config[ fn ] = assert( load( 'return '..ft ) )( ) config[ fn ] = assert( load( 'return '..ft ) )( )
@ -6289,6 +6300,7 @@ end
-- --
-- Returns an Inlet to that sync. -- Returns an Inlet to that sync.
-- --
--- @diagnostic disable-next-line: lowercase-global
function sync function sync
( (
opts opts
@ -6305,6 +6317,7 @@ end
-- --
-- Spawns a new child process. -- Spawns a new child process.
-- --
--- @diagnostic disable-next-line: lowercase-global
function spawn( function spawn(
agent, -- the reason why a process is spawned. agent, -- the reason why a process is spawned.
-- a delay or delay list for a sync -- a delay or delay list for a sync
@ -6398,6 +6411,7 @@ end
-- --
-- Spawns a child process using the default shell. -- Spawns a child process using the default shell.
-- --
--- @diagnostic disable-next-line: lowercase-global
function spawnShell function spawnShell
( (
agent, -- the delay(list) to spawn the command for agent, -- the delay(list) to spawn the command for
@ -6411,6 +6425,7 @@ end
-- --
-- Observes a filedescriptor. -- Observes a filedescriptor.
-- --
--- @diagnostic disable-next-line: lowercase-global
function observefd function observefd
( (
fd, -- file descriptor fd, -- file descriptor
@ -6424,6 +6439,7 @@ end
-- --
-- Stops observeing a filedescriptor. -- Stops observeing a filedescriptor.
-- --
--- @diagnostic disable-next-line: lowercase-global
function nonobservefd function nonobservefd
( (
fd -- file descriptor fd -- file descriptor
@ -6438,6 +6454,7 @@ end
-- Use now() to receive current timestamp -- Use now() to receive current timestamp
-- add seconds with '+' to it -- add seconds with '+' to it
-- --
--- @diagnostic disable-next-line: lowercase-global
alarm = UserAlarms.alarm alarm = UserAlarms.alarm
@ -6470,6 +6487,7 @@ end
-- --
-- The settings call -- The settings call
-- --
--- @diagnostic disable-next-line: lowercase-global
function settings function settings
( (
a1 -- a string for getting a setting a1 -- a string for getting a setting