From 551857ce6ebafe6cdd68a1d7796a476bade29ae8 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 28 Jun 2016 00:43:23 +0800 Subject: [PATCH] fix some luacheck warnings --- .ci/script.sh | 2 +- frontend/apps/reader/modules/readerpaging.lua | 4 +-- frontend/apps/reader/modules/readersearch.lua | 4 +-- frontend/apps/reader/modules/readerview.lua | 2 +- frontend/document/koptinterface.lua | 30 +++++++++---------- frontend/ui/data/koptoptions.lua | 8 ----- .../screen_disable_double_tap_table.lua | 2 +- .../ui/elements/screen_dpi_menu_table.lua | 30 +++++++++---------- frontend/ui/uimanager.lua | 4 +-- 9 files changed, 39 insertions(+), 47 deletions(-) diff --git a/.ci/script.sh b/.ci/script.sh index 62ff30eda..04df1e83f 100755 --- a/.ci/script.sh +++ b/.ci/script.sh @@ -8,4 +8,4 @@ make all retry_cmd 2 make testfront set +o pipefail luajit $(which luacheck) --no-color -q frontend | tee ./luacheck.out -test $(grep Total ./luacheck.out | awk '{print $2}') -le 53 +test $(grep Total ./luacheck.out | awk '{print $2}') -le 25 diff --git a/frontend/apps/reader/modules/readerpaging.lua b/frontend/apps/reader/modules/readerpaging.lua index f8fc54ad9..768f70f1e 100644 --- a/frontend/apps/reader/modules/readerpaging.lua +++ b/frontend/apps/reader/modules/readerpaging.lua @@ -605,7 +605,7 @@ function ReaderPaging:genPageStatesFromTop(top_page_state, blank_area, offset) if self.current_page == self.number_of_pages then break end self:_gotoPage(current_page + 1, "scrolling") current_page = current_page + 1 - local state = self:getNextPageState(blank_area, Geom:new{}) + state = self:getNextPageState(blank_area, Geom:new{}) table.insert(page_states, state) end end @@ -627,7 +627,7 @@ function ReaderPaging:genPageStatesFromBottom(bottom_page_state, blank_area, off if self.current_page == 1 then break end self:_gotoPage(current_page - 1, "scrolling") current_page = current_page - 1 - local state = self:getPrevPageState(blank_area, Geom:new{}) + state = self:getPrevPageState(blank_area, Geom:new{}) table.insert(page_states, 1, state) end end diff --git a/frontend/apps/reader/modules/readersearch.lua b/frontend/apps/reader/modules/readersearch.lua index 04dd1a38f..b5478e9a8 100644 --- a/frontend/apps/reader/modules/readersearch.lua +++ b/frontend/apps/reader/modules/readersearch.lua @@ -27,9 +27,9 @@ function ReaderSearch:addToMainMenu(tab_item_table) end function ReaderSearch:onShowSearchDialog(text) - local do_search = function(search_func, text, param) + local do_search = function(search_func, _text, param) return function() - local res = search_func(self, text, param) + local res = search_func(self, _text, param) if res then if self.ui.document.info.has_pages then self.ui.link:onGotoLink({page = res.page - 1}) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 16fe52a07..bd8c36927 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -452,7 +452,7 @@ function ReaderView:drawXPointerSavedHighlight(bb, x, y) end -- end for all saved highlight end -function ReaderView:drawHighlightRect(bb, x, y, rect, drawer) +function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer) local x, y, w, h = rect.x, rect.y, rect.w, rect.h if drawer == "underscore" then diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index 4c7ff4f5b..641071b68 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -322,12 +322,12 @@ function KoptInterface:renderOptimizedPage(doc, pageno, rect, zoom, rotation, re local cached = Cache:check(renderpg_hash, TileCacheItem) if not cached then local page_size = Document.getNativePageDimensions(doc, pageno) - local bbox = { + local full_page_bbox = { x0 = 0, y0 = 0, x1 = page_size.w, y1 = page_size.h, } - local kc = self:createContext(doc, pageno, bbox) + local kc = self:createContext(doc, pageno, full_page_bbox) local page = doc._document:openPage(pageno) kc:setZoom(zoom) page:getPagePix(kc) @@ -444,7 +444,7 @@ function KoptInterface:getReflowedTextBoxes(doc, pageno) local cached = Cache:check(hash) if not cached then local kctx_hash = "kctx|"..context_hash - local cached = Cache:check(kctx_hash) + cached = Cache:check(kctx_hash) if cached then local kc = self:waitForContext(cached.kctx) --kc:setDebug() @@ -468,7 +468,7 @@ function KoptInterface:getNativeTextBoxes(doc, pageno) local cached = Cache:check(hash) if not cached then local kctx_hash = "kctx|"..context_hash - local cached = Cache:check(kctx_hash) + cached = Cache:check(kctx_hash) if cached then local kc = self:waitForContext(cached.kctx) --kc:setDebug() @@ -493,7 +493,7 @@ function KoptInterface:getReflowedTextBoxesFromScratch(doc, pageno) local cached = Cache:check(hash) if not cached then local kctx_hash = "kctx|"..context_hash - local cached = Cache:check(kctx_hash) + cached = Cache:check(kctx_hash) if cached then local reflowed_kc = self:waitForContext(cached.kctx) local fullwidth, fullheight = reflowed_kc:getPageDim() @@ -541,19 +541,19 @@ end get page regions in native page via optical method, --]] function KoptInterface:getPageBlock(doc, pageno, x, y) - local kctx = nil + local kctx local bbox = doc:getPageBBox(pageno) local context_hash = self:getContextHash(doc, pageno, bbox) local hash = "pageblocks|"..context_hash local cached = Cache:check(hash) if not cached then local page_size = Document.getNativePageDimensions(doc, pageno) - local bbox = { + local full_page_bbox = { x0 = 0, y0 = 0, x1 = page_size.w, y1 = page_size.h, } - local kc = self:createContext(doc, pageno, bbox) + local kc = self:createContext(doc, pageno, full_page_bbox) local screen_size = Screen:getSize() -- leptonica needs a source image of at least 300dpi kc:setZoom(screen_size.w / page_size.w * 300 / self.screen_dpi) @@ -594,7 +594,7 @@ function KoptInterface:getReflewOCRWord(doc, pageno, rect) local cached = Cache:check(hash) if not cached then local kctx_hash = "kctx|"..context_hash - local cached = Cache:check(kctx_hash) + cached = Cache:check(kctx_hash) if cached then local kc = self:waitForContext(cached.kctx) local _, word = pcall( @@ -665,8 +665,8 @@ function KoptInterface:getClipPageContext(doc, pos0, pos1, pboxes, drawer) x = box.x, y = box.y, w = box.w, h = box.h, } - for _, box in ipairs(pboxes) do - rect = rect:combine(Geom:new(box)) + for _, _box in ipairs(pboxes) do + rect = rect:combine(Geom:new(_box)) end else local zoom = pos0.zoom or 1 @@ -910,9 +910,9 @@ end get link from position in screen page ]]-- function KoptInterface:getLinkFromPosition(doc, pageno, pos) - local function inside_box(pos, box) - if pos then - local x, y = pos.x, pos.y + local function _inside_box(_pos, box) + if _pos then + local x, y = _pos.x, _pos.y if box.x <= x and box.y <= y and box.x + box.w >= x and box.y + box.h >= y then @@ -934,7 +934,7 @@ function KoptInterface:getLinkFromPosition(doc, pageno, pos) w = link.x1 - link.x0 + Screen:scaleBySize(10), h = link.y1 - link.y0 + Screen:scaleBySize(10) } - if inside_box(pos, lbox) and link.page then + if _inside_box(pos, lbox) and link.page then return link, lbox end end diff --git a/frontend/ui/data/koptoptions.lua b/frontend/ui/data/koptoptions.lua index 4aa4efe8d..4a6df57d3 100644 --- a/frontend/ui/data/koptoptions.lua +++ b/frontend/ui/data/koptoptions.lua @@ -6,14 +6,6 @@ local function enable_if_equals(configurable, option, value) return configurable[option] == value end -local function enable_if_greater_than(configurable, option, value) - return configurable[option] > value -end - -local function enable_if_less_than(configurable, option, value) - return configurable[option] < value -end - local KoptOptions = { prefix = 'kopt', { diff --git a/frontend/ui/elements/screen_disable_double_tap_table.lua b/frontend/ui/elements/screen_disable_double_tap_table.lua index 54dfc5759..6fe1e0acb 100644 --- a/frontend/ui/elements/screen_disable_double_tap_table.lua +++ b/frontend/ui/elements/screen_disable_double_tap_table.lua @@ -8,7 +8,7 @@ return { return G_reader_settings:readSetting("disable_double_tap") ~= false end, callback = function() - disabled = G_reader_settings:readSetting("disable_double_tap") ~= false + local disabled = G_reader_settings:readSetting("disable_double_tap") ~= false G_reader_settings:saveSetting("disable_double_tap", not disabled) UIManager:show(InfoMessage:new{ text = _("This will take effect on next restart."), diff --git a/frontend/ui/elements/screen_dpi_menu_table.lua b/frontend/ui/elements/screen_dpi_menu_table.lua index 2dcbcb029..eb6bfa72f 100644 --- a/frontend/ui/elements/screen_dpi_menu_table.lua +++ b/frontend/ui/elements/screen_dpi_menu_table.lua @@ -6,13 +6,13 @@ local function dpi() return G_reader_settings:readSetting("screen_dpi") end local function custom() return G_reader_settings:readSetting("custom_screen_dpi") end -local function setDPI(dpi) +local function setDPI(_dpi) local InfoMessage = require("ui/widget/infomessage") local UIManager = require("ui/uimanager") UIManager:show(InfoMessage:new{ text = _("This will take effect on next restart."), }) - Screen:setDPI(dpi) + Screen:setDPI(_dpi) end @@ -29,32 +29,32 @@ return { { text = _("Small"), checked_func = function() - local dpi, custom = dpi(), custom() - return dpi and dpi <= 140 and dpi ~= custom + local _dpi, _custom = dpi(), custom() + return _dpi and _dpi <= 140 and _dpi ~= _custom end, callback = function() setDPI(120) end }, { text = _("Medium"), checked_func = function() - local dpi, custom = dpi(), custom() - return dpi and dpi > 140 and dpi <= 200 and dpi ~= custom + local _dpi, _custom = dpi(), custom() + return _dpi and _dpi > 140 and _dpi <= 200 and _dpi ~= _custom end, callback = function() setDPI(160) end }, { text = _("Large"), checked_func = function() - local dpi, custom = dpi(), custom() - return dpi and dpi > 200 and dpi ~= custom + local _dpi, _custom = dpi(), custom() + return _dpi and _dpi > 200 and _dpi ~= _custom end, callback = function() setDPI(240) end }, { text = _("Custom DPI") .. ": " .. (custom() or 160), checked_func = function() - local dpi, custom = dpi(), custom() - return custom and dpi == custom + local _dpi, _custom = dpi(), custom() + return _custom and _dpi == _custom end, callback = function() setDPI(custom() or 160) end, hold_input = { @@ -62,11 +62,11 @@ return { type = "number", hint = "(90 - 330)", callback = function(input) - local dpi = tonumber(input) - dpi = dpi < 90 and 90 or dpi - dpi = dpi > 330 and 330 or dpi - G_reader_settings:saveSetting("custom_screen_dpi", dpi) - setDPI(dpi) + local _dpi = tonumber(input) + _dpi = _dpi < 90 and 90 or _dpi + _dpi = _dpi > 330 and 330 or _dpi + G_reader_settings:saveSetting("custom_screen_dpi", _dpi) + setDPI(_dpi) end, }, }, diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 379fe5064..c5269227c 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -420,14 +420,14 @@ function UIManager:broadcastEvent(event) -- the widget's event handler might close widgets in which case -- a simple iterator like ipairs would skip over some entries local i = 1 - while (i <= #self._window_stack) do + while i <= #self._window_stack do local prev_widget = self._window_stack[i].widget self._window_stack[i].widget:handleEvent(event) local top_widget = self._window_stack[i] if top_widget == nil then -- top widget closed itself break - elseif (top_window.widget == prev_widget) then + elseif top_widget.widget == prev_widget then i = i + 1 end end