From deb9cadc7012262eb0eaf4cb58b654b62106d6de Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 27 Aug 2024 17:01:20 -0300 Subject: Teal: fixed all warnings Also addressed/removed all `--!` comments except for the ones that should stay. --- src/luarocks/admin/cmd/add.lua | 2 +- src/luarocks/admin/cmd/add.tl | 4 +-- src/luarocks/admin/cmd/refresh_cache.lua | 5 +-- src/luarocks/admin/cmd/refresh_cache.tl | 5 +-- src/luarocks/admin/cmd/remove.lua | 6 ++-- src/luarocks/admin/cmd/remove.tl | 8 ++--- src/luarocks/admin/index.lua | 16 +++++----- src/luarocks/admin/index.tl | 14 ++++---- src/luarocks/build.lua | 10 +++--- src/luarocks/build.tl | 10 +++--- src/luarocks/build/builtin.lua | 8 ++--- src/luarocks/build/builtin.tl | 8 ++--- src/luarocks/cmd.lua | 51 +++++++++++++++-------------- src/luarocks/cmd.tl | 55 +++++++++++++++++--------------- src/luarocks/cmd/build.lua | 9 +++--- src/luarocks/cmd/build.tl | 9 +++--- src/luarocks/cmd/config.lua | 11 ++++--- src/luarocks/cmd/config.tl | 13 ++++---- src/luarocks/cmd/doc.lua | 18 ++++++++--- src/luarocks/cmd/doc.tl | 18 ++++++++--- src/luarocks/cmd/init.lua | 7 ++-- src/luarocks/cmd/init.tl | 7 ++-- src/luarocks/cmd/install.lua | 16 ++++++---- src/luarocks/cmd/install.tl | 20 +++++++----- src/luarocks/cmd/make.lua | 11 ++++--- src/luarocks/cmd/make.tl | 11 ++++--- src/luarocks/cmd/new_version.lua | 35 ++++++++++++-------- src/luarocks/cmd/new_version.tl | 43 ++++++++++++++----------- src/luarocks/cmd/purge.lua | 12 +++---- src/luarocks/cmd/purge.tl | 10 +++--- src/luarocks/cmd/show.lua | 6 ++-- src/luarocks/cmd/show.tl | 6 ++-- src/luarocks/cmd/test.tl | 2 +- src/luarocks/cmd/unpack.lua | 8 +++-- src/luarocks/cmd/unpack.tl | 8 +++-- src/luarocks/cmd/upload.lua | 8 +++-- src/luarocks/cmd/upload.tl | 8 +++-- src/luarocks/cmd/write_rockspec.lua | 3 +- src/luarocks/cmd/write_rockspec.tl | 3 +- src/luarocks/core/types/args.d.tl | 14 ++++---- src/luarocks/download.lua | 6 ++-- src/luarocks/download.tl | 12 +++---- src/luarocks/fetch.tl | 2 +- src/luarocks/fetch/cvs.lua | 2 +- src/luarocks/fetch/cvs.tl | 2 +- src/luarocks/fetch/git.lua | 2 +- src/luarocks/fetch/git.tl | 2 +- src/luarocks/fetch/hg.lua | 2 +- src/luarocks/fetch/hg.tl | 2 +- src/luarocks/fetch/sscm.lua | 2 +- src/luarocks/fetch/sscm.tl | 2 +- src/luarocks/fetch/svn.lua | 2 +- src/luarocks/fetch/svn.tl | 2 +- src/luarocks/fs.d.tl | 2 +- src/luarocks/manif.tl | 2 +- src/luarocks/manif/writer.lua | 22 ++++++------- src/luarocks/manif/writer.tl | 28 ++++++++-------- src/luarocks/pack.lua | 19 +++++++---- src/luarocks/pack.tl | 19 +++++++---- src/luarocks/queries.lua | 1 - src/luarocks/queries.tl | 1 - src/luarocks/remove.lua | 11 +++++-- src/luarocks/remove.tl | 11 +++++-- src/luarocks/repos.lua | 23 +++++++------ src/luarocks/repos.tl | 23 +++++++------ src/luarocks/rockspecs.lua | 2 +- src/luarocks/rockspecs.tl | 4 +-- src/luarocks/test/busted.lua | 1 - src/luarocks/test/busted.tl | 1 - src/luarocks/tools/patch.lua | 29 ++++++----------- src/luarocks/tools/patch.tl | 34 ++++++++++---------- src/luarocks/tools/tar.lua | 9 +++--- src/luarocks/tools/tar.tl | 11 +++---- src/luarocks/tools/zip.lua | 6 ++-- src/luarocks/tools/zip.tl | 8 ++--- src/luarocks/type/manifest.tl | 2 +- src/luarocks/type_check.tl | 6 ++-- 77 files changed, 464 insertions(+), 369 deletions(-) (limited to 'src') diff --git a/src/luarocks/admin/cmd/add.lua b/src/luarocks/admin/cmd/add.lua index 862a08a8..d6572dae 100644 --- a/src/luarocks/admin/cmd/add.lua +++ b/src/luarocks/admin/cmd/add.lua @@ -73,7 +73,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server, do return nil, "No files found" end - local ok, err = fs.change_dir(local_cache) + ok, err = fs.change_dir(local_cache) if not ok then return nil, err end util.printout("Updating manifest...") diff --git a/src/luarocks/admin/cmd/add.tl b/src/luarocks/admin/cmd/add.tl index e544be96..56be7044 100644 --- a/src/luarocks/admin/cmd/add.tl +++ b/src/luarocks/admin/cmd/add.tl @@ -73,7 +73,7 @@ local function add_files_to_server(refresh: boolean, rockfiles: {string}, server return nil, "No files found" end - local ok, err = fs.change_dir(local_cache) + ok, err = fs.change_dir(local_cache) if not ok then return nil, err end util.printout("Updating manifest...") @@ -125,7 +125,7 @@ local function add_files_to_server(refresh: boolean, rockfiles: {string}, server return fs.execute(cmd) end -function add.command(args: Args): boolean, string, string --! +function add.command(args: Args): boolean, string, string local server, server_table, err = cache.get_upload_server(args.add_server or args.server) if not server then return nil, err end return add_files_to_server(not args.no_refresh, args.rocks, server, server_table, args.index) diff --git a/src/luarocks/admin/cmd/refresh_cache.lua b/src/luarocks/admin/cmd/refresh_cache.lua index 08e90bbc..35b7a3e9 100644 --- a/src/luarocks/admin/cmd/refresh_cache.lua +++ b/src/luarocks/admin/cmd/refresh_cache.lua @@ -24,8 +24,9 @@ function refresh_cache.command(args) if not server then return nil, err end local download_url = cache.get_server_urls(server, upload_server) - local ok, err = cache.refresh_local_cache(download_url, cfg.upload_user, cfg.upload_password) - if not ok then + local local_cache + local_cache, err = cache.refresh_local_cache(download_url, cfg.upload_user, cfg.upload_password) + if not local_cache then return nil, err else return true diff --git a/src/luarocks/admin/cmd/refresh_cache.tl b/src/luarocks/admin/cmd/refresh_cache.tl index 07480159..b0be9984 100644 --- a/src/luarocks/admin/cmd/refresh_cache.tl +++ b/src/luarocks/admin/cmd/refresh_cache.tl @@ -24,8 +24,9 @@ function refresh_cache.command(args: Args): boolean, string if not server then return nil, err end local download_url = cache.get_server_urls(server, upload_server) - local ok, err = cache.refresh_local_cache(download_url, cfg.upload_user, cfg.upload_password) - if not ok then + local local_cache: string + local_cache, err = cache.refresh_local_cache(download_url, cfg.upload_user, cfg.upload_password) + if not local_cache then return nil, err else return true diff --git a/src/luarocks/admin/cmd/remove.lua b/src/luarocks/admin/cmd/remove.lua index eee761fa..bef6ea0d 100644 --- a/src/luarocks/admin/cmd/remove.lua +++ b/src/luarocks/admin/cmd/remove.lua @@ -30,11 +30,11 @@ end local function remove_files_from_server(refresh, rockfiles, server, upload_server) - local download_url, login_url = cache.get_server_urls(server, upload_server) + local download_url, _login_url = cache.get_server_urls(server, upload_server) local at = fs.current_dir() local refresh_fn = refresh and cache.refresh_local_cache or cache.split_server_url - local local_cache, protocol, server_path, user, password = refresh_fn(download_url, cfg.upload_user, cfg.upload_password) + local local_cache, protocol, server_path, user, _password = refresh_fn(download_url, cfg.upload_user, cfg.upload_password) if not local_cache then return nil, protocol end @@ -58,7 +58,7 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve return nil, "No files removed." end - local ok, err = fs.change_dir(local_cache) + ok, err = fs.change_dir(local_cache) if not ok then return nil, err end util.printout("Updating manifest...") diff --git a/src/luarocks/admin/cmd/remove.tl b/src/luarocks/admin/cmd/remove.tl index 64b96ef2..0b1aa65b 100644 --- a/src/luarocks/admin/cmd/remove.tl +++ b/src/luarocks/admin/cmd/remove.tl @@ -30,11 +30,11 @@ end local function remove_files_from_server(refresh: boolean, rockfiles: {string}, server: string, upload_server: {string: string}): boolean, string - local download_url, login_url = cache.get_server_urls(server, upload_server) + local download_url, _login_url = cache.get_server_urls(server, upload_server) local at = fs.current_dir() local refresh_fn = refresh and cache.refresh_local_cache or cache.split_server_url - local local_cache, protocol, server_path, user, password = refresh_fn(download_url, cfg.upload_user, cfg.upload_password) + local local_cache, protocol, server_path, user, _password = refresh_fn(download_url, cfg.upload_user, cfg.upload_password) if not local_cache then return nil, protocol end @@ -58,7 +58,7 @@ local function remove_files_from_server(refresh: boolean, rockfiles: {string}, s return nil, "No files removed." end - local ok, err = fs.change_dir(local_cache) + ok, err = fs.change_dir(local_cache) if not ok then return nil, err end util.printout("Updating manifest...") @@ -89,7 +89,7 @@ end function admin_remove.command(args: Args): boolean, string local server, server_table, err = cache.get_upload_server(args.server) if not server then return nil, err end - return remove_files_from_server(not args.no_refresh, args.rocks, server, server_table) --! + return remove_files_from_server(not args.no_refresh, args.rocks, server, server_table) end diff --git a/src/luarocks/admin/index.lua b/src/luarocks/admin/index.lua index e2e2deff..c058697e 100644 --- a/src/luarocks/admin/index.lua +++ b/src/luarocks/admin/index.lua @@ -1,4 +1,4 @@ -local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local package = _tl_compat and _tl_compat.package or package; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table +local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table local index = {} @@ -115,7 +115,7 @@ function index.format_external_dependencies(rockspec) end if plats then for plat, entries in util.sortedpairs(plats) do - for name, desc in util.sortedpairs(entries) do + for name, _desc in util.sortedpairs(entries) do if not listed_set[name] then table.insert(deplist, name:lower() .. " (on " .. plat .. ")") end @@ -136,7 +136,7 @@ function index.make_index(repo) local out = io.open(dir.path(repo, "index.html"), "w") out:write(index_header) - for package, version_list in util.sortedpairs(manifest.repository) do + for pkg, version_list in util.sortedpairs(manifest.repository) do local latest_rockspec = nil local output = index_package_begin for version, data in util.sortedpairs(version_list, vers.compare_versions) do @@ -146,10 +146,10 @@ function index.make_index(repo) for _, item in ipairs(data) do local file if item.arch == 'rockspec' then - file = ("%s-%s.rockspec"):format(package, version) + file = ("%s-%s.rockspec"):format(pkg, version) if not latest_rockspec then latest_rockspec = file end else - file = ("%s-%s.%s.rock"):format(package, version, item.arch) + file = ("%s-%s.%s.rock"):format(pkg, version, item.arch) end table.insert(versions, '' .. item.arch .. '') end @@ -160,7 +160,7 @@ function index.make_index(repo) local rockspec = persist.load_into_table(dir.path(repo, latest_rockspec)) local descript = rockspec.description or {} local vars = { - anchor = package, + anchor = pkg, package = rockspec.package, original = rockspec.source.url, summary = descript.summary or "", @@ -173,8 +173,8 @@ function index.make_index(repo) vars.detailed = vars.detailed:gsub("(https?://[a-zA-Z0-9%.%%-_%+%[%]=%?&/$@;:]+)", '%1') output = output:gsub("$(%w+)", vars) else - output = output:gsub("$anchor", package) - output = output:gsub("$package", package) + output = output:gsub("$anchor", pkg) + output = output:gsub("$package", pkg) output = output:gsub("$(%w+)", "") end out:write(output) diff --git a/src/luarocks/admin/index.tl b/src/luarocks/admin/index.tl index 2cd47baf..c498932e 100644 --- a/src/luarocks/admin/index.tl +++ b/src/luarocks/admin/index.tl @@ -115,7 +115,7 @@ function index.format_external_dependencies(rockspec: Rockspec): string end if plats then for plat, entries in util.sortedpairs(plats) do - for name, desc in util.sortedpairs(entries) do + for name, _desc in util.sortedpairs(entries) do if not listed_set[name] then table.insert(deplist, name:lower() .. " (on "..plat..")") end @@ -136,7 +136,7 @@ function index.make_index(repo: string): boolean, string local out = io.open(dir.path(repo, "index.html"), "w") out:write(index_header) - for package, version_list in util.sortedpairs(manifest.repository) do + for pkg, version_list in util.sortedpairs(manifest.repository) do local latest_rockspec: string = nil local output = index_package_begin for version, data in util.sortedpairs(version_list, vers.compare_versions) do @@ -146,10 +146,10 @@ function index.make_index(repo: string): boolean, string for _, item in ipairs(data) do local file: string if item.arch == 'rockspec' then - file = ("%s-%s.rockspec"):format(package, version) + file = ("%s-%s.rockspec"):format(pkg, version) if not latest_rockspec then latest_rockspec = file end else - file = ("%s-%s.%s.rock"):format(package, version, item.arch) + file = ("%s-%s.%s.rock"):format(pkg, version, item.arch) end table.insert(versions, ''..item.arch..'') end @@ -160,7 +160,7 @@ function index.make_index(repo: string): boolean, string local rockspec = persist.load_into_table(dir.path(repo, latest_rockspec)) as Rockspec local descript = rockspec.description or {} local vars = { - anchor = package, + anchor = pkg, package = rockspec.package, original = rockspec.source.url, summary = descript.summary or "", @@ -173,8 +173,8 @@ function index.make_index(repo: string): boolean, string vars.detailed = vars.detailed:gsub("(https?://[a-zA-Z0-9%.%%-_%+%[%]=%?&/$@;:]+)", '%1') output = output:gsub("$(%w+)", vars) else - output = output:gsub("$anchor", package) - output = output:gsub("$package", package) + output = output:gsub("$anchor", pkg) + output = output:gsub("$package", pkg) output = output:gsub("$(%w+)", "") end out:write(output) diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 63082077..6b2d227f 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -69,7 +69,7 @@ do for patch, patchdata in util.sortedpairs(rockspec.build.patches) do util.printout("Applying patch " .. patch .. "...") local create_delete = rockspec:format_is_at_least("3.0") - local ok, err = fs.apply_patch(tostring(patch), patchdata, create_delete) + local ok, _err = fs.apply_patch(tostring(patch), patchdata, create_delete) if not ok then return nil, "Failed applying patch " .. patch end @@ -110,7 +110,7 @@ end local function process_dependencies(rockspec, opts, cwd) if not opts.build_only_deps then local ok, err, errcode = deps.check_external_deps(rockspec, "build") - if err then + if not ok then return nil, err, errcode end end @@ -141,7 +141,7 @@ local function process_dependencies(rockspec, opts, cwd) path.use_tree(cfg.root_dir) end - local ok, err, errcode = deps.fulfill_dependencies(rockspec, "build_dependencies", "all", opts.verify, deplock_dir) + local _ok, err, errcode = deps.fulfill_dependencies(rockspec, "build_dependencies", "all", opts.verify, deplock_dir) path.add_to_package_paths(cfg.root_dir) @@ -229,7 +229,7 @@ local function run_build_driver(rockspec, no_install) if cfg.accepted_build_types and not fun.contains(cfg.accepted_build_types, btype) then return nil, "This rockspec uses the '" .. btype .. "' build type, which is blocked by the 'accepted_build_types' setting in your LuaRocks configuration." end - local pok, driver_str = pcall(require, "luarocks.build." .. btype) + local _pok, driver_str = pcall(require, "luarocks.build." .. btype) if not (type(driver_str) == "table") then return nil, "Failed initializing build back-end for build type '" .. btype .. "': " .. driver_str else @@ -412,7 +412,7 @@ function build.build_rockspec(rockspec, opts, cwd) return name, version end - local dirs, err + local dirs local rollback if not opts.no_install then if repos.is_installed(name, version) then diff --git a/src/luarocks/build.tl b/src/luarocks/build.tl index 7fbe021f..9250e1dd 100644 --- a/src/luarocks/build.tl +++ b/src/luarocks/build.tl @@ -69,7 +69,7 @@ do for patch, patchdata in util.sortedpairs(rockspec.build.patches) do util.printout("Applying patch "..patch.."...") local create_delete = rockspec:format_is_at_least("3.0") - local ok, err = fs.apply_patch(tostring(patch), patchdata, create_delete) + local ok, _err = fs.apply_patch(tostring(patch), patchdata, create_delete) if not ok then return nil, "Failed applying patch "..patch end @@ -110,7 +110,7 @@ end local function process_dependencies(rockspec: Rockspec, opts: BOpts, cwd: string): boolean, string, string if not opts.build_only_deps then local ok, err, errcode = deps.check_external_deps(rockspec, "build") - if err then + if not ok then return nil, err, errcode end end @@ -141,7 +141,7 @@ local function process_dependencies(rockspec: Rockspec, opts: BOpts, cwd: string path.use_tree(cfg.root_dir as Tree) end - local ok, err, errcode = deps.fulfill_dependencies(rockspec, "build_dependencies", "all", opts.verify, deplock_dir) + local _ok, err, errcode = deps.fulfill_dependencies(rockspec, "build_dependencies", "all", opts.verify, deplock_dir) path.add_to_package_paths(cfg.root_dir) @@ -229,7 +229,7 @@ local function run_build_driver(rockspec: Rockspec, no_install: boolean): boolea if cfg.accepted_build_types and not fun.contains(cfg.accepted_build_types, btype) then return nil, "This rockspec uses the '"..btype.."' build type, which is blocked by the 'accepted_build_types' setting in your LuaRocks configuration." end - local pok, driver_str = pcall(require, "luarocks.build." .. btype) as (boolean, Builder | string) + local _pok, driver_str = pcall(require, "luarocks.build." .. btype) as (boolean, Builder | string) if not driver_str is Builder then return nil, "Failed initializing build back-end for build type '"..btype.."': "..driver_str else @@ -412,7 +412,7 @@ function build.build_rockspec(rockspec: Rockspec, opts: BOpts, cwd: string): str return name, version end - local dirs, err: InstallDirs, string + local dirs: InstallDirs local rollback: util.Fn if not opts.no_install then if repos.is_installed(name, version) then diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 24434fef..14812865 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -247,7 +247,7 @@ function builtin.run(rockspec, no_install) end return execute(variables.LD .. " " .. variables.LDFLAGS .. " " .. variables.LIBFLAG, "-o", library, _tl_table_unpack(extras)) end - compile_static_library = function(library, objects, libraries, libdirs, name) + compile_static_library = function(library, objects, _libraries, _libdirs, _name) local ok = execute(variables.AR, "rc", library, _tl_table_unpack(objects)) if ok then ok = execute(variables.RANLIB, library) @@ -256,7 +256,7 @@ function builtin.run(rockspec, no_install) end end - local ok, err + local ok, err, errcode local lua_modules = {} local lib_modules = {} local luadir = path.lua_dir(rockspec.name, rockspec.version) @@ -306,13 +306,13 @@ function builtin.run(rockspec, no_install) end if type(info) == "table" then if not checked_lua_h then - local ok, err, errcode = deps.check_lua_incdir(rockspec.variables) + ok, err, errcode = deps.check_lua_incdir(rockspec.variables) if not ok then return nil, err, errcode end if cfg.link_lua_explicitly then - local ok, err, errcode = deps.check_lua_libdir(rockspec.variables) + ok, err, errcode = deps.check_lua_libdir(rockspec.variables) if not ok then return nil, err, errcode end diff --git a/src/luarocks/build/builtin.tl b/src/luarocks/build/builtin.tl index 51d75900..b5a02f4c 100644 --- a/src/luarocks/build/builtin.tl +++ b/src/luarocks/build/builtin.tl @@ -247,7 +247,7 @@ function builtin.run(rockspec: Rockspec, no_install: boolean): boolean, string, end return execute(variables.LD.." "..variables.LDFLAGS.." "..variables.LIBFLAG, "-o", library, table.unpack(extras)) end - compile_static_library = function(library: string, objects: {string}, libraries: {string}, libdirs: {string}, name: string): boolean, string, string -- luacheck: ignore 211 + compile_static_library = function(library: string, objects: {string}, _libraries: {string}, _libdirs: {string}, _name: string): boolean, string, string local ok = execute(variables.AR, "rc", library, table.unpack(objects)) if ok then ok = execute(variables.RANLIB, library) @@ -256,7 +256,7 @@ function builtin.run(rockspec: Rockspec, no_install: boolean): boolean, string, end end - local ok, err: boolean, string + local ok, err, errcode: boolean, string, string local lua_modules = {} local lib_modules = {} local luadir = path.lua_dir(rockspec.name, rockspec.version) @@ -306,13 +306,13 @@ function builtin.run(rockspec: Rockspec, no_install: boolean): boolean, string, end if info is Module then if not checked_lua_h then - local ok, err, errcode = deps.check_lua_incdir(rockspec.variables) + ok, err, errcode = deps.check_lua_incdir(rockspec.variables) if not ok then return nil, err, errcode end if cfg.link_lua_explicitly then - local ok, err, errcode = deps.check_lua_libdir(rockspec.variables) + ok, err, errcode = deps.check_lua_libdir(rockspec.variables) if not ok then return nil, err, errcode end diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index e9c81a0f..90cf996b 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -385,45 +385,45 @@ local function use_to_fix_location(key, what) return buf end -local function get_config_text(cfg) +local function get_config_text(conf) local deps = require("luarocks.deps") - local libdir_ok = deps.check_lua_libdir(cfg.variables) - local incdir_ok = deps.check_lua_incdir(cfg.variables) - local lua_ok = cfg.variables.LUA and fs.exists(cfg.variables.LUA) + local libdir_ok = deps.check_lua_libdir(conf.variables) + local incdir_ok = deps.check_lua_incdir(conf.variables) + local lua_ok = conf.variables.LUA and fs.exists(conf.variables.LUA) local buf = "Configuration:\n" buf = buf .. " Lua:\n" - buf = buf .. " Version : " .. cfg.lua_version .. "\n" - if cfg.luajit_version then - buf = buf .. " LuaJIT : " .. cfg.luajit_version .. "\n" + buf = buf .. " Version : " .. conf.lua_version .. "\n" + if conf.luajit_version then + buf = buf .. " LuaJIT : " .. conf.luajit_version .. "\n" end - buf = buf .. " LUA : " .. show_status(cfg.variables.LUA, lua_ok, "interpreter not found") .. "\n" + buf = buf .. " LUA : " .. show_status(conf.variables.LUA, lua_ok, "interpreter not found") .. "\n" if not lua_ok then buf = buf .. use_to_fix_location("variables.LUA", lua_example) end - buf = buf .. " LUA_INCDIR : " .. show_status(cfg.variables.LUA_INCDIR, incdir_ok, "lua.h not found") .. "\n" + buf = buf .. " LUA_INCDIR : " .. show_status(conf.variables.LUA_INCDIR, incdir_ok, "lua.h not found") .. "\n" if lua_ok and not incdir_ok then buf = buf .. use_to_fix_location("variables.LUA_INCDIR") end - buf = buf .. " LUA_LIBDIR : " .. show_status(cfg.variables.LUA_LIBDIR, libdir_ok, "Lua library itself not found") .. "\n" + buf = buf .. " LUA_LIBDIR : " .. show_status(conf.variables.LUA_LIBDIR, libdir_ok, "Lua library itself not found") .. "\n" if lua_ok and not libdir_ok then buf = buf .. use_to_fix_location("variables.LUA_LIBDIR") end buf = buf .. "\n Configuration files:\n" - local conf = cfg.config_files - buf = buf .. " System : " .. show_status(fs.absolute_name(conf.system.file), conf.system.found) .. "\n" - if conf.user.file then - buf = buf .. " User : " .. show_status(fs.absolute_name(conf.user.file), conf.user.found) .. "\n" + local files = conf.config_files + buf = buf .. " System : " .. show_status(fs.absolute_name(files.system.file), files.system.found) .. "\n" + if files.user.file then + buf = buf .. " User : " .. show_status(fs.absolute_name(files.user.file), files.user.found) .. "\n" else buf = buf .. " User : disabled in this LuaRocks installation.\n" end - if conf.project then - buf = buf .. " Project : " .. show_status(fs.absolute_name(conf.project.file), conf.project.found) .. "\n" + if files.project then + buf = buf .. " Project : " .. show_status(fs.absolute_name(files.project.file), files.project.found) .. "\n" end buf = buf .. "\n Rocks trees in use: \n" - for _, tree in ipairs(cfg.rocks_trees) do + for _, tree in ipairs(conf.rocks_trees) do if type(tree) == "string" then buf = buf .. " " .. fs.absolute_name(tree) else @@ -604,14 +604,14 @@ function cmd.run_command(description, commands, external_namespace, ...) end end for i = last, 1, -1 do - local arg = args[i] - if arg:match("^[^-][^=]*=") then - local var, val = arg:match("^([A-Z_][A-Z0-9_]*)=(.*)") + local arg_i = args[i] + if arg_i:match("^[^-][^=]*=") then + local var, val = arg_i:match("^([A-Z_][A-Z0-9_]*)=(.*)") if val then cmdline_vars[var] = val table.remove(args, i) else - die("Invalid assignment: " .. arg) + die("Invalid assignment: " .. arg_i) end end end @@ -718,7 +718,8 @@ function cmd.run_command(description, commands, external_namespace, ...) die("Current directory does not exist. Please run LuaRocks from an existing directory.") end - local ok, err = process_tree_args(args, cfg.project_dir) + local ok + ok, err = process_tree_args(args, cfg.project_dir) if not ok then die(err) end @@ -769,7 +770,7 @@ function cmd.run_command(description, commands, external_namespace, ...) local lock if cmd_mod.needs_lock and cmd_mod.needs_lock(args) then - local ok, err = fs.check_command_permissions(args) + ok, err = fs.check_command_permissions(args) if not ok then die(err, cmd.errorcodes.PERMISSIONDENIED) end @@ -788,7 +789,9 @@ function cmd.run_command(description, commands, external_namespace, ...) end end - local call_ok, ok, err, exitcode = xpcall(function() + local call_ok + local exitcode + call_ok, ok, err, exitcode = xpcall(function() return cmd_mod.command(args) end, error_handler) diff --git a/src/luarocks/cmd.tl b/src/luarocks/cmd.tl index a3d2970f..6645e583 100644 --- a/src/luarocks/cmd.tl +++ b/src/luarocks/cmd.tl @@ -168,7 +168,7 @@ local function process_server_args(args: Args): boolean, string server[j] = dir.path(mirror, "dev") end end - end + end end if args.only_server then @@ -206,7 +206,7 @@ end -- @param message string: The error message. -- @param exitcode number: the exitcode to use local function die(message: string, exitcode?: integer) - assert(type(message) == "string", "bad error, expected string, got: " .. type(message)) --! + assert(type(message) == "string", "bad error, expected string, got: " .. type(message)) assert(exitcode == nil or type(exitcode) == "number", "bad error, expected number, got: " .. type(exitcode) .. " - " .. tostring(exitcode)) util.printerr("\nError: "..message) @@ -385,45 +385,45 @@ local function use_to_fix_location(key: string, what?: string): string return buf end -local function get_config_text(cfg: Config): string -- luacheck: ignore 431 +local function get_config_text(conf: Config): string local deps = require("luarocks.deps") - local libdir_ok = deps.check_lua_libdir(cfg.variables) - local incdir_ok = deps.check_lua_incdir(cfg.variables) - local lua_ok = cfg.variables.LUA and fs.exists(cfg.variables.LUA) + local libdir_ok = deps.check_lua_libdir(conf.variables) + local incdir_ok = deps.check_lua_incdir(conf.variables) + local lua_ok = conf.variables.LUA and fs.exists(conf.variables.LUA) local buf = "Configuration:\n" buf = buf.." Lua:\n" - buf = buf.." Version : "..cfg.lua_version.."\n" - if cfg.luajit_version then - buf = buf.." LuaJIT : "..cfg.luajit_version.."\n" + buf = buf.." Version : "..conf.lua_version.."\n" + if conf.luajit_version then + buf = buf.." LuaJIT : "..conf.luajit_version.."\n" end - buf = buf.." LUA : "..show_status(cfg.variables.LUA, lua_ok, "interpreter not found").."\n" + buf = buf.." LUA : "..show_status(conf.variables.LUA, lua_ok, "interpreter not found").."\n" if not lua_ok then buf = buf .. use_to_fix_location("variables.LUA", lua_example) end - buf = buf.." LUA_INCDIR : "..show_status(cfg.variables.LUA_INCDIR, incdir_ok, "lua.h not found").."\n" + buf = buf.." LUA_INCDIR : "..show_status(conf.variables.LUA_INCDIR, incdir_ok, "lua.h not found").."\n" if lua_ok and not incdir_ok then buf = buf .. use_to_fix_location("variables.LUA_INCDIR") end - buf = buf.." LUA_LIBDIR : "..show_status(cfg.variables.LUA_LIBDIR, libdir_ok, "Lua library itself not found").."\n" + buf = buf.." LUA_LIBDIR : "..show_status(conf.variables.LUA_LIBDIR, libdir_ok, "Lua library itself not found").."\n" if lua_ok and not libdir_ok then buf = buf .. use_to_fix_location("variables.LUA_LIBDIR") end buf = buf.."\n Configuration files:\n" - local conf = cfg.config_files - buf = buf.." System : "..show_status(fs.absolute_name(conf.system.file), conf.system.found).."\n" - if conf.user.file then - buf = buf.." User : "..show_status(fs.absolute_name(conf.user.file), conf.user.found).."\n" + local files = conf.config_files + buf = buf.." System : "..show_status(fs.absolute_name(files.system.file), files.system.found).."\n" + if files.user.file then + buf = buf.." User : "..show_status(fs.absolute_name(files.user.file), files.user.found).."\n" else buf = buf.." User : disabled in this LuaRocks installation.\n" end - if conf.project then - buf = buf.." Project : "..show_status(fs.absolute_name(conf.project.file), conf.project.found).."\n" + if files.project then + buf = buf.." Project : "..show_status(fs.absolute_name(files.project.file), files.project.found).."\n" end buf = buf.."\n Rocks trees in use: \n" - for _, tree in ipairs(cfg.rocks_trees) do + for _, tree in ipairs(conf.rocks_trees) do if tree is string then buf = buf.." "..fs.absolute_name(tree) else @@ -604,14 +604,14 @@ function cmd.run_command(description: string, commands: {string: string}, extern end end for i = last, 1, -1 do - local arg = args[i] - if arg:match("^[^-][^=]*=") then - local var, val = arg:match("^([A-Z_][A-Z0-9_]*)=(.*)") + local arg_i = args[i] + if arg_i:match("^[^-][^=]*=") then + local var, val = arg_i:match("^([A-Z_][A-Z0-9_]*)=(.*)") if val then cmdline_vars[var] = val table.remove(args, i) else - die("Invalid assignment: "..arg) + die("Invalid assignment: "..arg_i) end end end @@ -718,7 +718,8 @@ function cmd.run_command(description: string, commands: {string: string}, extern die("Current directory does not exist. Please run LuaRocks from an existing directory.") end - local ok, err = process_tree_args(args, cfg.project_dir) + local ok: boolean + ok, err = process_tree_args(args, cfg.project_dir) if not ok then die(err) end @@ -769,7 +770,7 @@ function cmd.run_command(description: string, commands: {string: string}, extern local lock: fs.Lock if cmd_mod.needs_lock and cmd_mod.needs_lock(args) then - local ok, err = fs.check_command_permissions(args) + ok, err = fs.check_command_permissions(args) if not ok then die(err, cmd.errorcodes.PERMISSIONDENIED) end @@ -788,7 +789,9 @@ function cmd.run_command(description: string, commands: {string: string}, extern end end - local call_ok, ok, err, exitcode = xpcall(function(): boolean, string, integer + local call_ok: boolean + local exitcode: integer + call_ok, ok, err, exitcode = xpcall(function(): boolean, string, integer return cmd_mod.command(args) end, error_handler) diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua index fb894c20..ee87d134 100644 --- a/src/luarocks/cmd/build.lua +++ b/src/luarocks/cmd/build.lua @@ -25,8 +25,6 @@ local repos = require("luarocks.repos") - - function cmd_build.add_to_parser(parser) local cmd = parser:command("build", "Build and install a rock, compiling its C parts if any.\n" .. "If the sources contain a luarocks.lock file, uses it as an authoritative source for " .. @@ -90,7 +88,6 @@ local function build_rock(rock_filename, opts) end local function do_build(name, namespace, version, opts) - local url, err if name:match("%.rockspec$") or name:match("%.rock$") then url = name @@ -112,7 +109,8 @@ local function do_build(name, namespace, version, opts) if url:match("%.rockspec$") then local cwd = fs.absolute_name(dir.path(".")) - local rockspec, err = fetch.load_rockspec(url, nil, opts.verify) + local rockspec + rockspec, err = fetch.load_rockspec(url, nil, opts.verify) if not rockspec then return nil, err end @@ -123,7 +121,8 @@ local function do_build(name, namespace, version, opts) opts.need_to_fetch = false end - local ok, err, errcode = build_rock(url, opts) + local ok, errcode + ok, err, errcode = build_rock(url, opts) if not ok then return nil, err, errcode end diff --git a/src/luarocks/cmd/build.tl b/src/luarocks/cmd/build.tl index c8d6a579..31e9bee9 100644 --- a/src/luarocks/cmd/build.tl +++ b/src/luarocks/cmd/build.tl @@ -22,9 +22,7 @@ local repos = require("luarocks.repos") local type Parser = require("luarocks.vendor.argparse").Parser local type Args = require("luarocks.core.types.args").Args - local type BOpts = require("luarocks.core.types.bopts").BOpts - local type Rockspec = require("luarocks.core.types.rockspec").Rockspec function cmd_build.add_to_parser(parser: Parser) @@ -90,7 +88,6 @@ local function build_rock(rock_filename: string, opts: BOpts): boolean, string, end local function do_build(name: string, namespace: string, version: string, opts: BOpts): string, string, string - local url, err: string, string if name:match("%.rockspec$") or name:match("%.rock$") then url = name @@ -112,7 +109,8 @@ local function do_build(name: string, namespace: string, version: string, opts: if url:match("%.rockspec$") then local cwd = fs.absolute_name(dir.path(".")) - local rockspec, err = fetch.load_rockspec(url, nil, opts.verify) + local rockspec: Rockspec + rockspec, err = fetch.load_rockspec(url, nil, opts.verify) if not rockspec then return nil, err end @@ -123,7 +121,8 @@ local function do_build(name: string, namespace: string, version: string, opts: opts.need_to_fetch = false end - local ok, err, errcode = build_rock(url, opts) + local ok, errcode: boolean, string + ok, err, errcode = build_rock(url, opts) if not ok then return nil, err, errcode end diff --git a/src/luarocks/cmd/config.lua b/src/luarocks/cmd/config.lua index b0b04913..71a09a92 100644 --- a/src/luarocks/cmd/config.lua +++ b/src/luarocks/cmd/config.lua @@ -197,7 +197,8 @@ local function write_entries(keys, scope, do_unset) end) end - local ok, err = fs.make_dir(dir.dir_name(file_name)) + local ok + ok, err = fs.make_dir(dir.dir_name(file_name)) if not ok then return nil, err end @@ -373,13 +374,13 @@ function config_cmd.command(args) if ok then if args.key == "variables.LUA_INCDIR" then - local ok = report_on_lua_incdir_config(args.value) - if not ok then + local found = report_on_lua_incdir_config(args.value) + if not found then warn_bad_c_config() end elseif args.key == "variables.LUA_LIBDIR" then - local ok = report_on_lua_libdir_config(args.value) - if not ok then + local found = report_on_lua_libdir_config(args.value) + if not found then warn_bad_c_config() end end diff --git a/src/luarocks/cmd/config.tl b/src/luarocks/cmd/config.tl index 53e3be5e..cdda3fb9 100644 --- a/src/luarocks/cmd/config.tl +++ b/src/luarocks/cmd/config.tl @@ -150,7 +150,7 @@ end local function infer_type(var: string): string local typ: string - traverse_varstring(var, cfg as PersistableTable, function(t: PersistableTable, k: string): boolean, string --! + traverse_varstring(var, cfg as PersistableTable, function(t: PersistableTable, k: string): boolean, string if t[k] then typ = type(t[k]) end @@ -197,7 +197,8 @@ local function write_entries(keys: {string: string}, scope: string, do_unset: bo end) end - local ok, err = fs.make_dir(dir.dir_name(file_name)) + local ok: boolean + ok, err = fs.make_dir(dir.dir_name(file_name)) if not ok then return nil, err end @@ -373,13 +374,13 @@ function config_cmd.command(args: Args): boolean, string if ok then if args.key == "variables.LUA_INCDIR" then - local ok = report_on_lua_incdir_config(args.value) - if not ok then + local found = report_on_lua_incdir_config(args.value) + if not found then warn_bad_c_config() end elseif args.key == "variables.LUA_LIBDIR" then - local ok = report_on_lua_libdir_config(args.value) - if not ok then + local found = report_on_lua_libdir_config(args.value) + if not found then warn_bad_c_config() end end diff --git a/src/luarocks/cmd/doc.lua b/src/luarocks/cmd/doc.lua index 1389d80c..87ac24ca 100644 --- a/src/luarocks/cmd/doc.lua +++ b/src/luarocks/cmd/doc.lua @@ -17,6 +17,7 @@ local download = require("luarocks.download") + function doc.add_to_parser(parser) local cmd = parser:command("doc", "Show documentation for an installed rock.\n\n" .. "Without any flags, tries to load the documentation using a series of heuristics.\n" .. @@ -45,17 +46,26 @@ local function show_homepage(homepage, name, namespace, version) end local function try_to_open_homepage(name, namespace, version) - local temp_dir, err = fs.make_temp_dir("doc-" .. name .. "-" .. (version or "")) + local temp_dir, err + temp_dir, err = fs.make_temp_dir("doc-" .. name .. "-" .. (version or "")) if not temp_dir then return nil, "Failed creating temporary directory: " .. err end + util.schedule_function(fs.delete, temp_dir) - local ok, err = fs.change_dir(temp_dir) + + local ok + ok, err = fs.change_dir(temp_dir) if not ok then return nil, err end - local filename, err = download.download_file("rockspec", name, namespace, version) + + local filename + filename, err = download.download_file("rockspec", name, namespace, version) if not filename then return nil, err end - local rockspec, err = fetch.load_local_rockspec(filename) + + local rockspec + rockspec, err = fetch.load_local_rockspec(filename) if not rockspec then return nil, err end + fs.pop_dir() local descript = rockspec.description or {} return show_homepage(descript.homepage, name, namespace, version) diff --git a/src/luarocks/cmd/doc.tl b/src/luarocks/cmd/doc.tl index 37eb2518..9e7bee2a 100644 --- a/src/luarocks/cmd/doc.tl +++ b/src/luarocks/cmd/doc.tl @@ -16,6 +16,7 @@ local download = require("luarocks.download") local type Parser = require("luarocks.vendor.argparse").Parser local type Args = require("luarocks.core.types.args").Args +local type Rockspec = require("luarocks.core.types.rockspec").Rockspec function doc.add_to_parser(parser: Parser) local cmd = parser:command("doc", "Show documentation for an installed rock.\n\n".. @@ -45,17 +46,26 @@ local function show_homepage(homepage: string, name: string, namespace: string, end local function try_to_open_homepage(name: string, namespace: string, version: string): boolean, string - local temp_dir, err = fs.make_temp_dir("doc-"..name.."-"..(version or "")) + local temp_dir, err: string, string + temp_dir, err = fs.make_temp_dir("doc-"..name.."-"..(version or "")) if not temp_dir then return nil, "Failed creating temporary directory: "..err end + util.schedule_function(fs.delete, temp_dir) - local ok, err = fs.change_dir(temp_dir) + + local ok: boolean + ok, err = fs.change_dir(temp_dir) if not ok then return nil, err end - local filename, err = download.download_file("rockspec", name, namespace, version) + + local filename: string + filename, err = download.download_file("rockspec", name, namespace, version) if not filename then return nil, err end - local rockspec, err = fetch.load_local_rockspec(filename) + + local rockspec: Rockspec + rockspec, err = fetch.load_local_rockspec(filename) if not rockspec then return nil, err end + fs.pop_dir() local descript = rockspec.description or {} return show_homepage(descript.homepage, name, namespace, version) diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.lua index 9b124974..a152b885 100644 --- a/src/luarocks/cmd/init.lua +++ b/src/luarocks/cmd/init.lua @@ -154,7 +154,7 @@ function init.command(args) if not has_rockspec then args.version = args.version or "dev" args.location = pwd - local ok, err = write_rockspec.command(args) + ok, err = write_rockspec.command(args) if not ok then util.printerr(err) end @@ -185,7 +185,8 @@ function init.command(args) fs.delete(fs.absolute_name(config_file)) end - local config_tbl, err = persist.load_config_file_if_basic(config_file, cfg) + local config_tbl + config_tbl, err = persist.load_config_file_if_basic(config_file, cfg) if config_tbl then local varnames = { "LUA_DIR", @@ -200,7 +201,7 @@ function init.command(args) (config_tbl.variables)[varname] = cfg.variables[varname] end end - local ok, err = persist.save_from_table(config_file, config_tbl) + ok, err = persist.save_from_table(config_file, config_tbl) if ok then util.printout("Wrote " .. config_file) else diff --git a/src/luarocks/cmd/init.tl b/src/luarocks/cmd/init.tl index fcd49422..313c6df9 100644 --- a/src/luarocks/cmd/init.tl +++ b/src/luarocks/cmd/init.tl @@ -154,7 +154,7 @@ function init.command(args: Args): boolean, string if not has_rockspec then args.version = args.version or "dev" args.location = pwd - local ok, err = write_rockspec.command(args) + ok, err = write_rockspec.command(args) if not ok then util.printerr(err) end @@ -185,7 +185,8 @@ function init.command(args: Args): boolean, string fs.delete(fs.absolute_name(config_file)) end - local config_tbl, err = persist.load_config_file_if_basic(config_file, cfg) + local config_tbl: PersistableTable + config_tbl, err = persist.load_config_file_if_basic(config_file, cfg) if config_tbl then local varnames = { "LUA_DIR", @@ -200,7 +201,7 @@ function init.command(args: Args): boolean, string (config_tbl.variables as PersistableTable)[varname] = cfg.variables[varname] end end - local ok, err = persist.save_from_table(config_file, config_tbl) + ok, err = persist.save_from_table(config_file, config_tbl) if ok then util.printout("Wrote " .. config_file) else diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index e582f6e1..28b1c888 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua @@ -23,7 +23,6 @@ local cfg = require("luarocks.core.cfg") - function install.add_to_parser(parser) local cmd = parser:command("install", "Install a rock.", util.see_also()) @@ -97,11 +96,15 @@ function install.install_binary_rock(rock_file, opts) fs.delete(install_dir) fs.remove_dir_if_empty(path.versions_dir(name)) end) - local ok - local oks, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) - if not oks then return nil, err, errcode end - local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) + local ok, err, errcode + + local filename + filename, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) + if not filename then return nil, err, errcode end + + local rockspec + rockspec, err, errcode = fetch.load_rockspec(path.rockspec_file(name, version)) if err then return nil, "Failed loading rockspec for installed package: " .. err, errcode end @@ -158,7 +161,8 @@ function install.install_binary_rock_deps(rock_file, opts) local oks, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) if not oks then return nil, err, errcode end - local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) + local rockspec + rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) if err then return nil, "Failed loading rockspec for installed package: " .. err, errcode end diff --git a/src/luarocks/cmd/install.tl b/src/luarocks/cmd/install.tl index 943afdba..6c472768 100644 --- a/src/luarocks/cmd/install.tl +++ b/src/luarocks/cmd/install.tl @@ -20,9 +20,8 @@ local cfg = require("luarocks.core.cfg") local type Parser = require("luarocks.vendor.argparse").Parser local type Args = require("luarocks.core.types.args").Args - - local type IOpts = require("luarocks.core.types.installs").IOpts +local type Rockspec = require("luarocks.core.types.rockspec").Rockspec function install.add_to_parser(parser: Parser) local cmd = parser:command("install", "Install a rock.", util.see_also()) -- luacheck: ignore 431 @@ -97,13 +96,17 @@ function install.install_binary_rock(rock_file: string, opts: IOpts): string, st fs.delete(install_dir) fs.remove_dir_if_empty(path.versions_dir(name)) end) - local ok: boolean - local oks, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) - if not oks then return nil, err, errcode end - local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) + local ok, err, errcode: boolean, string, string + + local filename: string + filename, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) + if not filename then return nil, err, errcode end + + local rockspec: Rockspec + rockspec, err, errcode = fetch.load_rockspec(path.rockspec_file(name, version)) if err then - return nil, "Failed loading rockspec for installed package: "..err, errcode + return nil, "Failed loading rockspec for installed package: " .. err, errcode end if opts.deps_mode ~= "none" then @@ -158,7 +161,8 @@ function install.install_binary_rock_deps(rock_file: string, opts: IOpts): strin local oks, err, errcode = fetch.fetch_and_unpack_rock(rock_file, install_dir, opts.verify) if not oks then return nil, err, errcode end - local rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) + local rockspec: Rockspec + rockspec, err = fetch.load_rockspec(path.rockspec_file(name, version)) if err then return nil, "Failed loading rockspec for installed package: "..err, errcode end diff --git a/src/luarocks/cmd/make.lua b/src/luarocks/cmd/make.lua index e8a52906..161ec0ac 100644 --- a/src/luarocks/cmd/make.lua +++ b/src/luarocks/cmd/make.lua @@ -99,7 +99,7 @@ function make.command(args) end local cwd = fs.absolute_name(dir.path(".")) - local rockspec, err, errcode = fetch.load_rockspec(rockspec_filename) + local rockspec, err = fetch.load_rockspec(rockspec_filename) if not rockspec then return nil, err end @@ -141,9 +141,9 @@ function make.command(args) return name, version end) else - local ok, err = build.build_rockspec(rockspec, opts, cwd) - if not ok then return nil, err end - name, version = ok, err + name, err = build.build_rockspec(rockspec, opts, cwd) + if not name then return nil, err end + version = err if opts.build_only_deps then util.printout("Stopping after installing dependencies for " .. name .. " " .. version) @@ -156,7 +156,8 @@ function make.command(args) end if (not args.keep) and not cfg.keep_other_versions then - local ok, err, warn = remove.remove_other_versions(name, version, args.force, args.force_fast) + local ok, warn + ok, err, warn = remove.remove_other_versions(name, version, args.force, args.force_fast) if not ok then return nil, err elseif warn then diff --git a/src/luarocks/cmd/make.tl b/src/luarocks/cmd/make.tl index 13b1d66b..fc467b31 100644 --- a/src/luarocks/cmd/make.tl +++ b/src/luarocks/cmd/make.tl @@ -99,7 +99,7 @@ function make.command(args: Args): boolean, string end local cwd = fs.absolute_name(dir.path(".")) - local rockspec, err, errcode = fetch.load_rockspec(rockspec_filename) + local rockspec, err = fetch.load_rockspec(rockspec_filename) if not rockspec then return nil, err end @@ -141,9 +141,9 @@ function make.command(args: Args): boolean, string return name, version end) else - local ok, err = build.build_rockspec(rockspec, opts, cwd) - if not ok then return nil, err end - name, version = ok, err -- luacheck: ignore 421 + name, err = build.build_rockspec(rockspec, opts, cwd) + if not name then return nil, err end + version = err if opts.build_only_deps then util.printout("Stopping after installing dependencies for " ..name.." "..version) @@ -156,7 +156,8 @@ function make.command(args: Args): boolean, string end if (not args.keep) and not cfg.keep_other_versions then - local ok, err, warn = remove.remove_other_versions(name, version, args.force, args.force_fast) + local ok, warn: boolean, string + ok, err, warn = remove.remove_other_versions(name, version, args.force, args.force_fast) if not ok then return nil, err elseif warn then diff --git a/src/luarocks/cmd/new_version.lua b/src/luarocks/cmd/new_version.lua index ea70a874..2d8d2365 100644 --- a/src/luarocks/cmd/new_version.lua +++ b/src/luarocks/cmd/new_version.lua @@ -78,6 +78,7 @@ end + local function check_url_and_update_md5(out_rs, invalid_is_error) local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-" .. out_rs.package) if not file then @@ -85,7 +86,7 @@ local function check_url_and_update_md5(out_rs, invalid_is_error) return nil, "invalid URL - " .. temp_dir end util.warning("invalid URL - " .. temp_dir) - return true, false + return true, nil, false end do local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, out_rs.source.url, out_rs.source.dir) @@ -106,15 +107,16 @@ local function check_url_and_update_md5(out_rs, invalid_is_error) end local old_md5 = out_rs.source.md5 out_rs.source.md5 = new_md5 - return true, new_md5 ~= old_md5 + return true, nil, new_md5 ~= old_md5 else util.printout("File successfully downloaded.") - return true, false + return true, nil, false end end end local function update_source_section(out_rs, url, tag, old_ver, new_ver) + local ok, err, md5_changed if tag then out_rs.source.tag = tag end @@ -123,7 +125,7 @@ local function update_source_section(out_rs, url, tag, old_ver, new_ver) return check_url_and_update_md5(out_rs) end if new_ver == old_ver then - return true + return true, nil, false end if out_rs.source.dir then try_replace(out_rs.source, "dir", old_ver, new_ver) @@ -134,24 +136,25 @@ local function update_source_section(out_rs, url, tag, old_ver, new_ver) local old_url = out_rs.source.url if try_replace(out_rs.source, "url", old_ver, new_ver) then - local ok, md5_changed = check_url_and_update_md5(out_rs, true) + ok, err, md5_changed = check_url_and_update_md5(out_rs, true) if ok then - return ok, md5_changed + return ok, nil, md5_changed end out_rs.source.url = old_url end if tag or try_replace(out_rs.source, "tag", old_ver, new_ver) then - return true + return true, nil, false end - local ok, md5_changed = check_url_and_update_md5(out_rs) + + ok, err, md5_changed = check_url_and_update_md5(out_rs) if not ok then - return nil, md5_changed + return nil, err end if md5_changed then util.warning("URL is the same, but MD5 has changed. Old rockspec is broken.") end - return true + return true, nil, true end function new_version.command(args) @@ -176,7 +179,8 @@ function new_version.command(args) end end - local valid_rs, err = fetch.load_rockspec(filename) + local valid_rs + valid_rs, err = fetch.load_rockspec(filename) if not valid_rs then return nil, err end @@ -206,11 +210,13 @@ function new_version.command(args) end local new_rockver = new_ver:gsub("-", "") - local out_rs, err = persist.load_into_table(filename), string + local out_rs + out_rs, err = persist.load_into_table(filename) local out_name = out_rs.package:lower() out_rs.version = new_rockver .. "-" .. tostring(new_rev) - local ok, err = update_source_section(out_rs, args.new_url, args.tag, old_ver, new_ver) + local ok + ok, err = update_source_section(out_rs, args.new_url, args.tag, old_ver, new_ver) if not ok then return nil, err end if out_rs.build and out_rs.build.type == "module" then @@ -226,7 +232,8 @@ function new_version.command(args) util.printout("Wrote " .. out_filename) - local valid_out_rs, err = fetch.load_local_rockspec(out_filename) + local valid_out_rs + valid_out_rs, err = fetch.load_local_rockspec(out_filename) if not valid_out_rs then return nil, "Failed loading generated rockspec: " .. err end diff --git a/src/luarocks/cmd/new_version.tl b/src/luarocks/cmd/new_version.tl index d5da0e86..d929376b 100644 --- a/src/luarocks/cmd/new_version.tl +++ b/src/luarocks/cmd/new_version.tl @@ -76,16 +76,17 @@ end -- Try to download source file using URL from a rockspec. -- If it specified MD5, update it. --- @return (true, false) if MD5 was not specified or it stayed same, --- (true, true) if MD5 changed, (nil, string) on error. -local function check_url_and_update_md5(out_rs: Rockspec, invalid_is_error?: boolean): boolean, string | boolean --! +-- @return true if no errors ocurred +-- @return an error message in case of errors +-- @return if no errors, a true boolean if the MD5 changed. +local function check_url_and_update_md5(out_rs: Rockspec, invalid_is_error?: boolean): boolean, string, boolean local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_rs.package) if not file then if invalid_is_error then return nil, "invalid URL - "..temp_dir end util.warning("invalid URL - "..temp_dir) - return true, false + return true, nil, false end do local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, out_rs.source.url, out_rs.source.dir) @@ -106,15 +107,16 @@ local function check_url_and_update_md5(out_rs: Rockspec, invalid_is_error?: boo end local old_md5 = out_rs.source.md5 out_rs.source.md5 = new_md5 - return true, new_md5 ~= old_md5 + return true, nil, new_md5 ~= old_md5 else util.printout("File successfully downloaded.") - return true, false + return true, nil, false end end end -local function update_source_section(out_rs: Rockspec, url: string, tag: string, old_ver: string, new_ver: string): boolean, string | boolean +local function update_source_section(out_rs: Rockspec, url: string, tag: string, old_ver: string, new_ver: string): boolean, string, boolean + local ok, err, md5_changed: boolean, string, boolean if tag then out_rs.source.tag = tag end @@ -123,7 +125,7 @@ local function update_source_section(out_rs: Rockspec, url: string, tag: string, return check_url_and_update_md5(out_rs) end if new_ver == old_ver then - return true + return true, nil, false end if out_rs.source.dir then try_replace(out_rs.source as {string: string}, "dir", old_ver, new_ver) @@ -134,24 +136,25 @@ local function update_source_section(out_rs: Rockspec, url: string, tag: string, local old_url = out_rs.source.url if try_replace(out_rs.source as {string: string}, "url", old_ver, new_ver) then - local ok, md5_changed = check_url_and_update_md5(out_rs, true) + ok, err, md5_changed = check_url_and_update_md5(out_rs, true) if ok then - return ok, md5_changed + return ok, nil, md5_changed end out_rs.source.url = old_url end if tag or try_replace(out_rs.source as {string: string}, "tag", old_ver, new_ver) then - return true + return true, nil, false end + -- Couldn't replace anything significant, use the old URL. - local ok, md5_changed = check_url_and_update_md5(out_rs) + ok, err, md5_changed = check_url_and_update_md5(out_rs) if not ok then - return nil, md5_changed + return nil, err end if md5_changed then util.warning("URL is the same, but MD5 has changed. Old rockspec is broken.") end - return true + return true, nil, true end function new_version.command(args: Args): boolean, string | boolean @@ -176,7 +179,8 @@ function new_version.command(args: Args): boolean, string | boolean end end - local valid_rs, err = fetch.load_rockspec(filename) + local valid_rs: Rockspec + valid_rs, err = fetch.load_rockspec(filename) if not valid_rs then return nil, err end @@ -206,11 +210,13 @@ function new_version.command(args: Args): boolean, string | boolean end local new_rockver = new_ver:gsub("-", "") - local out_rs, err = persist.load_into_table(filename) as Rockspec, string + local out_rs: Rockspec + out_rs, err = persist.load_into_table(filename) as (Rockspec, string) local out_name = out_rs.package:lower() out_rs.version = new_rockver.."-"..tostring(new_rev) - local ok, err = update_source_section(out_rs, args.new_url, args.tag, old_ver, new_ver) + local ok: boolean + ok, err = update_source_section(out_rs, args.new_url, args.tag, old_ver, new_ver) if not ok then return nil, err end if out_rs.build and out_rs.build.type == "module" then @@ -226,7 +232,8 @@ function new_version.command(args: Args): boolean, string | boolean util.printout("Wrote "..out_filename) - local valid_out_rs, err = fetch.load_local_rockspec(out_filename) + local valid_out_rs: Rockspec + valid_out_rs, err = fetch.load_local_rockspec(out_filename) if not valid_out_rs then return nil, "Failed loading generated rockspec: "..err end diff --git a/src/luarocks/cmd/purge.lua b/src/luarocks/cmd/purge.lua index b7d28f82..f84a15f2 100644 --- a/src/luarocks/cmd/purge.lua +++ b/src/luarocks/cmd/purge.lua @@ -1,4 +1,4 @@ -local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local package = _tl_compat and _tl_compat.package or package + local purge = {} @@ -51,11 +51,11 @@ function purge.command(args) sort = vers.compare_versions end - for package, versions in util.sortedpairs(results) do + for pkg, versions in util.sortedpairs(results) do for version, _ in util.sortedpairs(versions, sort) do if args.old_versions then - util.printout("Keeping " .. package .. " " .. version .. "...") - local ok, err, warn = remove.remove_other_versions(package, version, args.force, args.force_fast) + util.printout("Keeping " .. pkg .. " " .. version .. "...") + local ok, err, warn = remove.remove_other_versions(pkg, version, args.force, args.force_fast) if not ok then util.printerr(err) elseif warn then @@ -63,8 +63,8 @@ function purge.command(args) end break else - util.printout("Removing " .. package .. " " .. version .. "...") - local ok, err = repo_writer.delete_version(package, version, "none", true) + util.printout("Removing " .. pkg .. " " .. version .. "...") + local ok, err = repo_writer.delete_version(pkg, version, "none", true) if not ok then util.printerr(err) end diff --git a/src/luarocks/cmd/purge.tl b/src/luarocks/cmd/purge.tl index 9d8eacc1..2801f357 100644 --- a/src/luarocks/cmd/purge.tl +++ b/src/luarocks/cmd/purge.tl @@ -51,11 +51,11 @@ function purge.command(args: Args): boolean, string sort = vers.compare_versions end - for package, versions in util.sortedpairs(results) do + for pkg, versions in util.sortedpairs(results) do for version, _ in util.sortedpairs(versions, sort) do if args.old_versions then - util.printout("Keeping "..package.." "..version.."...") - local ok, err, warn = remove.remove_other_versions(package, version, args.force, args.force_fast) + util.printout("Keeping "..pkg.." "..version.."...") + local ok, err, warn = remove.remove_other_versions(pkg, version, args.force, args.force_fast) if not ok then util.printerr(err) elseif warn then @@ -63,8 +63,8 @@ function purge.command(args: Args): boolean, string end break else - util.printout("Removing "..package.." "..version.."...") - local ok, err = repo_writer.delete_version(package, version, "none", true) + util.printout("Removing "..pkg.." "..version.."...") + local ok, err = repo_writer.delete_version(pkg, version, "none", true) if not ok then util.printerr(err) end diff --git a/src/luarocks/cmd/show.lua b/src/luarocks/cmd/show.lua index 7f9ca9c6..5022e288 100644 --- a/src/luarocks/cmd/show.lua +++ b/src/luarocks/cmd/show.lua @@ -307,8 +307,10 @@ function show.command(args) if not rockspec then return nil, err end local descript = rockspec.description or {} - local manifest, err = manif.load_manifest(repo_url) - if not manifest then return nil, err end + + local manifest, manifest_err = manif.load_manifest(repo_url) + if not manifest then return nil, manifest_err end + local minfo = manifest.repository[name][version][1] if args.rock_tree then util.printout(tree) diff --git a/src/luarocks/cmd/show.tl b/src/luarocks/cmd/show.tl index 6063179a..56d70277 100644 --- a/src/luarocks/cmd/show.tl +++ b/src/luarocks/cmd/show.tl @@ -307,8 +307,10 @@ function show.command(args: Args): boolean, string if not rockspec then return nil,err end local descript = rockspec.description or {} - local manifest, err = manif.load_manifest(repo_url) - if not manifest then return nil,err end + + local manifest, manifest_err = manif.load_manifest(repo_url) + if not manifest then return nil, manifest_err end + local minfo = manifest.repository[name][version][1] if args.rock_tree then util.printout(tree) diff --git a/src/luarocks/cmd/test.tl b/src/luarocks/cmd/test.tl index b1189d47..a258e4a3 100644 --- a/src/luarocks/cmd/test.tl +++ b/src/luarocks/cmd/test.tl @@ -35,7 +35,7 @@ to separate LuaRocks arguments from test suite arguments.]], :argname("") end -function cmd_test.command(args: Args): boolean, string, string --! +function cmd_test.command(args: Args): boolean, string, string if args.rockspec and args.rockspec:match("rockspec$") then return test.run_test_suite(args.rockspec, args.test_type, args.args, args.prepare) end diff --git a/src/luarocks/cmd/unpack.lua b/src/luarocks/cmd/unpack.lua index 5a1ae799..aa136c32 100644 --- a/src/luarocks/cmd/unpack.lua +++ b/src/luarocks/cmd/unpack.lua @@ -47,7 +47,8 @@ local function unpack_rockspec(rockspec_file, dir_name) if not rockspec then return nil, "Failed loading rockspec " .. rockspec_file .. ": " .. err end - local ok, err = fs.change_dir(dir_name) + local ok + ok, err = fs.change_dir(dir_name) if not ok then return nil, err end local filename, sources_dir = fetch.fetch_sources(rockspec, true, ".") if not filename then @@ -78,10 +79,13 @@ local function unpack_rock(rock_file, dir_name, kind) ok, err = fs.change_dir(dir_name) if not ok then return nil, err end local rockspec_file = dir_name .. ".rockspec" - local rockspec, err = fetch.load_rockspec(rockspec_file) + + local rockspec + rockspec, err = fetch.load_rockspec(rockspec_file) if not rockspec then return nil, "Failed loading rockspec " .. rockspec_file .. ": " .. err end + if kind == "src" then if rockspec.source.file then ok, err = fs.unpack_archive(rockspec.source.file) diff --git a/src/luarocks/cmd/unpack.tl b/src/luarocks/cmd/unpack.tl index 0e168785..6d05ecde 100644 --- a/src/luarocks/cmd/unpack.tl +++ b/src/luarocks/cmd/unpack.tl @@ -47,7 +47,8 @@ local function unpack_rockspec(rockspec_file: string, dir_name: string): Rockspe if not rockspec then return nil, "Failed loading rockspec "..rockspec_file..": "..err end - local ok, err = fs.change_dir(dir_name) + local ok: boolean + ok, err = fs.change_dir(dir_name) if not ok then return nil, err end local filename, sources_dir = fetch.fetch_sources(rockspec, true, ".") if not filename then @@ -78,10 +79,13 @@ local function unpack_rock(rock_file: string, dir_name: string, kind: string): R ok, err = fs.change_dir(dir_name) if not ok then return nil, err end local rockspec_file = dir_name..".rockspec" - local rockspec, err = fetch.load_rockspec(rockspec_file) + + local rockspec: Rockspec + rockspec, err = fetch.load_rockspec(rockspec_file) if not rockspec then return nil, "Failed loading rockspec "..rockspec_file..": "..err end + if kind == "src" then if rockspec.source.file then ok, err = fs.unpack_archive(rockspec.source.file) diff --git a/src/luarocks/cmd/upload.lua b/src/luarocks/cmd/upload.lua index 70a1f9b9..cc65de0b 100644 --- a/src/luarocks/cmd/upload.lua +++ b/src/luarocks/cmd/upload.lua @@ -24,6 +24,7 @@ local Api = require("luarocks.upload.api") + function upload.add_to_parser(parser) local cmd = parser:command("upload", "Pack a source rock file (.src.rock extension) " .. "and upload it and the rockspec to the public rocks repository.", util.see_also()): @@ -60,13 +61,16 @@ function upload.command(args) api.debug = true end - local rockspec, err, errcode = fetch.load_rockspec(args.rockspec) + local rockspec + local errcode + rockspec, err, errcode = fetch.load_rockspec(args.rockspec) if err then return nil, err, errcode end util.printout("Sending " .. tostring(args.rockspec) .. " ...") - local res, err = api:method("check_rockspec", { + local res + res, err = api:method("check_rockspec", { package = rockspec.package, version = rockspec.version, }) diff --git a/src/luarocks/cmd/upload.tl b/src/luarocks/cmd/upload.tl index df544d13..a222a50c 100644 --- a/src/luarocks/cmd/upload.tl +++ b/src/luarocks/cmd/upload.tl @@ -23,6 +23,7 @@ local type Response = upload.Response local type Parser = require("luarocks.vendor.argparse").Parser local type Args = require("luarocks.core.types.args").Args +local type Rockspec = require("luarocks.core.types.rockspec").Rockspec function upload.add_to_parser(parser: Parser) local cmd = parser:command("upload", "Pack a source rock file (.src.rock extension) ".. @@ -60,13 +61,16 @@ function upload.command(args: Args): boolean, string, string api.debug = true end - local rockspec, err, errcode = fetch.load_rockspec(args.rockspec) + local rockspec: Rockspec + local errcode: string + rockspec, err, errcode = fetch.load_rockspec(args.rockspec) if err then return nil, err, errcode end util.printout("Sending " .. tostring(args.rockspec) .. " ...") - local res, err = api:method("check_rockspec", { + local res: Response + res, err = api:method("check_rockspec", { package = rockspec.package, version = rockspec.version }) as (Response, string) diff --git a/src/luarocks/cmd/write_rockspec.lua b/src/luarocks/cmd/write_rockspec.lua index 156339b8..b84c2803 100644 --- a/src/luarocks/cmd/write_rockspec.lua +++ b/src/luarocks/cmd/write_rockspec.lua @@ -386,7 +386,8 @@ function write_rockspec.command(args) end end - local ok, err = fs.change_dir(local_dir) + local ok + ok, err = fs.change_dir(local_dir) if not ok then return nil, "Failed reaching files from project - error entering directory " .. local_dir end if not (args.summary and args.detailed) then diff --git a/src/luarocks/cmd/write_rockspec.tl b/src/luarocks/cmd/write_rockspec.tl index 6ece30da..7354a683 100644 --- a/src/luarocks/cmd/write_rockspec.tl +++ b/src/luarocks/cmd/write_rockspec.tl @@ -386,7 +386,8 @@ function write_rockspec.command(args: Args): boolean, string end end - local ok, err = fs.change_dir(local_dir) + local ok: boolean + ok, err = fs.change_dir(local_dir) if not ok then return nil, "Failed reaching files from project - error entering directory "..local_dir end if not (args.summary and args.detailed) then diff --git a/src/luarocks/core/types/args.d.tl b/src/luarocks/core/types/args.d.tl index d2aca6fc..510855dd 100644 --- a/src/luarocks/core/types/args.d.tl +++ b/src/luarocks/core/types/args.d.tl @@ -3,18 +3,18 @@ local record args tree: string global: boolean deps_mode: string - ["local"]: boolean --! + ["local"]: boolean project_tree: string server: string dev: boolean - only_server: string --! + only_server: string verbose: string lua_version: string lua_dir: string no_project: boolean input: {string} nodeps: boolean - timeout: number --! + timeout: number command: string key: string value: string @@ -26,8 +26,8 @@ local record args pack_binary_rock: boolean only_deps: boolean branch: string - verify: boolean --! - check_lua_versions: boolean --! + verify: boolean + check_lua_versions: boolean pin: boolean no_install: boolean sign: boolean @@ -48,7 +48,7 @@ local record args json: boolean home: boolean porcelain: boolean - list: boolean --! + list: boolean name: string all: boolean source: string @@ -109,4 +109,4 @@ local record args end end -return args \ No newline at end of file +return args diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index 068ade96..b82cbe41 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua @@ -34,13 +34,13 @@ function download.download_all(arch, name, namespace, version) local has_result = false local all_ok = true local any_err = "" - for name, result in pairs(results) do - for version, items in pairs(result) do + for rname, result in pairs(results) do + for rversion, items in pairs(result) do for _, item in ipairs(items) do if item.arch ~= "installed" then has_result = true - local filename = path.make_url(item.repo, name, version, item.arch) + local filename = path.make_url(item.repo, rname, rversion, item.arch) local ok, err = get_file(filename) if not ok then all_ok = false diff --git a/src/luarocks/download.tl b/src/luarocks/download.tl index f993da0f..9a7076f7 100644 --- a/src/luarocks/download.tl +++ b/src/luarocks/download.tl @@ -34,13 +34,13 @@ function download.download_all(arch: string, name: string, namespace: string, ve local has_result = false local all_ok = true local any_err = "" - for name, result in pairs(results) do -- luacheck: ignore 422 - for version, items in pairs(result) do -- luacheck: ignore 422 + for rname, result in pairs(results) do -- luacheck: ignore 422 + for rversion, items in pairs(result) do -- luacheck: ignore 422 for _, item in ipairs(items) do -- Ignore provided rocks. if item.arch ~= "installed" then has_result = true - local filename = path.make_url(item.repo, name, version, item.arch) + local filename = path.make_url(item.repo, rname, rversion, item.arch) local ok, err = get_file(filename) if not ok then all_ok = false @@ -54,11 +54,11 @@ function download.download_all(arch: string, name: string, namespace: string, ve if has_result then return all_ok, any_err end - + local rock = util.format_rock_name(name, namespace, version) return nil, "Could not find a result named "..rock..(search_err and ": "..search_err or ".") end - + function download.download_file(arch: string, name: string, namespace?: string, version?: string, check_lua_versions?: boolean): string, string local query = queries.new(name, namespace, version, false, arch) local search_err: string @@ -68,7 +68,7 @@ function download.download_file(arch: string, name: string, namespace?: string, if url then return get_file(url) end - + local rock = util.format_rock_name(name, namespace, version) return nil, "Could not find a result named "..rock..(search_err and ": "..search_err or ".") end diff --git a/src/luarocks/fetch.tl b/src/luarocks/fetch.tl index 222b2194..6859142f 100644 --- a/src/luarocks/fetch.tl +++ b/src/luarocks/fetch.tl @@ -196,7 +196,7 @@ function fetch.fetch_url(url: string, filename?: string, cache?: boolean, mirror if not name then return nil, "Failed downloading "..url..(err and " - "..err or ""), err_code end - return name, nil, nil, from_cache --! string or boolean + return name, nil, nil, from_cache else return nil, "Unsupported protocol "..protocol end diff --git a/src/luarocks/fetch/cvs.lua b/src/luarocks/fetch/cvs.lua index 6aabfb31..d890c04c 100644 --- a/src/luarocks/fetch/cvs.lua +++ b/src/luarocks/fetch/cvs.lua @@ -16,7 +16,7 @@ local util = require("luarocks.util") -function cvs.get_sources(rockspec, extract, dest_dir) +function cvs.get_sources(rockspec, _extract, dest_dir) local cvs_cmd = rockspec.variables.CVS local ok, err_msg = fs.is_tool_available(cvs_cmd, "CVS") if not ok then diff --git a/src/luarocks/fetch/cvs.tl b/src/luarocks/fetch/cvs.tl index c8fc5e3d..6d2264ee 100644 --- a/src/luarocks/fetch/cvs.tl +++ b/src/luarocks/fetch/cvs.tl @@ -16,7 +16,7 @@ local type Rockspec = require("luarocks.core.types.rockspec").Rockspec -- @return (string, string) or (nil, string): The absolute pathname of -- the fetched source tarball and the temporary directory created to -- store it; or nil and an error message. -function cvs.get_sources(rockspec: Rockspec, extract: boolean, dest_dir?: string): string, string --? extract not needed +function cvs.get_sources(rockspec: Rockspec, _extract: boolean, dest_dir?: string): string, string --? extract not needed local cvs_cmd = rockspec.variables.CVS local ok, err_msg = fs.is_tool_available(cvs_cmd, "CVS") if not ok then diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua index b32dfb1b..4242c342 100644 --- a/src/luarocks/fetch/git.lua +++ b/src/luarocks/fetch/git.lua @@ -86,7 +86,7 @@ end -function git.get_sources(rockspec, extract, dest_dir, depth) +function git.get_sources(rockspec, _extract, dest_dir, depth) local git_cmd = rockspec.variables.GIT local name_version = rockspec.name .. "-" .. rockspec.version diff --git a/src/luarocks/fetch/git.tl b/src/luarocks/fetch/git.tl index 6d281a33..2ad5b2b1 100644 --- a/src/luarocks/fetch/git.tl +++ b/src/luarocks/fetch/git.tl @@ -86,7 +86,7 @@ end -- @return (string, string) or (nil, string): The absolute pathname of -- the fetched source tarball and the temporary directory created to -- store it; or nil and an error message. -function git.get_sources(rockspec: Rockspec, extract: boolean, dest_dir?: string, depth?: string): string, string +function git.get_sources(rockspec: Rockspec, _extract: boolean, dest_dir?: string, depth?: string): string, string local git_cmd = rockspec.variables.GIT local name_version = rockspec.name .. "-" .. rockspec.version diff --git a/src/luarocks/fetch/hg.lua b/src/luarocks/fetch/hg.lua index 5265920f..6fe0812b 100644 --- a/src/luarocks/fetch/hg.lua +++ b/src/luarocks/fetch/hg.lua @@ -16,7 +16,7 @@ local util = require("luarocks.util") -function hg.get_sources(rockspec, extract, dest_dir) +function hg.get_sources(rockspec, _extract, dest_dir) local hg_cmd = rockspec.variables.HG local ok_available, err_msg = fs.is_tool_available(hg_cmd, "Mercurial") diff --git a/src/luarocks/fetch/hg.tl b/src/luarocks/fetch/hg.tl index 3f94cee1..e34f9145 100644 --- a/src/luarocks/fetch/hg.tl +++ b/src/luarocks/fetch/hg.tl @@ -16,7 +16,7 @@ local type Rockspec = require("luarocks.core.types.rockspec").Rockspec -- @return (string, string) or (nil, string): The absolute pathname of -- the fetched source tarball and the temporary directory created to -- store it; or nil and an error message. -function hg.get_sources(rockspec: Rockspec, extract: boolean, dest_dir?: string): string, string +function hg.get_sources(rockspec: Rockspec, _extract: boolean, dest_dir?: string): string, string local hg_cmd = rockspec.variables.HG local ok_available, err_msg = fs.is_tool_available(hg_cmd, "Mercurial") diff --git a/src/luarocks/fetch/sscm.lua b/src/luarocks/fetch/sscm.lua index f635c02f..20478c72 100644 --- a/src/luarocks/fetch/sscm.lua +++ b/src/luarocks/fetch/sscm.lua @@ -15,7 +15,7 @@ local dir = require("luarocks.dir") -function sscm.get_sources(rockspec, extract, dest_dir) +function sscm.get_sources(rockspec, _extract, _dest_dir) local sscm_cmd = rockspec.variables.SSCM local module = rockspec.source.module or dir.base_name(rockspec.source.url) diff --git a/src/luarocks/fetch/sscm.tl b/src/luarocks/fetch/sscm.tl index 7c850a4b..45255bcb 100644 --- a/src/luarocks/fetch/sscm.tl +++ b/src/luarocks/fetch/sscm.tl @@ -15,7 +15,7 @@ local type Rockspec = require("luarocks.core.types.rockspec").Rockspec -- @return (string, string) or (nil, string): The absolute pathname of -- the fetched source tarball and the temporary directory created to -- store it; or nil and an error message. -function sscm.get_sources(rockspec: Rockspec, extract: boolean, dest_dir?: string): string, string +function sscm.get_sources(rockspec: Rockspec, _extract: boolean, _dest_dir?: string): string, string local sscm_cmd = rockspec.variables.SSCM local module = rockspec.source.module or dir.base_name(rockspec.source.url) diff --git a/src/luarocks/fetch/svn.lua b/src/luarocks/fetch/svn.lua index cd467cef..e265684c 100644 --- a/src/luarocks/fetch/svn.lua +++ b/src/luarocks/fetch/svn.lua @@ -16,7 +16,7 @@ local util = require("luarocks.util") -function svn.get_sources(rockspec, extract, dest_dir) +function svn.get_sources(rockspec, _extract, dest_dir) local svn_cmd = rockspec.variables.SVN local ok, err_msg = fs.is_tool_available(svn_cmd, "Subversion") diff --git a/src/luarocks/fetch/svn.tl b/src/luarocks/fetch/svn.tl index 4d738d74..741b0141 100644 --- a/src/luarocks/fetch/svn.tl +++ b/src/luarocks/fetch/svn.tl @@ -16,7 +16,7 @@ local type Rockspec = require("luarocks.core.types.rockspec").Rockspec -- @return (string, string) or (nil, string): The absolute pathname of -- the fetched source tarball and the temporary directory created to -- store it; or nil and an error message. -function svn.get_sources(rockspec: Rockspec, extract: boolean, dest_dir?: string): string, string +function svn.get_sources(rockspec: Rockspec, _extract: boolean, dest_dir?: string): string, string local svn_cmd = rockspec.variables.SVN local ok, err_msg = fs.is_tool_available(svn_cmd, "Subversion") diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl index 3d145bab..580f7c3f 100644 --- a/src/luarocks/fs.d.tl +++ b/src/luarocks/fs.d.tl @@ -43,7 +43,7 @@ local record fs record Lock free: function() end - lock_access: function(string, ?boolean): Lock, string --! + lock_access: function(string, ?boolean): Lock, string unlock_access: function(Lock) copy: function(string, string, ?string): boolean, string unpack_archive: function(string): boolean, string diff --git a/src/luarocks/manif.tl b/src/luarocks/manif.tl index 23ed081b..6a62a73f 100644 --- a/src/luarocks/manif.tl +++ b/src/luarocks/manif.tl @@ -142,7 +142,7 @@ function manif.load_manifest(repo_url: string, lua_version?: string, versioned_o pathname = nozip end local manifest, err, errcode = core.manifest_loader(pathname, repo_url, lua_version) - if not manifest and err is string then --! + if not manifest and err is string then return nil, err, errcode end diff --git a/src/luarocks/manif/writer.lua b/src/luarocks/manif/writer.lua index 04becbac..7d78c2ea 100644 --- a/src/luarocks/manif/writer.lua +++ b/src/luarocks/manif/writer.lua @@ -134,7 +134,7 @@ end local function sort_package_matching_table(tbl) if next(tbl) then - for item, pkgs in pairs(tbl) do + for _item, pkgs in pairs(tbl) do if #pkgs > 1 then table.sort(pkgs, sort_pkgs) @@ -261,17 +261,17 @@ function writer.make_rock_manifest(name, version) local walk = tree local last local last_name - local next + local nxt for filename in file:gmatch("[^\\/]+") do - next = walk[filename] - if not next then - next = {} - walk[filename] = next + nxt = walk[filename] + if not nxt then + nxt = {} + walk[filename] = nxt end last = walk last_name = filename - assert(type(next) == "table") - walk = next + assert(type(nxt) == "table") + walk = nxt end if fs.is_file(full_path) then @@ -303,8 +303,8 @@ function writer.make_namespace_file(name, version, namespace) if not fd then return nil, err end - local ok, err = fd:write(namespace) - if not ok then + fd, err = fd:write(namespace) + if not fd then return nil, err end fd:close() @@ -416,7 +416,7 @@ function writer.remove_from_manifest(name, version, repo, deps_mode) if deps_mode == "none" then deps_mode = cfg.deps_mode end - local manifest, err = manif.load_manifest(rocks_dir) + local manifest, _err = manif.load_manifest(rocks_dir) if not manifest then util.printerr("No existing manifest. Attempting to rebuild...") diff --git a/src/luarocks/manif/writer.tl b/src/luarocks/manif/writer.tl index b333c36f..7b30f5c2 100644 --- a/src/luarocks/manif/writer.tl +++ b/src/luarocks/manif/writer.tl @@ -134,7 +134,7 @@ end local function sort_package_matching_table(tbl: {string: {string}}) if next(tbl) then - for item, pkgs in pairs(tbl) do + for _item, pkgs in pairs(tbl) do if #pkgs > 1 then table.sort(pkgs, sort_pkgs) -- Remove duplicates from the sorted array. @@ -261,17 +261,17 @@ function writer.make_rock_manifest(name: string, version: string): boolean, stri local walk = tree local last: {string : Entry} local last_name: string - local next: Entry + local nxt: Entry for filename in file:gmatch("[^\\/]+") do - next = walk[filename] - if not next then - next = {} - walk[filename] = next + nxt = walk[filename] + if not nxt then + nxt = {} + walk[filename] = nxt end last = walk last_name = filename - assert(next is {string: Entry}) - walk = next + assert(nxt is {string: Entry}) + walk = nxt end if fs.is_file(full_path) then @@ -303,8 +303,8 @@ function writer.make_namespace_file(name: string, version: string, namespace?: s if not fd then return nil, err end - local ok, err = fd:write(namespace) - if not ok then + fd, err = fd:write(namespace) + if not fd then return nil, err end fd:close() @@ -370,7 +370,7 @@ end -- "none" for using the default dependency mode from the configuration. -- @return boolean or (nil, string): True if manifest was updated successfully, -- or nil and an error message. -function writer.add_to_manifest(name: string, version: string, repo: string, deps_mode: string): boolean, string +function writer.add_to_manifest(name: string, version: string, repo: string, deps_mode: string): boolean, string assert(not name:match("/")) local rocks_dir = path.rocks_dir(repo or cfg.root_dir) @@ -388,7 +388,7 @@ function writer.add_to_manifest(name: string, version: string, repo: string, dep local results: {string : {string : {Result}}} = {[name] = {[version] = {{arch = "installed", repo = rocks_dir}}}} local ok: boolean - ok, err = store_results(results, manifest) --! + ok, err = store_results(results, manifest) if not ok then return nil, err end update_dependencies(manifest, deps_mode) @@ -416,7 +416,7 @@ function writer.remove_from_manifest(name: string, version: string, repo: string if deps_mode == "none" then deps_mode = cfg.deps_mode end - local manifest, err = manif.load_manifest(rocks_dir) + local manifest, _err = manif.load_manifest(rocks_dir) if not manifest then util.printerr("No existing manifest. Attempting to rebuild...") -- Manifest built by `writer.make_manifest` should already @@ -436,7 +436,7 @@ function writer.remove_from_manifest(name: string, version: string, repo: string return writer.make_manifest(rocks_dir, deps_mode) end - remove_package_items(manifest.modules, name, version, version_entry.modules) --! + remove_package_items(manifest.modules, name, version, version_entry.modules) remove_package_items(manifest.commands, name, version, version_entry.commands) package_entry[version] = nil diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index 8a4df1a0..2596ca11 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua @@ -111,18 +111,19 @@ function pack.pack_installed_rock(query, tree) local temp_dir = fs.make_temp_dir("pack") fs.copy_contents(prefix, temp_dir) + local ok local is_binary = false if rock_manifest.lib then - local ok, err = copy_back_files(name, version, (rock_manifest.lib), path.deploy_lib_dir(repo), dir.path(temp_dir, "lib"), "exec") + ok, err = copy_back_files(name, version, (rock_manifest.lib), path.deploy_lib_dir(repo), dir.path(temp_dir, "lib"), "exec") if not ok then return nil, "Failed copying back files: " .. err end is_binary = true end if rock_manifest.lua then - local ok, err = copy_back_files(name, version, (rock_manifest.lua), path.deploy_lua_dir(repo), dir.path(temp_dir, "lua"), "read") + ok, err = copy_back_files(name, version, (rock_manifest.lua), path.deploy_lua_dir(repo), dir.path(temp_dir, "lua"), "read") if not ok then return nil, "Failed copying back files: " .. err end end - local ok, err = fs.change_dir(temp_dir) + ok, err = fs.change_dir(temp_dir) if not ok then return nil, err end if not is_binary and not repos.has_binaries(name, version) then rock_file = rock_file:gsub("%." .. cfg.arch:gsub("%-", "%%-") .. "%.", ".all.") @@ -172,16 +173,22 @@ function pack.pack_binary_rock(name, namespace, version, sign, cmd) util.schedule_function(fs.delete, temp_dir) path.use_tree(temp_dir) - local ok, err = cmd() - if not ok then + + local ret + ret, err = cmd() + if not ret then return nil, err end + local rname, rversion = path.parse_name(name) if not rname then rname, rversion = name, version end local query = queries.new(rname, namespace, rversion) - local file, err = pack.pack_installed_rock(query, temp_dir) + + local file + file, err = pack.pack_installed_rock(query, temp_dir) + return pack.report_and_sign_local_file(file, err, sign) end diff --git a/src/luarocks/pack.tl b/src/luarocks/pack.tl index 8bb284f7..d23595a9 100644 --- a/src/luarocks/pack.tl +++ b/src/luarocks/pack.tl @@ -111,18 +111,19 @@ function pack.pack_installed_rock(query: Query, tree: string | Tree): string, st local temp_dir = fs.make_temp_dir("pack") fs.copy_contents(prefix, temp_dir) + local ok: boolean local is_binary = false if rock_manifest.lib then - local ok, err = copy_back_files(name, version, (rock_manifest.lib as {string: Entry}), path.deploy_lib_dir(repo), dir.path(temp_dir, "lib"), "exec") + ok, err = copy_back_files(name, version, (rock_manifest.lib as {string: Entry}), path.deploy_lib_dir(repo), dir.path(temp_dir, "lib"), "exec") if not ok then return nil, "Failed copying back files: " .. err end is_binary = true end if rock_manifest.lua then - local ok, err = copy_back_files(name, version, (rock_manifest.lua as {string: Entry}), path.deploy_lua_dir(repo), dir.path(temp_dir, "lua"), "read") + ok, err = copy_back_files(name, version, (rock_manifest.lua as {string: Entry}), path.deploy_lua_dir(repo), dir.path(temp_dir, "lua"), "read") if not ok then return nil, "Failed copying back files: " .. err end end - local ok, err = fs.change_dir(temp_dir) + ok, err = fs.change_dir(temp_dir) if not ok then return nil, err end if not is_binary and not repos.has_binaries(name, version) then rock_file = rock_file:gsub("%."..cfg.arch:gsub("%-","%%-").."%.", ".all.") @@ -172,16 +173,22 @@ function pack.pack_binary_rock(name: string, namespace: string, version: string, util.schedule_function(fs.delete, temp_dir) path.use_tree(temp_dir) - local ok, err = cmd() - if not ok then + + local ret: string + ret, err = cmd() + if not ret then return nil, err end + local rname, rversion = path.parse_name(name) if not rname then rname, rversion = name, version end local query = queries.new(rname, namespace, rversion) - local file, err = pack.pack_installed_rock(query, temp_dir) + + local file: string + file, err = pack.pack_installed_rock(query, temp_dir) + return pack.report_and_sign_local_file(file, err, sign) end diff --git a/src/luarocks/queries.lua b/src/luarocks/queries.lua index 34b6d687..917ca2f4 100644 --- a/src/luarocks/queries.lua +++ b/src/luarocks/queries.lua @@ -11,7 +11,6 @@ local query = require("luarocks.core.types.query") - local query_mt = {} query_mt.__index = query.Query diff --git a/src/luarocks/queries.tl b/src/luarocks/queries.tl index 303d9250..ed421a97 100644 --- a/src/luarocks/queries.tl +++ b/src/luarocks/queries.tl @@ -9,7 +9,6 @@ local cfg = require("luarocks.core.cfg") local query = require("luarocks.core.types.query") local type Query = query.Query -local type Version = require("luarocks.core.types.version").Version local type Constraint = require("luarocks.core.types.version").Constraint local query_mt: metatable = {} diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index 72d3a1d8..ef19eac2 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -36,7 +36,7 @@ local function check_dependents(name, versions, deps_mode) local_rocks[name] = nil for rock_name, rock_versions in pairs(local_rocks) do for rock_version, _ in pairs(rock_versions) do - local rockspec, err = fetch.load_rockspec(path.rockspec_file(rock_name, rock_version)) + local rockspec = fetch.load_rockspec(path.rockspec_file(rock_name, rock_version)) if rockspec then local _, missing = deps.match_deps(rockspec.dependencies.queries, rockspec.rocks_provided, deps_mode, skip_set) if missing[name] then @@ -127,8 +127,13 @@ function remove.remove_other_versions(name, version, force, fast) if not fast then - local rock_manifest, load_err = manif.load_rock_manifest(name, version) - local ok, err = repos.check_everything_is_installed(name, version, rock_manifest, cfg.root_dir, false) + local rock_manifest, err = manif.load_rock_manifest(name, version) + if not rock_manifest then + return nil, err + end + + local ok + ok, err = repos.check_everything_is_installed(name, version, rock_manifest, cfg.root_dir, false) if not ok then return nil, err end diff --git a/src/luarocks/remove.tl b/src/luarocks/remove.tl index 11d270a9..21fdd51b 100644 --- a/src/luarocks/remove.tl +++ b/src/luarocks/remove.tl @@ -36,7 +36,7 @@ local function check_dependents(name: string, versions: {string: {Result}}, deps local_rocks[name] = nil for rock_name, rock_versions in pairs(local_rocks) do for rock_version, _ in pairs(rock_versions) do - local rockspec, err = fetch.load_rockspec(path.rockspec_file(rock_name, rock_version)) + local rockspec = fetch.load_rockspec(path.rockspec_file(rock_name, rock_version)) if rockspec then local _, missing = deps.match_deps(rockspec.dependencies.queries, rockspec.rocks_provided, deps_mode, skip_set) if missing[name] then @@ -127,8 +127,13 @@ function remove.remove_other_versions(name: string, version: string, force: bool if not fast then -- since we're not using --keep, this means that all files of the rock being installed -- should be available as non-versioned variants. Double-check that: - local rock_manifest, load_err = manif.load_rock_manifest(name, version) - local ok, err = repos.check_everything_is_installed(name, version, rock_manifest, cfg.root_dir, false) + local rock_manifest, err = manif.load_rock_manifest(name, version) + if not rock_manifest then + return nil, err + end + + local ok: boolean + ok, err = repos.check_everything_is_installed(name, version, rock_manifest, cfg.root_dir, false) if not ok then return nil, err end diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 956825e4..c4c5f28f 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua @@ -160,7 +160,7 @@ function repos.has_binaries(name, version) end local bin = entries["bin"] if type(bin) == "table" then - for bin_name, md5 in pairs(bin) do + for bin_name, _md5 in pairs(bin) do if fs.is_actual_binary(dir.path(cfg.deploy_bin_dir, bin_name)) then return true @@ -222,7 +222,7 @@ local function find_suffixed(file, suffix) end local function check_suffix(filename, suffix) - local suffixed_filename, err = find_suffixed(filename, suffix) + local suffixed_filename, _err = find_suffixed(filename, suffix) if not suffixed_filename then return "" end @@ -308,7 +308,8 @@ local function prepare_op_install() return nil, err end - local backup, err = backup_existing(op.backup, op.dst) + local backup + backup, err = backup_existing(op.backup, op.dst) if err then return nil, err end @@ -559,8 +560,12 @@ local function double_check_all(double_checks, repo) local errs = {} for next_name, versions in pairs(double_checks) do for next_version in pairs(versions) do - local rock_manifest, load_err = manif.load_rock_manifest(next_name, next_version) - local ok, err = repos.check_everything_is_installed(next_name, next_version, rock_manifest, repo, true) + local rock_manifest + local ok, err + rock_manifest, err = manif.load_rock_manifest(next_name, next_version) + if rock_manifest then + ok, err = repos.check_everything_is_installed(next_name, next_version, rock_manifest, repo, true) + end if not ok then table.insert(errs, err) end @@ -582,7 +587,7 @@ end -function repos.delete_local_version(name, version, deps_mode, quick) +function repos.delete_local_version(name, version, _deps_mode, quick) assert(not name:match("/")) local rock_manifest, load_err = manif.load_rock_manifest(name, version) @@ -602,7 +607,7 @@ function repos.delete_local_version(name, version, deps_mode, quick) if rock_manifest.bin then repos.recurse_rock_manifest_entry(rock_manifest.bin, function(file_path) local paths = get_deploy_paths(name, version, "bin", file_path, repo) - local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "bin", file_path) + local mode, _cur_name, _cur_version, item_name = check_spot_if_available(name, version, "bin", file_path) if mode == "v" then table.insert(deletes, { name = paths.v, suffix = cfg.wrapper_suffix }) else @@ -622,7 +627,7 @@ function repos.delete_local_version(name, version, deps_mode, quick) if rock_manifest.lua then repos.recurse_rock_manifest_entry(rock_manifest.lua, function(file_path) local paths = get_deploy_paths(name, version, "lua", file_path, repo) - local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "lua", file_path) + local mode, _cur_name, _cur_version, item_name = check_spot_if_available(name, version, "lua", file_path) if mode == "v" then table.insert(deletes, { name = paths.v }) else @@ -644,7 +649,7 @@ function repos.delete_local_version(name, version, deps_mode, quick) if rock_manifest.lib then repos.recurse_rock_manifest_entry(rock_manifest.lib, function(file_path) local paths = get_deploy_paths(name, version, "lib", file_path, repo) - local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "lib", file_path) + local mode, _cur_name, _cur_version, item_name = check_spot_if_available(name, version, "lib", file_path) if mode == "v" then table.insert(deletes, { name = paths.v }) else diff --git a/src/luarocks/repos.tl b/src/luarocks/repos.tl index 29645112..93c85d9a 100644 --- a/src/luarocks/repos.tl +++ b/src/luarocks/repos.tl @@ -160,7 +160,7 @@ function repos.has_binaries(name: string, version: string): boolean end local bin = entries["bin"] if bin is {string:Entry} then - for bin_name, md5 in pairs(bin) do + for bin_name, _md5 in pairs(bin) do -- TODO verify that it is the same file. If it isn't, find the actual command. if fs.is_actual_binary(dir.path(cfg.deploy_bin_dir, bin_name)) then return true @@ -222,7 +222,7 @@ local function find_suffixed(file: string, suffix: string): string, string end local function check_suffix(filename: string, suffix: string): string - local suffixed_filename, err = find_suffixed(filename, suffix) + local suffixed_filename, _err = find_suffixed(filename, suffix) if not suffixed_filename then return "" end @@ -308,7 +308,8 @@ local function prepare_op_install(): function(Op): (boolean, string), function() return nil, err end - local backup, err = backup_existing(op.backup, op.dst) + local backup: string + backup, err = backup_existing(op.backup, op.dst) if err then return nil, err end @@ -559,8 +560,12 @@ local function double_check_all(double_checks: {string: {string: boolean}}, repo local errs: {string} = {} for next_name, versions in pairs(double_checks) do for next_version in pairs(versions) do - local rock_manifest, load_err = manif.load_rock_manifest(next_name, next_version) - local ok, err = repos.check_everything_is_installed(next_name, next_version, rock_manifest, repo, true) + local rock_manifest: {string: Entry} + local ok, err: boolean, string + rock_manifest, err = manif.load_rock_manifest(next_name, next_version) + if rock_manifest then + ok, err = repos.check_everything_is_installed(next_name, next_version, rock_manifest, repo, true) + end if not ok then table.insert(errs, err) end @@ -582,7 +587,7 @@ end -- of another version that provides the same module that -- was deleted. This is used during 'purge', as every module -- will be eventually deleted. -function repos.delete_local_version(name: string, version: string, deps_mode: string, quick: boolean): boolean, string, string +function repos.delete_local_version(name: string, version: string, _deps_mode: string, quick: boolean): boolean, string, string assert(not name:match("/")) local rock_manifest, load_err = manif.load_rock_manifest(name, version) @@ -602,7 +607,7 @@ function repos.delete_local_version(name: string, version: string, deps_mode: st if rock_manifest.bin then repos.recurse_rock_manifest_entry(rock_manifest.bin, function(file_path: string): boolean, string local paths = get_deploy_paths(name, version, "bin", file_path, repo) - local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "bin", file_path) + local mode, _cur_name, _cur_version, item_name = check_spot_if_available(name, version, "bin", file_path) if mode == "v" then table.insert(deletes, { name = paths.v, suffix = cfg.wrapper_suffix }) else @@ -622,7 +627,7 @@ function repos.delete_local_version(name: string, version: string, deps_mode: st if rock_manifest.lua then repos.recurse_rock_manifest_entry(rock_manifest.lua, function(file_path: string): boolean, string local paths = get_deploy_paths(name, version, "lua", file_path, repo) - local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "lua", file_path) + local mode, _cur_name, _cur_version, item_name = check_spot_if_available(name, version, "lua", file_path) if mode == "v" then table.insert(deletes, { name = paths.v }) else @@ -644,7 +649,7 @@ function repos.delete_local_version(name: string, version: string, deps_mode: st if rock_manifest.lib then repos.recurse_rock_manifest_entry(rock_manifest.lib, function(file_path: string): boolean, string local paths = get_deploy_paths(name, version, "lib", file_path, repo) - local mode, cur_name, cur_version, item_name = check_spot_if_available(name, version, "lib", file_path) + local mode, _cur_name, _cur_version, item_name = check_spot_if_available(name, version, "lib", file_path) if mode == "v" then table.insert(deletes, { name = paths.v }) else diff --git a/src/luarocks/rockspecs.lua b/src/luarocks/rockspecs.lua index c41469fd..c82e4856 100644 --- a/src/luarocks/rockspecs.lua +++ b/src/luarocks/rockspecs.lua @@ -107,7 +107,7 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick) do local parsed_format = vers.parse_version(rockspec.rockspec_format or "1.0") - rockspec.format_is_at_least = function(self, version) + rockspec.format_is_at_least = function(_self, version) return parsed_format >= vers.parse_version(version) end end diff --git a/src/luarocks/rockspecs.tl b/src/luarocks/rockspecs.tl index 15a28de0..a34c0dbf 100644 --- a/src/luarocks/rockspecs.tl +++ b/src/luarocks/rockspecs.tl @@ -107,12 +107,12 @@ function rockspecs.from_persisted_table(filename: string, rockspec: Rockspec, gl -- @return boolean: true if rockspec format matches version or is newer, false otherwise. do local parsed_format = vers.parse_version(rockspec.rockspec_format or "1.0") - rockspec.format_is_at_least = function(self: Rockspec, version: string): boolean + rockspec.format_is_at_least = function(_self: Rockspec, version: string): boolean return parsed_format >= vers.parse_version(version) end end - platform_overrides(rockspec.build as {any : any}) --! + platform_overrides(rockspec.build as {any : any}) platform_overrides(rockspec.dependencies as {any : any}) platform_overrides(rockspec.build_dependencies as {any : any}) platform_overrides(rockspec.test_dependencies as {any : any}) diff --git a/src/luarocks/test/busted.lua b/src/luarocks/test/busted.lua index bc00b33a..aa47349b 100644 --- a/src/luarocks/test/busted.lua +++ b/src/luarocks/test/busted.lua @@ -7,7 +7,6 @@ local deps = require("luarocks.deps") local path = require("luarocks.path") local dir = require("luarocks.dir") local queries = require("luarocks.queries") -local install = require("luarocks.cmd.install") diff --git a/src/luarocks/test/busted.tl b/src/luarocks/test/busted.tl index 832a81b7..878319c7 100644 --- a/src/luarocks/test/busted.tl +++ b/src/luarocks/test/busted.tl @@ -7,7 +7,6 @@ local deps = require("luarocks.deps") local path = require("luarocks.path") local dir = require("luarocks.dir") local queries = require("luarocks.queries") -local install = require("luarocks.cmd.install") local type Test = require("luarocks.core.types.rockspec").Test diff --git a/src/luarocks/tools/patch.lua b/src/luarocks/tools/patch.lua index 5c21eaf0..4bf27e31 100644 --- a/src/luarocks/tools/patch.lua +++ b/src/luarocks/tools/patch.lua @@ -53,7 +53,7 @@ end local debugmode = false -local function debug(_) end +local function dbg(_) end local function info(_) end local function warning(s) io.stderr:write(s .. '\n') end @@ -79,14 +79,6 @@ local function table_copy(t) return t2 end -local function exists(filename) - local fh = io.open(filename) - local result = fh ~= nil - if fh then fh:close() end - return result -end -local function isfile() return true end - local function string_as_file(s) return { at = 0, @@ -279,7 +271,7 @@ function patch.read_patch(filename, data) elseif startswith(line, "--- ") then state = 'filenames' if debugmode and #files.source > 0 then - debug(string.format("- %2d hunks for %s", #files.hunks[nextfileno], + dbg(string.format("- %2d hunks for %s", #files.hunks[nextfileno], files.source[nextfileno])) end end @@ -393,7 +385,7 @@ function patch.read_patch(filename, data) else if debugmode and #files.source > 0 then - debug(string.format("- %2d hunks for %s", #files.hunks[nextfileno], + dbg(string.format("- %2d hunks for %s", #files.hunks[nextfileno], files.source[nextfileno])) end end @@ -512,7 +504,7 @@ local function patch_hunks(srcname, tgtname, hunks) local srclineno = 1 local lineends = { ['\n'] = 0, ['\r\n'] = 0, ['\r'] = 0 } for hno, h in ipairs(hunks) do - debug(string.format("processing hunk %d for file %s", hno, tgtname)) + dbg(string.format("processing hunk %d for file %s", hno, tgtname)) while srclineno < h.startsrc do local line = src_readline() @@ -596,17 +588,16 @@ local function patch_file(source, target, epoch, hunks, strip, create_delete) end source = strip_dirs(source, strip) local f2patch = source - if not exists(f2patch) then + if not fs.exists(f2patch) then f2patch = strip_dirs(target, strip) f2patch = fs.absolute_name(f2patch) - if not exists(f2patch) then + if not fs.exists(f2patch) then warning(string.format("source/target file does not exist\n--- %s\n+++ %s", source, f2patch)) return false end end - - if not isfile() then + if not fs.is_file(f2patch) then warning(string.format("not a file - %s", f2patch)) return false end @@ -658,7 +649,7 @@ local function patch_file(source, target, epoch, hunks, strip, create_delete) if endlstrip(line) == hunkfind[hunklineno] then hunklineno = hunklineno + 1 else - debug(string.format("hunk no.%d doesn't match source file %s", + dbg(string.format("hunk no.%d doesn't match source file %s", hunkno, source)) hunkno = hunkno + 1 @@ -672,7 +663,7 @@ local function patch_file(source, target, epoch, hunks, strip, create_delete) end if lineno == hunk.startsrc + #hunkfind - 1 then - debug(string.format("file %s hunk no.%d -- is ready to be patched", + dbg(string.format("file %s hunk no.%d -- is ready to be patched", source, hunkno)) hunkno = hunkno + 1 validhunks = validhunks + 1 @@ -715,7 +706,7 @@ local function patch_file(source, target, epoch, hunks, strip, create_delete) return true end local backupname = source .. ".orig" - if exists(backupname) then + if fs.exists(backupname) then warning(string.format("can't backup original file to %s - aborting", backupname)) return false diff --git a/src/luarocks/tools/patch.tl b/src/luarocks/tools/patch.tl index 1babbc88..83c16ab7 100644 --- a/src/luarocks/tools/patch.tl +++ b/src/luarocks/tools/patch.tl @@ -22,7 +22,7 @@ local record patch invalid: boolean text: {string} end - record File --! + record File at: integer str: string len: integer @@ -31,7 +31,7 @@ local record patch close: function(File): boolean end record Files - source: {string} --! + source: {string} target: {string} epoch: {boolean} hunks: {{Hunk}} @@ -53,7 +53,7 @@ end -- logging local debugmode = false -local function debug(_: string) end --! +local function dbg(_: string) end local function info(_: string) end local function warning(s: string) io.stderr:write(s .. '\n') end @@ -79,7 +79,7 @@ local function table_copy(t: {K: V}): {K: V} return t2 end -local function string_as_file(s: string): File --! +local function string_as_file(s: string): File return { at = 0, str = s, @@ -122,7 +122,7 @@ local function file_lines(f: FILE): function(): string elseif f then local chunk = f:read(CHUNK_SIZE) if chunk then - buffer = buffer:sub(pos_beg) .. chunk --! funcy stuff with pos + buffer = buffer:sub(pos_beg) .. chunk pos_beg = 1 else f = nil @@ -178,11 +178,11 @@ function patch.read_patch(filename: string, data: string): Files, boolean } local hunkactual: Hunk = {linessrc=nil, linestgt=nil} - info(string.format("reading patch %s", filename)) --! + info(string.format("reading patch %s", filename)) local fp: FILE if data then - fp = string_as_file(data) as FILE --! cast + fp = string_as_file(data) as FILE else fp = filename == '-' and io.stdin or open(filename, "rb") end @@ -271,7 +271,7 @@ function patch.read_patch(filename: string, data: string): Files, boolean elseif startswith(line, "--- ") then state = 'filenames' if debugmode and #files.source > 0 then - debug(string.format("- %2d hunks for %s", #files.hunks[nextfileno], + dbg(string.format("- %2d hunks for %s", #files.hunks[nextfileno], files.source[nextfileno])) end end @@ -385,7 +385,7 @@ function patch.read_patch(filename: string, data: string): Files, boolean else -- duplicated message when an eof is reached if debugmode and #files.source > 0 then - debug(string.format("- %2d hunks for %s", #files.hunks[nextfileno], + dbg(string.format("- %2d hunks for %s", #files.hunks[nextfileno], files.source[nextfileno])) end end @@ -406,7 +406,7 @@ local function find_hunk(file: {string}, h: Hunk, hno: integer): boolean if l > fuzz then -- todo: \ No newline at the end of file if startswith(hline, " ") or startswith(hline, "-") then - local line = file[lineno] --! cast + local line = file[lineno] lineno = lineno + 1 if not line or #line == 0 then found = false @@ -468,7 +468,7 @@ local function check_patched(file: {string}, hunks: {Hunk}): boolean if #file < h.starttgt then error('nomatch', 0) end - lineno = h.starttgt as integer --! cast + lineno = h.starttgt as integer for _, hline in ipairs(h.text) do -- todo: \ No newline at the end of file if not startswith(hline, "-") and not startswith(hline, "\\") then @@ -502,9 +502,9 @@ local function patch_hunks(srcname: string, tgtname: string, hunks: {Hunk}): boo -- of patching. Also issue a warning about mixed lineends local srclineno = 1 - local lineends = {['\n']=0, ['\r\n']=0, ['\r']=0} + local lineends: {string: integer} = {['\n']=0, ['\r\n']=0, ['\r']=0} for hno, h in ipairs(hunks) do - debug(string.format("processing hunk %d for file %s", hno, tgtname)) + dbg(string.format("processing hunk %d for file %s", hno, tgtname)) -- skip to line just before hunk starts while srclineno < h.startsrc do local line = src_readline() @@ -533,7 +533,7 @@ local function patch_hunks(srcname: string, tgtname: string, hunks: {Hunk}): boo local line2write = hline:sub(2) -- detect if line ends are consistent in source file local sum = 0 - for _,v in pairs(lineends as {string:any}) do if v as integer > 0 then sum=sum+1 end end --! unchecked + for _,v in pairs(lineends) do if v > 0 then sum=sum+1 end end if sum == 1 then local newline: string for k,v in pairs(lineends as {string:any}) do if v ~= 0 then newline = k end end @@ -649,7 +649,7 @@ local function patch_file(source: string, target: string, epoch: boolean, hunks: if endlstrip(line) == hunkfind[hunklineno] then hunklineno = hunklineno + 1 else - debug(string.format("hunk no.%d doesn't match source file %s", + dbg(string.format("hunk no.%d doesn't match source file %s", hunkno, source)) -- file may be already patched, but check other hunks anyway hunkno = hunkno + 1 @@ -663,7 +663,7 @@ local function patch_file(source: string, target: string, epoch: boolean, hunks: end -- check if processed line is the last line if lineno == hunk.startsrc + #hunkfind - 1 then - debug(string.format("file %s hunk no.%d -- is ready to be patched", + dbg(string.format("file %s hunk no.%d -- is ready to be patched", source, hunkno)) hunkno = hunkno + 1 validhunks = validhunks + 1 @@ -706,7 +706,7 @@ local function patch_file(source: string, target: string, epoch: boolean, hunks: return true end local backupname = source .. ".orig" - if exists(backupname) then + if fs.exists(backupname) then warning(string.format("can't backup original file to %s - aborting", backupname)) return false diff --git a/src/luarocks/tools/tar.lua b/src/luarocks/tools/tar.lua index 25e1d0ec..6db1334a 100644 --- a/src/luarocks/tools/tar.lua +++ b/src/luarocks/tools/tar.lua @@ -111,7 +111,7 @@ local function read_header_block(block) if header.typeflag == "unknown" then if checksum_header(block) ~= header.chksum then - return false, "Failed header checksum" + return nil, "Failed header checksum" end end return header @@ -136,13 +136,12 @@ function tar.untar(filename, destdir) break end - local headerp - headerp, err = read_header_block(block) - if not headerp then + local header + header, err = read_header_block(block) + if not header then ok = false break end - local header = headerp local file_data = "" if header.size > 0 then local nread = math.ceil(header.size / blocksize) * blocksize diff --git a/src/luarocks/tools/tar.tl b/src/luarocks/tools/tar.tl index a156bf9f..4d726cbc 100644 --- a/src/luarocks/tools/tar.tl +++ b/src/luarocks/tools/tar.tl @@ -84,7 +84,7 @@ local function nullterm(s: string): string return s:match("^[^%z]*") end -local function read_header_block(block: string): boolean | Header, string +local function read_header_block(block: string): Header, string local header: Header = {} header.name = nullterm(block:sub(1,100)) header.mode = nullterm(block:sub(101,108)):gsub(" ", "") @@ -111,7 +111,7 @@ local function read_header_block(block: string): boolean | Header, string -- end if header.typeflag == "unknown" then if checksum_header(block) ~= header.chksum then - return false, "Failed header checksum" + return nil, "Failed header checksum" end end return header @@ -136,13 +136,12 @@ function tar.untar(filename: string, destdir: string): boolean, string break end - local headerp: boolean | Header - headerp, err = read_header_block(block) - if not headerp then + local header: Header + header, err = read_header_block(block) + if not header then ok = false break end - local header: Header = headerp as Header --! cast local file_data = "" if header.size > 0 then local nread = math.ceil(header.size / blocksize) * blocksize diff --git a/src/luarocks/tools/zip.lua b/src/luarocks/tools/zip.lua index b54d9e86..f692796d 100644 --- a/src/luarocks/tools/zip.lua +++ b/src/luarocks/tools/zip.lua @@ -110,12 +110,12 @@ else error("unknown zlib library", 0) end -local function number_to_lestring(number, nbytes) +local function number_to_lestring(num, nbytes) local out = {} for _ = 1, nbytes do - local byte = number % 256 + local byte = num % 256 table.insert(out, string.char(byte)) - number = (number - byte) / 256 + num = math.floor((num - byte) / 256) end return table.concat(out) end diff --git a/src/luarocks/tools/zip.tl b/src/luarocks/tools/zip.tl index 82a19011..ad65f20a 100644 --- a/src/luarocks/tools/zip.tl +++ b/src/luarocks/tools/zip.tl @@ -59,7 +59,7 @@ local function shr(n: integer, m: integer): integer return math.floor(n / 2^m) end -local function shl(n: integer, m: integer): integer +local function shl(n: integer, m: integer): integer return (n * 2^m) as integer end @@ -110,12 +110,12 @@ else error("unknown zlib library", 0) end -local function number_to_lestring(number: number, nbytes: number): string +local function number_to_lestring(num: integer, nbytes: number): string local out = {} for _ = 1, nbytes do - local byte: integer = number as integer % 256 --! cast I don't like + local byte: integer = num % 256 table.insert(out, string.char(byte)) - number = (number - byte) / 256 + num = (num - byte) // 256 end return table.concat(out) end diff --git a/src/luarocks/type/manifest.tl b/src/luarocks/type/manifest.tl index 11bdc566..d6a6012c 100644 --- a/src/luarocks/type/manifest.tl +++ b/src/luarocks/type/manifest.tl @@ -82,7 +82,7 @@ local manifest_formats = type_check.declare_schemas({ -- mismatches. -- @return boolean or (nil, string): true if type checking -- succeeded, or nil and an error message if it failed. -function type_manifest.check(manifest: Manifest, globals: {string: any}): boolean, string --! +function type_manifest.check(manifest: Manifest, globals: {string: any}): boolean, string local format = manifest_formats["3.0"] local ok, err = type_check.check_undeclared_globals(globals, format) if not ok then return nil, err end diff --git a/src/luarocks/type_check.tl b/src/luarocks/type_check.tl index 1b332be0..e8086a58 100644 --- a/src/luarocks/type_check.tl +++ b/src/luarocks/type_check.tl @@ -1,6 +1,6 @@ local record type_check - type_check_table: function(version: string, tbl: {any: any}, typetbl: TableSchema, context: string): boolean, string --! tbl and typetbl types) + type_check_table: function(version: string, tbl: {any: any}, typetbl: TableSchema, context: string): boolean, string record TableSchema fields: {string: TableSchema} @@ -134,7 +134,7 @@ local function type_check_item(version: string, item: any, typetbl: TableSchema, end local pattern = typetbl._pattern if pattern then - if not item:match("^"..pattern.."$") then --! cast or tostring + if not item:match("^"..pattern.."$") then local what = typetbl._name or ("'"..pattern.."'") return nil, "Type mismatch on field "..context..": invalid value '"..item.."' does not match " .. what end @@ -219,7 +219,7 @@ function type_check.type_check_table(version: string, tbl: {any: any}, typetbl: return true end -function type_check.check_undeclared_globals(globals: {string: any}, typetbl: TableSchema): boolean, string --! tbl and typetbl types +function type_check.check_undeclared_globals(globals: {string: any}, typetbl: TableSchema): boolean, string local undeclared = {} for glob, _ in pairs(globals) do if not (typetbl.fields[glob] or typetbl.fields["MUST_"..glob]) then -- cgit v1.2.3-55-g6feb