Skip to content

Commit

Permalink
Merge pull request #25 from starius/fix-luacheck-warnings
Browse files Browse the repository at this point in the history
Fix luacheck warnings
  • Loading branch information
starius committed Feb 23, 2016
2 parents 568f2ad + 036c49a commit 06e8894
Show file tree
Hide file tree
Showing 25 changed files with 37 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ install:
- luarocks make --local CFLAGS="-O0 -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="-shared --coverage"

script:
- if [[ "$LUA" != *"luajit"* ]]; then .travis/lua-globals.sh `find src -name '*.lua'`; fi
- luacheck `find src -name '*.lua'`
- tar -cf /tmp/lua-src.tar.gz src/npge/*.lua src/npge/*/*.lua
- rm src/npge/*.lua src/npge/*/*.lua
- export LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0
Expand Down
6 changes: 0 additions & 6 deletions .travis/lua-globals.sh

This file was deleted.

1 change: 1 addition & 0 deletions .travis/setup_rocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ luarocks install luaposix --local
luarocks install lua-rote --local
luarocks install alnbox --local
luarocks install tree --local
luarocks install luacheck --local
2 changes: 1 addition & 1 deletion src/npge/algo/Blast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Blast.checkNoCollisions(bs1, bs2)
end
end

function Blast.blastnCmd(bank_fname, query_fname, options)
function Blast.blastnCmd(bank_fname, query_fname)
local config = require 'npge.config'
local nullName = require 'npge.util.nullName'
local args = {
Expand Down
6 changes: 3 additions & 3 deletions src/npge/algo/BlastHits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local function readBlast(file, query, bank, same, line_handler)
return query_name and bank_name
and query_row and bank_row
end
local function goodFragments(query_f, bank_f)
local function goodFragments(_, _)
return true
end
if same then
Expand Down Expand Up @@ -96,8 +96,8 @@ local function readBlast(file, query, bank, same, line_handler)
query_row = {}
bank_row = {}
elseif goodHit() then
local function parseAlignment(line)
local parts = split(line)
local function parseAlignment(line1)
local parts = split(line1)
assert(#parts == 4 or #parts == 3)
if #parts == 4 then
local _, start, row, stop = unpack(parts)
Expand Down
8 changes: 4 additions & 4 deletions src/npge/algo/CheckPangenome.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ return function(blockset)
-- block must be in right orientation
-- Quality of s,h,r-blocks is part of this step
for block, name in blockset:iterBlocks() do
local t, size, length, n = npge.block.parseName(name)
local t, size, length, _ = npge.block.parseName(name)
if size ~= block:size() then
fail("Block %s has size %d", name, block:size())
end
Expand Down Expand Up @@ -104,9 +104,9 @@ return function(blockset)
warning([[ All of these good parts were
eliminated by better or equal blocks]])
else
local names = blockNames(better_parts)
local better_names = blockNames(better_parts)
fail(" The following %d parts can be added: %s",
#better_parts, names)
#better_parts, better_names)
end
end
end
Expand All @@ -125,7 +125,7 @@ return function(blockset)
local joined = npge.algo.Join(blockset)
warning("Joining neighbour blocks produces %d blocks",
joined:size())
for i, block in ipairs(joined:blocks()) do
for _, block in ipairs(joined:blocks()) do
local block_name = npge.block.giveName(block, #genomes)
inspectBlock('Joined ' .. block_name, block)
end
Expand Down
2 changes: 1 addition & 1 deletion src/npge/algo/JoinMinor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ local function joinMinor(block, bs, joined, joinable)
local Block = require 'npge.model.Block'
local minor_block = Block(fragments)
table.insert(joined, minor_block)
for neighbour, f_ori in pairs(neighbours[ori]) do
for neighbour, _ in pairs(neighbours[ori]) do
joinable[neighbour] = nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/npge/algo/Merge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ return function(blocksets)
end
end
local seqs = {}
for name, seq in pairs(name2seq) do
for _, seq in pairs(name2seq) do
table.insert(seqs, seq)
end
local concatArrays = require 'npge.util.concatArrays'
Expand Down
2 changes: 1 addition & 1 deletion src/npge/algo/Multiply.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local function Multiply(bs1, bs2)
end
end
end
for block2, oo in pairs(block2_to_fragments) do
for _, oo in pairs(block2_to_fragments) do
-- TODO preserve alignment
table.insert(blocks, model.Block(oo))
end
Expand Down
2 changes: 1 addition & 1 deletion src/npge/algo/NonCovered.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ return function(blockset)
local fragments = {}
local last_pos = seq:length() - 1
local prev
for fragment, part in blockset:iterFragments(seq) do
for _, part in blockset:iterFragments(seq) do
local last = prev and max(prev) or -1
local first = min(part)
if first - last > 1 then
Expand Down
8 changes: 4 additions & 4 deletions src/npge/algo/Overlapping.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ return function(blockset, block)
for f1 in block:iterFragments() do
local fragments = blockset:overlappingFragments(f1)
for _, f2 in ipairs(fragments) do
local block = blockset:blockByFragment(f2)
blocks_set[block] = true
local block1 = blockset:blockByFragment(f2)
blocks_set[block1] = true
end
end
local blocks = {}
for block, _ in pairs(blocks_set) do
table.insert(blocks, block)
for block1, _ in pairs(blocks_set) do
table.insert(blocks, block1)
end
return blocks
end
4 changes: 2 additions & 2 deletions src/npge/algo/PrimaryHits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ return function(blockset)
local Genomes = require 'npge.algo.Genomes'
local has_genomes, _, genome2seqs = pcall(Genomes, blockset)
if has_genomes then
for genome, seqs in pairs(genome2seqs) do
for _, seqs in pairs(genome2seqs) do
table.insert(level2bss[1], BlockSet(seqs, {}))
end
else
Expand All @@ -35,7 +35,7 @@ return function(blockset)
end

local niterations = #(level2bss[1]) - 1
for i = 1, niterations do
for _ = 1, niterations do
local a, level_a = assert(popBs())
local b, level_b = assert(popBs())
local Cover = require 'npge.algo.Cover'
Expand Down
2 changes: 1 addition & 1 deletion src/npge/algo/UnwindBlocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
local function mergeSequences(prefix2blockset)
local blocksets = {}
local BlockSet = require 'npge.model.BlockSet'
for prefix, blockset in pairs(prefix2blockset) do
for _, blockset in pairs(prefix2blockset) do
local seqs = blockset:sequences()
table.insert(blocksets, BlockSet(seqs, {}))
end
Expand Down
4 changes: 2 additions & 2 deletions src/npge/alignment/alignRows.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local function compress(rows)
-- returns new rows, decompression_info
local new_rows = {}
local decompression_info = {}
for i, row in ipairs(rows) do
for _, row in ipairs(rows) do
if #row >= 1 then
table.insert(new_rows, row)
table.insert(decompression_info, #new_rows)
Expand Down Expand Up @@ -74,7 +74,7 @@ end

local function emptyRows(n)
local rows = {}
for i = 1, n do
for _ = 1, n do
table.insert(rows, '')
end
return rows
Expand Down
2 changes: 1 addition & 1 deletion src/npge/alignment/complementRows.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
return function(rows)
local new_rows = {}
local complement = require 'npge.alignment.complement'
for i, row in ipairs(rows) do
for _, row in ipairs(rows) do
table.insert(new_rows, complement(row))
end
return new_rows
Expand Down
1 change: 0 additions & 1 deletion src/npge/block/slice.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ return function(block, min, max, row)
assert(#row >= (max - min + 1))
local for_block = {}
for fragment in block:iterFragments() do
local seq = fragment:sequence()
local frag_min = block:block2right(fragment, min)
local frag_max = block:block2left(fragment, max)
if frag_min ~= -1 and frag_max ~= -1 and
Expand Down
4 changes: 2 additions & 2 deletions src/npge/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ local about = {}
for section_name, section in pairs(config) do
about[section_name] = {}
local names = {}
for name, value_and_desc in pairs(section) do
for name, _ in pairs(section) do
table.insert(names, name)
end
for _, name in ipairs(names) do
Expand Down Expand Up @@ -80,7 +80,7 @@ end
local function loadConfig(_, conf)
local sandbox = require 'npge.util.sandbox'
local env = {}
for section_name, section in pairs(config) do
for section_name, _ in pairs(config) do
env[section_name] = {}
end
env.Decimal = function() end -- C++ NPGe compatibility
Expand Down
2 changes: 1 addition & 1 deletion src/npge/io/LoadFromLua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ return function(code, enable_fromRef)
next=next, pairs=pairs, pcall=pcall,
tonumber=tonumber, tostring=tostring,
type=type,
unpack = unpack or table.unpack,
unpack = _G.unpack or table.unpack,
string = {
byte=string.byte, char=string.char,
format=string.format, len=string.len,
Expand Down
8 changes: 3 additions & 5 deletions src/npge/io/ReadFromBs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ local function isParted(start, stop, ori)
return diff * ori < 0
end

local function getParts(seqname, start, stop, ori, text)
local function getParts(seqname, start, stop, ori, text0)
local toAtgcn = require 'npge.alignment.toAtgcn'
local text = toAtgcn(text)
local text = toAtgcn(text0)
local length = #text
local length1, length2
if ori == 1 then
Expand Down Expand Up @@ -113,7 +113,6 @@ local function readWithoutReference(generator)
local seqname2parts = {}
local ev = require 'npge.util.extractValue'
local Sequence = require 'npge.model.Sequence'
local parseId = require 'npge.fragment.parseId'
for name, description, text in generator do
local blockname = ev(description, "block")
if blockname then
Expand Down Expand Up @@ -145,7 +144,7 @@ local function readWithoutReference(generator)
collectgarbage() -- large text
end
local sequences = {}
for name, seq in pairs(seqname2seq) do
for _, seq in pairs(seqname2seq) do
table.insert(sequences, seq)
end
return sequences, blockname2fragments
Expand Down Expand Up @@ -183,7 +182,6 @@ return function(lines, blockset_with_sequences)
local bs1 = BlockSet(sequences, {})
local blocks = {}
for blockname, fr_descs in pairs(blockname2fragments) do
local Block = require 'npge.model.Block'
blocks[blockname] = makeBlock(bs1, fr_descs)
end
return BlockSet(sequences, blocks)
Expand Down
2 changes: 1 addition & 1 deletion src/npge/io/ShortForm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ function ShortForm.decode(iterator, seq_bs)
local loader, env = ShortForm.loaderAndEnv()
local sandbox = require 'npge.util.sandbox'
for line in iterator do
local f, err = assert(sandbox(env, line))
local f, _ = assert(sandbox(env, line))
f()
end
return ShortForm.loader2blockset(loader, seq_bs)
Expand Down
2 changes: 1 addition & 1 deletion src/npge/util/loadstring.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
-- Copyright (C) 2014-2016 Boris Nagaev
-- See the LICENSE file for terms of use.

return loadstring or load
return _G.loadstring or _G.load
2 changes: 1 addition & 1 deletion src/npge/util/mapItems.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-- map items to ngroups groups of almost equal size
return function(ngroups, items)
local groups = {}
for i = 1, ngroups do
for _ = 1, ngroups do
table.insert(groups, {})
end
math.randomseed(os.time())
Expand Down
6 changes: 3 additions & 3 deletions src/npge/util/sandbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ return function(env, code)
_VERSION == 'Lua 5.3',
'Implemented in Lua 5.1, 5.2 and 5.3 only')
if _VERSION == 'Lua 5.2' or _VERSION == 'Lua 5.3' then
return load(code, 'sandbox', 't', env)
return _G.load(code, 'sandbox', 't', env)
elseif _VERSION == 'Lua 5.1' then
local f, message = loadstring(code, 'sandbox')
local f, message = _G.loadstring(code, 'sandbox')
if not f then
return nil, message
end
setfenv(f, env)
_G.setfenv(f, env)
return f
end
end
1 change: 0 additions & 1 deletion src/npge/util/threads.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ return function(generator, collector)
local result = loadstring(code)()
return collector({result})
end
local config = require 'npge.config'
local conf = config:save()
local threads = spawnWorkers(generator, workers, conf)
return collectResults(collector, threads)
Expand Down
2 changes: 1 addition & 1 deletion src/npge/util/unpack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
-- Copyright (C) 2014-2016 Boris Nagaev
-- See the LICENSE file for terms of use.

return unpack or table.unpack
return _G.unpack or table.unpack

0 comments on commit 06e8894

Please sign in to comment.