From 46f2d252c42d5040a472cb96732b16a19d83efd3 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 1 Mar 2015 00:12:05 -0300 Subject: Code cleanups suggested by luacheck. --- src/luarocks/add.lua | 2 +- src/luarocks/admin_remove.lua | 2 +- src/luarocks/build.lua | 19 +++++++++++-------- src/luarocks/build/builtin.lua | 4 ++-- src/luarocks/tools/patch.lua | 39 ++++++++++++++++++--------------------- src/luarocks/tools/zip.lua | 4 ++-- src/luarocks/write_rockspec.lua | 2 +- 7 files changed, 36 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua index fc913c95..81adff9b 100644 --- a/src/luarocks/add.lua +++ b/src/luarocks/add.lua @@ -50,7 +50,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) if not ok then return nil, err end local files = {} - for i, rockfile in ipairs(rockfiles) do + for _, rockfile in ipairs(rockfiles) do if fs.exists(rockfile) then util.printout("Copying file "..rockfile.." to "..local_cache.."...") local absolute = fs.absolute_name(rockfile) diff --git a/src/luarocks/admin_remove.lua b/src/luarocks/admin_remove.lua index 839121d1..5a1cf20b 100644 --- a/src/luarocks/admin_remove.lua +++ b/src/luarocks/admin_remove.lua @@ -46,7 +46,7 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve if not ok then return nil, err end local nr_files = 0 - for i, rockfile in ipairs(rockfiles) do + for _, rockfile in ipairs(rockfiles) do local basename = dir.base_name(rockfile) local file = dir.path(local_cache, basename) util.printout("Removing file "..file.."...") diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 01bfa9d9..96191b11 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -133,14 +133,14 @@ local function install_default_docs(name, version) local patterns = { "readme", "license", "copying" } local dest = dir.path(path.install_dir(name, version), "doc") local has_dir = false - for name in fs.dir() do + for file in fs.dir() do for _, pattern in ipairs(patterns) do - if name:lower():match("^"..pattern) then + if file:lower():match("^"..pattern) then if not has_dir then fs.make_dir(dest) has_dir = true end - fs.copy(name, dest) + fs.copy(file, dest) break end end @@ -181,7 +181,8 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m end end - local ok, err, errcode = deps.check_external_deps(rockspec, "build") + local ok + ok, err, errcode = deps.check_external_deps(rockspec, "build") if err then return nil, err, errcode end @@ -345,15 +346,17 @@ end function build.build_rock(rock_file, need_to_fetch, deps_mode) assert(type(rock_file) == "string") assert(type(need_to_fetch) == "boolean") - - local unpack_dir, err, errcode = fetch.fetch_and_unpack_rock(rock_file) + + local ok, err, errcode + local unpack_dir + unpack_dir, err, errcode = fetch.fetch_and_unpack_rock(rock_file) if not unpack_dir then return nil, err, errcode end local rockspec_file = path.rockspec_name_from_rock(rock_file) - local ok, err = fs.change_dir(unpack_dir) + ok, err = fs.change_dir(unpack_dir) if not ok then return nil, err end - local ok, err, errcode = build.build_rockspec(rockspec_file, need_to_fetch, false, deps_mode) + ok, err, errcode = build.build_rockspec(rockspec_file, need_to_fetch, false, deps_mode) fs.pop_dir() return ok, err, errcode end diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 47aa71fc..57af7dbc 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -74,7 +74,7 @@ function builtin.run(rockspec) add_flags(extras, "-I%s", incdirs) return execute(variables.CC.." "..variables.CFLAGS, "-c", "-o", object, "-I"..variables.LUA_INCDIR, source, unpack(extras)) end - compile_library = function(library, objects, libraries, libdirs, name) + compile_library = function(library, objects, libraries, libdirs) local extras = { unpack(objects) } add_flags(extras, "-L%s", libdirs) add_flags(extras, "-l%s", libraries) @@ -170,7 +170,7 @@ function builtin.run(rockspec) end return execute(variables.LD.." "..variables.LIBFLAG, "-o", library, "-L"..variables.LUA_LIBDIR, unpack(extras)) end - compile_wrapper_binary = function(fullname, name) return true, name end + compile_wrapper_binary = function(_, name) return true, name end --TODO EXEWRAPPER end diff --git a/src/luarocks/tools/patch.lua b/src/luarocks/tools/patch.lua index 8df3093d..b53bad61 100644 --- a/src/luarocks/tools/patch.lua +++ b/src/luarocks/tools/patch.lua @@ -22,8 +22,8 @@ local format = string.format -- logging local debugmode = false -local function debug(s) end -local function info(s) end +local function debug(_) end +local function info(_) end local function warning(s) io.stderr:write(s .. '\n') end -- Returns boolean whether string s2 starts with string s. @@ -57,27 +57,30 @@ end local function isfile() return true end --FIX? local function read_file(filename) - local fh, err, oserr = io.open(filename, 'rb') + local fh, data, err, oserr + fh, err, oserr = io.open(filename, 'rb') if not fh then return fh, err, oserr end - local data, err, oserr = fh:read'*a' + data, err, oserr = fh:read'*a' fh:close() if not data then return nil, err, oserr end return data end local function write_file(filename, data) - local fh, err, oserr = io.open(filename 'wb') + local fh, status, err, oserr + fh, err, oserr = io.open(filename 'wb') if not fh then return fh, err, oserr end - local status, err, oserr = fh:write(data) + status, err, oserr = fh:write(data) fh:close() if not status then return nil, err, oserr end return true end local function file_copy(src, dest) - local data, err, oserr = read_file(src) + local data, status, err, oserr + data, err, oserr = read_file(src) if not data then return data, err, oserr end - local status, err, oserr = write_file(dest) + status, err, oserr = write_file(dest) if not status then return status, err, oserr end return true end @@ -420,7 +423,7 @@ local function find_hunk(file, h, hno) end h.startsrc = location h.starttgt = h.starttgt + offset - for i=1,fuzz do + for _=1,fuzz do table.remove(h.text, 1) table.remove(h.text, #h.text) end @@ -532,7 +535,7 @@ local function patch_hunks(srcname, tgtname, hunks) local line2write = hline:sub(2) -- detect if line ends are consistent in source file local sum = 0 - for k,v in pairs(lineends) do if v > 0 then sum=sum+1 end end + for _,v in pairs(lineends) do if v > 0 then sum=sum+1 end end if sum == 1 then local newline for k,v in pairs(lineends) do if v ~= 0 then newline = k end end @@ -553,7 +556,7 @@ end local function strip_dirs(filename, strip) if strip == nil then return filename end - for i=1,strip do + for _=1,strip do filename=filename:gsub("^[^/]*/", "") end return filename @@ -593,7 +596,6 @@ function patch.apply_patch(the_patch, strip) local hunkno = 1 local hunk = hunks[hunkno] local hunkfind = {} - local hunkreplace = {} local validhunks = 0 local canpatch = false local hunklineno @@ -610,15 +612,10 @@ function patch.apply_patch(the_patch, strip) elseif lineno == hunk.startsrc then hunkfind = {} for _,x in ipairs(hunk.text) do - if x:sub(1,1) == ' ' or x:sub(1,1) == '-' then - hunkfind[#hunkfind+1] = endlstrip(x:sub(2)) - end end - hunkreplace = {} - for _,x in ipairs(hunk.text) do - if x:sub(1,1) == ' ' or x:sub(1,1) == '+' then - hunkreplace[#hunkreplace+1] = endlstrip(x:sub(2)) - end end - --pprint(hunkreplace) + if x:sub(1,1) == ' ' or x:sub(1,1) == '-' then + hunkfind[#hunkfind+1] = endlstrip(x:sub(2)) + end + end hunklineno = 1 -- todo \ No newline at end of file diff --git a/src/luarocks/tools/zip.lua b/src/luarocks/tools/zip.lua index 40cc089a..83a66434 100644 --- a/src/luarocks/tools/zip.lua +++ b/src/luarocks/tools/zip.lua @@ -10,7 +10,7 @@ local dir = require("luarocks.dir") local function number_to_bytestring(number, nbytes) local out = {} - for i = 1, nbytes do + for _ = 1, nbytes do local byte = number % 256 table.insert(out, string.char(byte)) number = (number - byte) / 256 @@ -237,7 +237,7 @@ function zip.zip(zipfile, ...) end end - local ok = zw:close() + ok = zw:close() if not ok then return false, "error closing "..zipfile end diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index 403cbc83..5b129ab0 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua @@ -219,7 +219,7 @@ function write_rockspec.run(...) version = flags["tag"]:gsub("^v", "") end end - + local protocol, pathname = dir.split_url(url_or_dir) if not fetch.is_basic_protocol(protocol) then if not name then -- cgit v1.2.3-55-g6feb