From 8c26e2dab4a00339dc8b41133bbd8ede6f75f1ad Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 7 Feb 2016 13:29:46 +0100 Subject: [PATCH] Fix all luacheck warnings in lib/gears Signed-off-by: Uli Schlachter --- lib/gears/cache.lua | 2 +- lib/gears/color.lua | 33 +++++++++++++++------------------ lib/gears/debug.lua | 2 -- lib/gears/matrix.lua | 10 +++++----- lib/gears/object.lua | 3 ++- lib/gears/shape.lua | 14 +++++++------- lib/gears/surface.lua | 2 +- lib/gears/timer.lua | 8 ++++---- lib/gears/wallpaper.lua | 16 ++++++++-------- 9 files changed, 43 insertions(+), 47 deletions(-) diff --git a/lib/gears/cache.lua b/lib/gears/cache.lua index 7329a1e79..905f58b08 100644 --- a/lib/gears/cache.lua +++ b/lib/gears/cache.lua @@ -7,7 +7,7 @@ local select = select local setmetatable = setmetatable -local unpack = unpack or table.unpack +local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) local cache = {} diff --git a/lib/gears/color.lua b/lib/gears/color.lua index 63533c48d..5454dfc3d 100644 --- a/lib/gears/color.lua +++ b/lib/gears/color.lua @@ -8,7 +8,7 @@ local setmetatable = setmetatable local string = string local table = table -local unpack = unpack or table.unpack -- v5.1: unpack, v5.2: table.unpack +local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) local tonumber = tonumber local ipairs = ipairs local pairs = pairs @@ -88,7 +88,6 @@ end -- @param col The color for the pattern -- @return A cairo pattern object function color.create_solid_pattern(col) - local col = col if col == nil then col = "#000000" elseif type(col) == "table" then @@ -102,7 +101,6 @@ end -- @param file The filename of the file -- @return a cairo pattern object function color.create_png_pattern(file) - local file = file if type(file) == "table" then file = file.file end @@ -138,7 +136,7 @@ local function string_pattern(creator, arg) local args = { parse_numbers(iterator()) } local to = { parse_numbers(iterator()) } -- Now merge those two tables - for k, v in pairs(to) do + for _, v in pairs(to) do table.insert(args, v) end -- And call our creator function with the values @@ -220,7 +218,7 @@ function color.create_pattern_uncached(col) if cairo.Pattern:is_type_of(col) then return col end - local col = col or "#000000" + col = col or "#000000" if type(col) == "string" then local t = string.match(col, "[^:]+") if color.types[t] then @@ -271,18 +269,17 @@ end -- @return The pattern if it is surely opaque, else nil function color.create_opaque_pattern(col) local pattern = color.create_pattern(col) - local type = pattern:get_type() - local extend = pattern:get_extend() + local kind = pattern:get_type() - if type == "SOLID" then - local status, r, g, b, a = pattern:get_rgba() - if a ~= 1 then + if kind == "SOLID" then + local _, _, _, _, alpha = pattern:get_rgba() + if alpha ~= 1 then return end return pattern - elseif type == "SURFACE" then - local status, surface = pattern:get_surface() - if status ~= "SUCCESS" or surface.content ~= "COLOR" then + elseif kind == "SURFACE" then + local status, surf = pattern:get_surface() + if status ~= "SUCCESS" or surf.content ~= "COLOR" then -- The surface has an alpha channel which *might* be non-opaque return end @@ -294,8 +291,8 @@ function color.create_opaque_pattern(col) end return pattern - elseif type == "LINEAR" then - local status, stops = pattern:get_color_stop_count() + elseif kind == "LINEAR" then + local _, stops = pattern:get_color_stop_count() -- No color stops or extend NONE -> pattern *might* contain transparency if stops == 0 or pattern:get_extend() == "NONE" then @@ -304,8 +301,8 @@ function color.create_opaque_pattern(col) -- Now check if any of the color stops contain transparency for i = 0, stops - 1 do - local status, offset, r, g, b, a = pattern:get_color_stop_rgba(i) - if a ~= 1 then + local _, _, _, _, _, alpha = pattern:get_color_stop_rgba(i) + if alpha ~= 1 then return end end @@ -330,7 +327,7 @@ function color.recolor_image(image, new_color) return image end -function color.mt:__call(...) +function color.mt.__call(_, ...) return color.create_pattern(...) end diff --git a/lib/gears/debug.lua b/lib/gears/debug.lua index af323e2e2..ec27ed5dc 100644 --- a/lib/gears/debug.lua +++ b/lib/gears/debug.lua @@ -5,9 +5,7 @@ -- @module gears.debug --------------------------------------------------------------------------- -local error = error local tostring = tostring -local traceback = debug.traceback local print = print local type = type local pairs = pairs diff --git a/lib/gears/matrix.lua b/lib/gears/matrix.lua index 687a4f967..ed91915eb 100644 --- a/lib/gears/matrix.lua +++ b/lib/gears/matrix.lua @@ -175,7 +175,7 @@ end -- @treturn number The x coordinate of the transformed point. -- @treturn number The x coordinate of the transformed point. function matrix:transform_point(x, y) - local x, y = self:transform_distance(x, y) + x, y = self:transform_distance(x, y) return self.x0 + x, self.y0 + y end @@ -195,10 +195,10 @@ function matrix:transform_rectangle(x, y, width, height) local x3, y3 = self:transform_point(x + width, y + height) local x4, y4 = self:transform_point(x + width, y) -- Find the extremal points of the result - local x = math.min(x1, x2, x3, x4) - local y = math.min(y1, y2, y3, y4) - local width = math.max(x1, x2, x3, x4) - x - local height = math.max(y1, y2, y3, y4) - y + x = math.min(x1, x2, x3, x4) + y = math.min(y1, y2, y3, y4) + width = math.max(x1, x2, x3, x4) - x + height = math.max(y1, y2, y3, y4) - y return x, y, width, height end diff --git a/lib/gears/object.lua b/lib/gears/object.lua index e2f9ef02d..2eb230cdb 100644 --- a/lib/gears/object.lua +++ b/lib/gears/object.lua @@ -60,6 +60,7 @@ local function make_the_gc_obey(func) -- Lua 5.1 only has the behaviour we want if a userdata is used as the -- value in a weak table. Thus, do some magic so that we get a userdata. + -- luacheck: globals newproxy getfenv setfenv local userdata = newproxy(true) getmetatable(userdata).__gc = function() end -- Now bind the lifetime of userdata to the lifetime of func. For this, @@ -137,7 +138,7 @@ local function new() return ret end -function object.mt:__call(...) +function object.mt.__call(_, ...) return new(...) end diff --git a/lib/gears/shape.lua b/lib/gears/shape.lua index 76b16f87c..eff81489b 100644 --- a/lib/gears/shape.lua +++ b/lib/gears/shape.lua @@ -64,9 +64,9 @@ end -- @tparam[opt=10] number arrow_size The width and height of the arrow -- @tparam[opt=width/2 - arrow_size/2] number arrow_position The position of the arrow function module.infobubble(cr, width, height, corner_radius, arrow_size, arrow_position) - local corner_radius = corner_radius or 5 - local arrow_size = arrow_size or 10 - local arrow_position = arrow_position or width/2 - arrow_size/2 + corner_radius = corner_radius or 5 + arrow_size = arrow_size or 10 + arrow_position = arrow_position or width/2 - arrow_size/2 cr:move_to(0 ,corner_radius) @@ -109,9 +109,9 @@ end -- @tparam[opt=width /2] number shaft_width The width of the shaft of the arrow -- @tparam[opt=height/2] number shaft_length The head_length of the shaft (the rest is the head) function module.arrow(cr, width, height, head_width, shaft_width, shaft_length) - local shaft_length = shaft_length or height / 2 - local shaft_width = shaft_width or width / 2 - local head_width = head_width or width + shaft_length = shaft_length or height / 2 + shaft_width = shaft_width or width / 2 + head_width = head_width or width local head_length = height - shaft_length cr:move_to ( width/2 , 0 ) @@ -146,7 +146,7 @@ end -- @tparam number height The shape height -- @tparam[opt=height/2] number arrow_depth The width of the arrow part of the shape function module.powerline(cr, width, height, arrow_depth) - local arrow_depth = arrow_depth or height/2 + arrow_depth = arrow_depth or height/2 cr:move_to(0 , 0 ) cr:line_to(width - arrow_depth , 0 ) cr:line_to(width , height/2 ) diff --git a/lib/gears/surface.lua b/lib/gears/surface.lua index 64afabea3..ed9e7b9c5 100644 --- a/lib/gears/surface.lua +++ b/lib/gears/surface.lua @@ -114,7 +114,7 @@ function surface.load(_surface) return do_load_and_handle_errors(_surface, surface.load_silently) end -function surface.mt:__call(...) +function surface.mt.__call(_, ...) return surface.load(...) end diff --git a/lib/gears/timer.lua b/lib/gears/timer.lua index 6eee64beb..1c50cefe1 100644 --- a/lib/gears/timer.lua +++ b/lib/gears/timer.lua @@ -14,7 +14,7 @@ local setmetatable = setmetatable local table = table local tonumber = tonumber local traceback = debug.traceback -local unpack = unpack or table.unpack -- v5.1: unpack, v5.2: table.unpack +local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) local glib = require("lgi").GLib local object = require("gears.object") @@ -43,7 +43,7 @@ function timer:start() return end self.data.source_id = glib.timeout_add(glib.PRIORITY_DEFAULT, self.data.timeout * 1000, function() - local success, message = xpcall(function() + xpcall(function() self:emit_signal("timeout") end, function(err) print(debug.traceback("Error during executing timeout handler: "..tostring(err))) @@ -160,7 +160,7 @@ end local delayed_calls = {} capi.awesome.connect_signal("refresh", function() for _, callback in ipairs(delayed_calls) do - local success, message = xpcall(function() + xpcall(function() callback[1](unpack(callback, 2)) end, function(err) print(debug.traceback("Error during delayed call: "..tostring(err), 2)) @@ -177,7 +177,7 @@ function timer.delayed_call(callback, ...) table.insert(delayed_calls, { callback, ... }) end -function timer.mt:__call(...) +function timer.mt.__call(_, ...) return timer.new(...) end diff --git a/lib/gears/wallpaper.lua b/lib/gears/wallpaper.lua index e09262a9d..aba2464e2 100644 --- a/lib/gears/wallpaper.lua +++ b/lib/gears/wallpaper.lua @@ -58,9 +58,9 @@ function wallpaper.prepare_context(s) -- Set the wallpaper (delayed) timer.delayed_call(function() - local wp = pending_wallpaper + local paper = pending_wallpaper pending_wallpaper = nil - wallpaper.set(wp) + wallpaper.set(paper) end) else -- Draw to the already-pending wallpaper @@ -99,8 +99,8 @@ end -- gears.color. The default is black. function wallpaper.centered(surf, s, background) local geom, cr = wallpaper.prepare_context(s) - local surf = surface(surf) - local background = color(background) + surf = surface(surf) + background = color(background) -- Fill the area with the background cr.operator = cairo.Operator.SOURCE @@ -122,7 +122,7 @@ end -- all screens are set. -- @param offset This can be set to a table with entries x and y. function wallpaper.tiled(surf, s, offset) - local geom, cr = wallpaper.prepare_context(s) + local _, cr = wallpaper.prepare_context(s) if offset then cr:translate(offset.x, offset.y) @@ -144,7 +144,7 @@ end -- @param offset This can be set to a table with entries x and y. function wallpaper.maximized(surf, s, ignore_aspect, offset) local geom, cr = wallpaper.prepare_context(s) - local surf = surface(surf) + surf = surface(surf) local w, h = surface.get_size(surf) local aspect_w = geom.width / w local aspect_h = geom.height / h @@ -176,8 +176,8 @@ end -- gears.color. The default is black. function wallpaper.fit(surf, s, background) local geom, cr = wallpaper.prepare_context(s) - local surf = surface(surf) - local background = color(background) + surf = surface(surf) + background = color(background) -- Fill the area with the background cr.operator = cairo.Operator.SOURCE