minor: a lot of luacheck fixes

pull/1820/head
Qingping Hou 8 years ago
parent 5e3100874f
commit e422842256

@ -6,6 +6,9 @@ globals = {
} }
read_globals = { read_globals = {
"ANDROID_FONT_DIR",
"KOBO_TOUCH_MIRRORED",
"KOBO_SYNC_BRIGHTNESS_WITH_NICKEL",
"DRCOUNTMAX", "DRCOUNTMAX",
"DHINTCOUNT", "DHINTCOUNT",
"DFULL_SCREEN", "DFULL_SCREEN",

@ -71,7 +71,7 @@ script:
- make all - make all
- travis_retry make testfront - travis_retry make testfront
- luajit $(which luacheck) --no-color -q frontend | tee ./luacheck.out - luajit $(which luacheck) --no-color -q frontend | tee ./luacheck.out
- test $(grep Total ./luacheck.out | awk '{print $2}') -le 140 - test $(grep Total ./luacheck.out | awk '{print $2}') -le 65
after_success: after_success:
- make coverage - make coverage

@ -1,21 +1,10 @@
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local FrameContainer = require("ui/widget/container/framecontainer") local FrameContainer = require("ui/widget/container/framecontainer")
local FileManagerMenu = require("apps/filemanager/filemanagermenu")
local DocumentRegistry = require("document/documentregistry")
local VerticalGroup = require("ui/widget/verticalgroup")
local ButtonDialog = require("ui/widget/buttondialog")
local VerticalSpan = require("ui/widget/verticalspan")
local OPDSBrowser = require("ui/widget/opdsbrowser") local OPDSBrowser = require("ui/widget/opdsbrowser")
local TextWidget = require("ui/widget/textwidget")
local lfs = require("libs/libkoreader-lfs")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local Font = require("ui/font")
local Screen = require("device").screen local Screen = require("device").screen
local Geom = require("ui/geometry")
local Event = require("ui/event")
local DEBUG = require("dbg") local DEBUG = require("dbg")
local _ = require("gettext") local _ = require("gettext")
local util = require("ffi/util")
local Blitbuffer = require("ffi/blitbuffer") local Blitbuffer = require("ffi/blitbuffer")
local OPDSCatalog = InputContainer:extend{ local OPDSCatalog = InputContainer:extend{

@ -92,7 +92,7 @@ function ReaderBookmark:importSavedHighlight(config)
if not config:readSetting("highlights_imported") then if not config:readSetting("highlights_imported") then
for page, marks in pairs(textmarks) do for page, marks in pairs(textmarks) do
for _, mark in ipairs(marks) do for _, mark in ipairs(marks) do
local page = self.ui.document.info.has_pages and page or mark.pos0 page = self.ui.document.info.has_pages and page or mark.pos0
-- highlights saved by some old versions don't have pos0 field -- highlights saved by some old versions don't have pos0 field
-- we just ignore those highlights -- we just ignore those highlights
if page then if page then
@ -125,7 +125,7 @@ function ReaderBookmark:onSaveSettings()
end end
function ReaderBookmark:onToggleBookmark() function ReaderBookmark:onToggleBookmark()
local pn_or_xp = nil local pn_or_xp
if self.ui.document.info.has_pages then if self.ui.document.info.has_pages then
pn_or_xp = self.view.state.page pn_or_xp = self.view.state.page
else else
@ -295,16 +295,16 @@ end
-- binary search of sorted bookmarks -- binary search of sorted bookmarks
function ReaderBookmark:isBookmarkAdded(item) function ReaderBookmark:isBookmarkAdded(item)
local _start, _middle, _end, direction = 1, 1, #self.bookmarks, 0 local _start, _middle, _end = 1, 1, #self.bookmarks
while _start <= _end do while _start <= _end do
_middle = math.floor((_start + _end)/2) _middle = math.floor((_start + _end)/2)
if self:isBookmarkSame(item, self.bookmarks[_middle]) then if self:isBookmarkSame(item, self.bookmarks[_middle]) then
return true return true
end end
if self:isBookmarkInPageOrder(item, self.bookmarks[_middle]) then if self:isBookmarkInPageOrder(item, self.bookmarks[_middle]) then
_end, direction = _middle - 1, 0 _end = _middle - 1
else else
_start, direction = _middle + 1, 1 _start = _middle + 1
end end
end end
return false return false

@ -1,9 +1,6 @@
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local Screen = require("device").screen
local Geom = require("ui/geometry")
local Device = require("device") local Device = require("device")
local Event = require("ui/event") local Event = require("ui/event")
local GestureRange = require("ui/gesturerange")
local _ = require("gettext") local _ = require("gettext")
local ReaderRotation = InputContainer:new{ local ReaderRotation = InputContainer:new{
@ -26,7 +23,7 @@ function ReaderRotation:init()
end end
end end
-- TODO: reset rotation on new document, maybe on new page? -- @TODO: reset rotation on new document, maybe on new page?
function ReaderRotation:onRotate(rotate_by) function ReaderRotation:onRotate(rotate_by)
self.current_rotation = (self.current_rotation + rotate_by) % 360 self.current_rotation = (self.current_rotation + rotate_by) % 360

@ -1,8 +1,6 @@
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local ButtonDialog = require("ui/widget/buttondialog") local ButtonDialog = require("ui/widget/buttondialog")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local Geom = require("ui/geometry")
local Screen = require("ui/screen")
local DEBUG = require("dbg") local DEBUG = require("dbg")
local _ = require("gettext") local _ = require("gettext")
@ -69,7 +67,7 @@ function ReaderSearch:onShowSearchDialog(text)
self.ui.highlight:clear() self.ui.highlight:clear()
end, end,
} }
local res = do_search(self.searchFromCurrent, text, 0)() do_search(self.searchFromCurrent, text, 0)()
UIManager:show(self.search_dialog) UIManager:show(self.search_dialog)
-- TODO: regional -- TODO: regional
UIManager:setDirty(self.dialog, "partial") UIManager:setDirty(self.dialog, "partial")

@ -1,5 +1,5 @@
local Generic = require("device/generic/device") local Generic = require("device/generic/device")
local isAndroid, android = pcall(require, "android") local _, android = pcall(require, "android")
local ffi = require("ffi") local ffi = require("ffi")
local DEBUG = require("dbg") local DEBUG = require("dbg")

@ -40,7 +40,7 @@ local Device = {
} }
function Device:new(o) function Device:new(o)
local o = o or {} o = o or {}
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
return o return o

@ -10,7 +10,7 @@ local BasePowerD = {
} }
function BasePowerD:new(o) function BasePowerD:new(o)
local o = o or {} o = o or {}
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
if o.init then o:init() end if o.init then o:init() end

@ -73,7 +73,7 @@ local GestureDetector = {
} }
function GestureDetector:new(o) function GestureDetector:new(o)
local o = o or {} o = o or {}
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
if o.init then o:init() end if o.init then o:init() end

@ -6,6 +6,8 @@ local _ = require("gettext")
local Key = require("device/key") local Key = require("device/key")
local GestureDetector = require("device/gesturedetector") local GestureDetector = require("device/gesturedetector")
-- luacheck: push
-- luacheck: ignore
-- constants from <linux/input.h> -- constants from <linux/input.h>
local EV_SYN = 0 local EV_SYN = 0
local EV_KEY = 1 local EV_KEY = 1
@ -36,6 +38,7 @@ local ABS_MT_POSITION_X = 53
local ABS_MT_POSITION_Y = 54 local ABS_MT_POSITION_Y = 54
local ABS_MT_TRACKING_ID = 57 local ABS_MT_TRACKING_ID = 57
local ABS_MT_PRESSURE = 58 local ABS_MT_PRESSURE = 58
-- luacheck: pop
--[[ --[[
an interface to get input events an interface to get input events
@ -105,7 +108,7 @@ local Input = {
} }
function Input:new(o) function Input:new(o)
local o = o or {} o = o or {}
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
if o.init then o:init() end if o.init then o:init() end

@ -147,8 +147,11 @@ function Kindle4:init()
Kindle.init(self) Kindle.init(self)
end end
-- luacheck: push
-- luacheck: ignore
local ABS_MT_POSITION_X = 53 local ABS_MT_POSITION_X = 53
local ABS_MT_POSITION_Y = 54 local ABS_MT_POSITION_Y = 54
-- luacheck: pop
function KindleTouch:init() function KindleTouch:init()
self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = DEBUG} self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = DEBUG}
self.powerd = require("device/kindle/powerd"):new{ self.powerd = require("device/kindle/powerd"):new{

@ -1,6 +1,8 @@
local Generic = require("device/generic/device") -- <= look at this file! local Generic = require("device/generic/device") -- <= look at this file!
local DEBUG = require("dbg") local DEBUG = require("dbg")
-- luacheck: push
-- luacheck: ignore
local EVT_INIT = 21 local EVT_INIT = 21
local EVT_EXIT = 22 local EVT_EXIT = 22
local EVT_SHOW = 23 local EVT_SHOW = 23
@ -32,6 +34,7 @@ local KEY_PREV2 = 0x1c
local KEY_NEXT2 = 0x1d local KEY_NEXT2 = 0x1d
local KEY_COVEROPEN = 0x02 local KEY_COVEROPEN = 0x02
local KEY_COVERCLOSE = 0x03 local KEY_COVERCLOSE = 0x03
-- luacheck: pop
local function yes() return true end local function yes() return true end
@ -49,12 +52,12 @@ function PocketBook:init()
ev.value = ev.type == EVT_KEYDOWN and 1 or 0 ev.value = ev.type == EVT_KEYDOWN and 1 or 0
ev.type = 1 -- EV_KEY ev.type = 1 -- EV_KEY
elseif ev.type == EVT_BACKGROUND then elseif ev.type == EVT_BACKGROUND then
isInBackGround = true self.isInBackGround = true
self:onPowerEvent("Power") self:onPowerEvent("Power")
elseif isInBackGround and ev.type == EVT_FOREGROUND then elseif self.isInBackGround and ev.type == EVT_FOREGROUND then
isInBackGround = false self.isInBackGround = false
self:onPowerEvent("Power") self:onPowerEvent("Power")
elseif not isInBackGround and ev.type == EVT_FOREGROUND then elseif not self.isInBackGround and ev.type == EVT_FOREGROUND then
self.screen:refreshPartial() self.screen:refreshPartial()
end end
end) end)

@ -594,7 +594,7 @@ function KoptInterface:getReflewOCRWord(doc, pageno, rect)
local cached = Cache:check(kctx_hash) local cached = Cache:check(kctx_hash)
if cached then if cached then
local kc = self:waitForContext(cached.kctx) local kc = self:waitForContext(cached.kctx)
local ok, word = pcall( local _, word = pcall(
kc.getTOCRWord, kc, "dst", kc.getTOCRWord, kc, "dst",
rect.x, rect.y, rect.w, rect.h, rect.x, rect.y, rect.w, rect.h,
self.tessocr_data, self.ocr_lang, self.ocr_type, 0, 1) self.tessocr_data, self.ocr_lang, self.ocr_type, 0, 1)
@ -628,7 +628,7 @@ function KoptInterface:getNativeOCRWord(doc, pageno, rect)
--kc:exportSrcPNGFile({rect}, nil, "ocr-word.png") --kc:exportSrcPNGFile({rect}, nil, "ocr-word.png")
local word_w, word_h = kc:getPageDim() local word_w, word_h = kc:getPageDim()
--DEBUG(word_w, word_h) --DEBUG(word_w, word_h)
local ok, word = pcall( local _, word = pcall(
kc.getTOCRWord, kc, "src", kc.getTOCRWord, kc, "src",
0, 0, word_w, word_h, 0, 0, word_w, word_h,
self.tessocr_data, self.ocr_lang, self.ocr_type, 0, 1) self.tessocr_data, self.ocr_lang, self.ocr_type, 0, 1)
@ -655,7 +655,7 @@ end
function KoptInterface:getClipPageContext(doc, pos0, pos1, pboxes, drawer) function KoptInterface:getClipPageContext(doc, pos0, pos1, pboxes, drawer)
assert(pos0.page == pos1.page) assert(pos0.page == pos1.page)
assert(pos0.zoom == pos1.zoom) assert(pos0.zoom == pos1.zoom)
local rect = nil local rect
if pboxes and #pboxes > 0 then if pboxes and #pboxes > 0 then
local box = pboxes[1] local box = pboxes[1]
rect = Geom:new{ rect = Geom:new{
@ -1060,7 +1060,7 @@ function KoptInterface:nativeToPageRectTransform(doc, pageno, rect)
y = rect.y + rect.h - 5 y = rect.y + rect.h - 5
} }
local boxes = self:getPageBoxesFromPositions(doc, pageno, pos0, pos1) local boxes = self:getPageBoxesFromPositions(doc, pageno, pos0, pos1)
res_rect = nil local res_rect = nil
if #boxes > 0 then if #boxes > 0 then
res_rect = boxes[1] res_rect = boxes[1]
for _, box in pairs(boxes) do for _, box in pairs(boxes) do

@ -422,7 +422,7 @@ function UIManager:_refresh(mode, region)
-- combine both refreshes' regions -- combine both refreshes' regions
local combined = region:combine(self._refresh_stack[i].region) local combined = region:combine(self._refresh_stack[i].region)
-- update the mode, if needed -- update the mode, if needed
local mode = update_mode(mode, self._refresh_stack[i].mode) mode = update_mode(mode, self._refresh_stack[i].mode)
-- remove colliding update -- remove colliding update
table.remove(self._refresh_stack, i) table.remove(self._refresh_stack, i)
-- and try again with combined data -- and try again with combined data

Loading…
Cancel
Save