Skip to content

Commit

Permalink
Fix various luacheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
staticssleever668 committed Nov 29, 2020
1 parent a071cc5 commit 0a2ff9e
Show file tree
Hide file tree
Showing 27 changed files with 76 additions and 69 deletions.
4 changes: 2 additions & 2 deletions helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ end
-- @return cmd PID
function helpers.async(cmd, callback)
return spawn.easy_async(cmd,
function (stdout, stderr, reason, exit_code)
function (stdout, _, _, exit_code)
callback(stdout, exit_code)
end)
end

-- like above, but call spawn.easy_async with a shell
function helpers.async_with_shell(cmd, callback)
return spawn.easy_async_with_shell(cmd,
function (stdout, stderr, reason, exit_code)
function (stdout, _, _, exit_code)
callback(stdout, exit_code)
end)
end
Expand Down
4 changes: 2 additions & 2 deletions layout/centerwork.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ local function arrange(p, layout)
end
end

local function mouse_resize_handler(c, corner, x, y, orientation)
local function mouse_resize_handler(c, _, _, _, orientation)
local wa = c.screen.workarea
local mwfact = c.screen.selected_tag.master_width_factor
local g = c:geometry()
Expand Down Expand Up @@ -208,7 +208,7 @@ end
local function clients_by_position()
local this = client.focus
if this then
sorted = client.focus.first_tag:clients()
local sorted = client.focus.first_tag:clients()
table.sort(sorted, compare_position)

local idx = 0
Expand Down
2 changes: 1 addition & 1 deletion layout/termfair.lua
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ local function do_fair(p, orientation)
for i = 1, (num_x-1) do
local height = math.floor(wa.height / num_y[i])
local wy = wa.y
for j = 0, (num_y[i]-2) do
for _ = 0, (num_y[i]-2) do
local g = {}
g.x = wx
g.y = wy
Expand Down
11 changes: 5 additions & 6 deletions util/dkjson.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ SOFTWARE.
--]==]

-- global dependencies:
local pairs, type, tostring, tonumber, getmetatable, setmetatable, rawset =
pairs, type, tostring, tonumber, getmetatable, setmetatable, rawset
local pairs, type, tostring, tonumber, getmetatable, setmetatable =
pairs, type, tostring, tonumber, getmetatable, setmetatable
local error, require, pcall, select = error, require, pcall, select
local floor, huge = math.floor, math.huge
local strrep, gsub, strsub, strbyte, strchar, strfind, strlen, strformat =
Expand Down Expand Up @@ -246,7 +246,7 @@ local function exception(reason, value, state, buffer, buflen, defaultmessage)
end
end

function json.encodeexception(reason, value, state, defaultmessage)
function json.encodeexception(_, _, _, defaultmessage)
return quotestring("<" .. defaultmessage .. ">")
end

Expand Down Expand Up @@ -321,7 +321,7 @@ encode2 = function (value, indent, level, buffer, buflen, tables, globalorder, s
local v = value[k]
if v then
used[k] = true
buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state)
buflen, _ = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state)
prev = true -- add a seperator before the next element
end
end
Expand Down Expand Up @@ -504,7 +504,6 @@ end
local scanvalue -- forward declaration

local function scantable (what, closechar, str, startpos, nullval, objectmeta, arraymeta)
local len = strlen (str)
local tbl, n = {}, 0
local pos = startpos + 1
if what == 'object' then
Expand Down Expand Up @@ -626,7 +625,7 @@ function json.use_lpeg ()
local PlainChar = 1 - S"\"\\\n\r"
local EscapeSequence = (P"\\" * g.C (S"\"\\/bfnrt" + Err "unsupported escape sequence")) / escapechars
local HexDigit = R("09", "af", "AF")
local function UTF16Surrogate (match, pos, high, low)
local function UTF16Surrogate (_, _, high, low)
high, low = tonumber (high, 16), tonumber (low, 16)
if 0xD800 <= high and high <= 0xDBff and 0xDC00 <= low and low <= 0xDFFF then
return true, unichar ((high - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000)
Expand Down
4 changes: 2 additions & 2 deletions util/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function util.menu_clients_current_tags(menu, args)
local t = cls_tags[i]
local cls = t:clients()

for k, c in pairs(cls) do
for _, c in pairs(cls) do
cls_t[#cls_t + 1] = { awful.util.escape(c.name) or "",
function ()
c.minimized = false
Expand Down Expand Up @@ -99,7 +99,7 @@ end
function util.tag_view_nonempty(direction, sc)
local s = sc or awful.screen.focused()

for i = 1, #s.tags do
for _ = 1, #s.tags do
awful.tag.viewidx(direction, s)
if #s.clients > 0 then
return
Expand Down
7 changes: 3 additions & 4 deletions util/menu_iterator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

local naughty = require("naughty")
local helpers = require("lain.helpers")
local util = require("lain.util")
local atable = require("awful.util").table
local assert = assert
local pairs = pairs
Expand Down Expand Up @@ -42,8 +41,8 @@ end
-- * timeout: time to wait before confirming the menu selection
-- * icon: icon to display in the notification of the chosen label
local function iterate(menu, timeout, icon)
local timeout = timeout or 4 -- default timeout for each menu entry
local icon = icon or nil -- icon to display on the menu
timeout = timeout or 4 -- default timeout for each menu entry
icon = icon or nil -- icon to display on the menu

-- Build the list of choices
if not state.index then
Expand Down Expand Up @@ -104,7 +103,7 @@ local function menu(args)

local ch_combinations = args.combination == "powerset" and helpers.powerset(choices) or helpers.trivial_partition_set(choices)

for _,c in pairs(extra_choices) do
for _, c in pairs(extra_choices) do
ch_combinations = atable.join(ch_combinations, {{c[1]}})
end

Expand Down
6 changes: 3 additions & 3 deletions util/quake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function quake:display()

if not client then
-- The client does not exist, we spawn it
cmd = string.format("%s %s %s", self.app,
local cmd = string.format("%s %s %s", self.app,
string.format(self.argname, self.name), self.extra)
awful.spawn(cmd, { tag = self.screen.selected_tag })
return
Expand Down Expand Up @@ -89,8 +89,8 @@ function quake:display()
client.fullscreen = false
client.hidden = true
local ctags = client:tags()
for i, t in pairs(ctags) do
ctags[i] = nil
for j, _ in pairs(ctags) do
ctags[j] = nil
end
client:tags(ctags)
end
Expand Down
10 changes: 5 additions & 5 deletions util/separators.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ function separators.arrow_right(col1, col2)
widget.col1 = col1
widget.col2 = col2

widget.fit = function(m, w, h)
widget.fit = function(_, _, _)
return separators.width, separators.height
end

widget.update = function(col1, col2)
widget.update = function(_, _)
widget.col1 = col1
widget.col2 = col2
widget:emit_signal("widget::redraw_needed")
end

widget.draw = function(mycross, wibox, cr, width, height)
widget.draw = function(_, _, cr, width, height)
if widget.col2 ~= "alpha" then
cr:set_source_rgb(gears.color.parse_color(widget.col2))
cr:new_path()
Expand Down Expand Up @@ -69,7 +69,7 @@ function separators.arrow_left(col1, col2)
widget.col1 = col1
widget.col2 = col2

widget.fit = function(m, w, h)
widget.fit = function(_, _, _)
return separators.width, separators.height
end

Expand All @@ -79,7 +79,7 @@ function separators.arrow_left(col1, col2)
widget:emit_signal("widget::redraw_needed")
end

widget.draw = function(mycross, wibox, cr, width, height)
widget.draw = function(_, _, cr, width, height)
if widget.col1 ~= "alpha" then
cr:set_source_rgb(gears.color.parse_color(widget.col1))
cr:new_path()
Expand Down
2 changes: 1 addition & 1 deletion widget/alsa.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local string = string
-- lain.widget.alsa

local function factory(args)
local args = args or {}
args = args or {}
local alsa = { widget = args.widget or wibox.widget.textbox() }
local timeout = args.timeout or 5
local settings = args.settings or function() end
Expand Down
6 changes: 3 additions & 3 deletions widget/alsabar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ local function factory(args)
_playback = "off"
}

local args = args or {}
args = args or {}

local timeout = args.timeout or 5
local settings = args.settings or function() end
local width = args.width or 63
local height = args.height or 1
local margins = args.margins or 1
local paddings = args.paddings or 1
local ticks = args.ticks or false
local ticks_size = args.ticks_size or 7
local tick = args.tick or "|"
Expand Down Expand Up @@ -136,7 +136,7 @@ local function factory(args)
end
end

int = math.modf((alsabar._current_level / 100) * tot)
local int = math.modf((alsabar._current_level / 100) * tot)
preset.text = string.format(
"%s%s%s%s",
tick_pre,
Expand Down
3 changes: 2 additions & 1 deletion widget/bat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ local function factory(args)
return
end

local args = args or {}
args = args or {}

local bat = { widget = args.widget or wibox.widget.textbox() }
local timeout = args.timeout or 30
local notify = args.notify or "on"
Expand Down
2 changes: 1 addition & 1 deletion widget/cal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ local function factory(args)

function cal.hover_on() cal.show(0) end
function cal.move(offset)
local offset = offset or 0
offset = offset or 0
cal.month, cal.year = cal.getdate(cal.month, cal.year, offset)
cal.show(0, cal.month, cal.year)
end
Expand Down
3 changes: 2 additions & 1 deletion widget/contrib/moc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ local string = string
-- lain.widget.contrib.moc

local function factory(args)
local args = args or {}
args = args or {}

local moc = { widget = args.widget or wibox.widget.textbox() }
local timeout = args.timeout or 2
local music_dir = args.music_dir or os.getenv("HOME") .. "/Music"
Expand Down
12 changes: 6 additions & 6 deletions widget/contrib/redshift.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local type = type
-- lain.widget.contrib.redshift
local redshift = { active = false, pid = nil }

function redshift:start()
function redshift.start()
execute("pkill redshift")
awful.spawn.with_shell("redshift -x") -- clear adjustments
redshift.pid = awful.spawn.with_shell("redshift")
Expand All @@ -25,14 +25,14 @@ function redshift:start()
end
end

function redshift:toggle()
function redshift.toggle()
async({ awful.util.shell, "-c", string.format("ps -p %d -o pid=", redshift.pid) }, function(f)
if f and #f > 0 then -- redshift is running
-- Sending -USR1 toggles redshift (See project website)
execute("pkill -USR1 redshift")
redshift.active = not redshift.active
else -- not started or killed, (re)start it
redshift:start()
redshift.start()
end
redshift.update_fun(redshift.active)
end)
Expand All @@ -43,11 +43,11 @@ end
-- @param widget: Widget to attach to.
-- @param fun: Function to be run each time redshift is toggled (optional).
-- Use it to update widget text or icons on status change.
function redshift:attach(widget, fun)
function redshift.attach(widget, fun)
redshift.update_fun = fun or function() end
if not redshift.pid then redshift:start() end
if not redshift.pid then redshift.start() end
if widget then
widget:buttons(awful.util.table.join(awful.button({}, 1, function () redshift:toggle() end)))
widget:buttons(awful.util.table.join(awful.button({}, 1, function () redshift.toggle() end)))
end
end

Expand Down
4 changes: 2 additions & 2 deletions widget/contrib/task.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ local markup = require("lain.util").markup
local awful = require("awful")
local naughty = require("naughty")
local mouse = mouse
local string = string

-- Taskwarrior notification
-- lain.widget.contrib.task
Expand Down Expand Up @@ -69,7 +68,8 @@ function task.prompt()
end

function task.attach(widget, args)
local args = args or {}
args = args or {}

task.show_cmd = args.show_cmd or "task next"
task.prompt_text = args.prompt_text or "Enter task command: "
task.followtag = args.followtag or false
Expand Down
8 changes: 4 additions & 4 deletions widget/contrib/tp_smapi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

local helpers = require("lain.helpers")
local focused = require("awful.screen").focused
local gears = require("gears")
local naughty = require("naughty")
local wibox = require("wibox")
local string = string
Expand Down Expand Up @@ -61,7 +60,7 @@ local function factory(apipath)
local chem = tp_smapi.get(batid, "chemistry") or "no_chem"
local status = tp_smapi.get(batid, "state")
local time = tp_smapi.time(batid)
local msg = ""
local msg

if status and status ~= "idle" then
msg = string.format("[%s] %s %s", status, time ~= "N/A" and time or "unknown remaining time",
Expand All @@ -80,7 +79,8 @@ local function factory(apipath)
end

function tp_smapi.create_widget(args)
local args = args or {}
args = args or {}

local pspath = args.pspath or "/sys/class/power_supply/"
local batteries = args.batteries or (args.battery and {args.battery}) or {}
local timeout = args.timeout or 30
Expand All @@ -95,7 +95,7 @@ local function factory(apipath)

local all_batteries_installed = true

for i, battery in ipairs(batteries) do
for _, battery in ipairs(batteries) do
if not tp_smapi.installed(battery) then
naughty.notify {
preset = naughty.config.critical,
Expand Down
4 changes: 2 additions & 2 deletions widget/cpu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ local helpers = require("lain.helpers")
local wibox = require("wibox")
local math = math
local string = string
local tostring = tostring

-- CPU usage
-- lain.widget.cpu

local function factory(args)
local args = args or {}
args = args or {}

local cpu = { core = {}, widget = args.widget or wibox.widget.textbox() }
local timeout = args.timeout or 2
local settings = args.settings or function() end
Expand Down
4 changes: 2 additions & 2 deletions widget/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ local math = math
local string = string
local tconcat = table.concat
local type = type
local tonumber = tonumber
local query_size = Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE
local query_free = Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE
local query_used = Gio.FILE_ATTRIBUTE_FILESYSTEM_USED
Expand All @@ -26,7 +25,8 @@ local query = query_size .. "," .. query_free .. "," .. query_used
-- lain.widget.fs

local function factory(args)
local args = args or {}
args = args or {}

local fs = {
widget = args.widget or wibox.widget.textbox(),
units = {
Expand Down
3 changes: 2 additions & 1 deletion widget/imap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ local tonumber = tonumber
-- lain.widget.imap

local function factory(args)
local args = args or {}
args = args or {}

local imap = { widget = args.widget or wibox.widget.textbox() }
local server = args.server
local mail = args.mail
Expand Down
Loading

0 comments on commit 0a2ff9e

Please sign in to comment.