Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use luacheck #343

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

codes = true

std = 'luajit'

max_line_length = 200

ignore = {
'611', -- line contains only whitespace
'612', -- line contains trailing whitespace
'613', -- trailing whitespace in a string
'614', -- trailing whitespace in a comment
}

globals = {
'terra',
'terralib',
'cudalib',
}

self = false

files['src/cudalib.lua'].read_globals = { 'opaque', 'uint' }
files['src/cudalib.lua'].ignore = {
'212/cudahome', -- unused argument cudahome
}
files['src/strict.lua'].max_line_length = 400
files['src/strict.lua'].ignore = { '111/Strict' } -- setting non-standard global variable Strict
files['src/terralib.lua'].max_line_length = 300
files['src/terralib.lua'].ignore = {
'113/Strict', -- accessing undefined variable Strict
'122/debug', -- setting read-only field traceback of global debug
'142/package', -- setting undefined field terrapath of global package
'143/package', -- accessing undefined field terrapath.gmatch of global package
'211/meet', -- unused variable meet
'211/orig', -- unused variable orig
'212', -- unused argument
'421/result', -- shadowing definition of variable result
'422/e', -- shadowing definition of argument e
'422/v', -- shadowing definition of argument v
'423/i', -- shadowing definition of loop variable i
'431', -- shadowing upvalue
'432', -- shadowing upvalue argument
'511', -- unreachable code
'542', -- empty if branch
}
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ all: $(EXECUTABLE) $(DYNLIBRARY)
test: all
(cd tests; ./run)

luacheck:
luacheck --config .luacheckrc src

variants: $(LIBRARY_VARIANTS)

build/%.o: src/%.cpp $(PACKAGE_DEPS)
Expand Down
20 changes: 10 additions & 10 deletions src/asdl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function List:map(fn,...)
return l
end
function List:insertall(elems)
for i,e in ipairs(elems) do
for _,e in ipairs(elems) do
self:insert(e)
end
end
Expand Down Expand Up @@ -150,9 +150,9 @@ local function parseAll(text)
until not nextif("|")
if nextif("attributes") then
local attributes = parseFields()
for i,ctor in ipairs(sum.constructors) do
for _,ctor in ipairs(sum.constructors) do
ctor.fields = ctor.fields or List()
for i,a in ipairs(attributes) do
for _,a in ipairs(attributes) do
ctor.fields:insert(a)
end
end
Expand Down Expand Up @@ -314,7 +314,7 @@ function Context:DefineClass(name,unique,fields)
local names = List()
local checks = List()
local tns = List()
for i,f in ipairs(fields) do
for _,f in ipairs(fields) do
names:insert(f.name)
tns:insert(f.list and f.type.."*" or f.type)
checks:insert(self:GetCheckForField(unique,f))
Expand Down Expand Up @@ -368,11 +368,11 @@ function Context:DefineClass(name,unique,fields)
end
function class:__tostring()
local members = List()
for i,f in ipairs(fields) do
for _,f in ipairs(fields) do
local v,r = self[f.name]
if f.list then
local elems = List()
for i,e in ipairs(self[f.name]) do
for _,e in ipairs(self[f.name]) do
elems:insert(tostring(e))
end
r = "{"..elems:concat(",").."}"
Expand Down Expand Up @@ -410,18 +410,18 @@ end
function Context:Define(text)
local defs = parseAll(text)
-- register all new type names
for i,d in ipairs(defs) do
for _,d in ipairs(defs) do
self:DeclareClass(d.name)
if d.type.kind == "sum" then
for i,c in ipairs(d.type.constructors) do
for _,c in ipairs(d.type.constructors) do
self:DeclareClass(c.name)
end
end
end
for i,d in ipairs(defs) do
for _,d in ipairs(defs) do
if d.type.kind == "sum" then
local parent = self:DefineClass(d.name,false,nil)
for i,c in ipairs(d.type.constructors) do
for _,c in ipairs(d.type.constructors) do
local child = self:DefineClass(c.name,c.unique,c.fields)
parent.members[child] = true --mark that any subclass is a member of its parent
child.kind = basename(c.name)
Expand Down
2 changes: 1 addition & 1 deletion src/cudalib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function cudalib.toptx(module,dumpmodule,version)
elseif type(v) == "table" and terra.isfunction(v.kernel) then -- annotated kernel
addkernel(k,v.kernel)
if v.annotations then
for i,a in pairs(v.annotations) do
for _,a in pairs(v.annotations) do
annotations:insert({k,tostring(a[1]),tonumber(a[2])})
end
end
Expand Down
1 change: 0 additions & 1 deletion src/genclangpaths.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
--See Copyright Notice in ../LICENSE.txt
--usage: genclangpaths.lua output /path/to/clang [addition args to parse]
local ffi = require("ffi")
local outputfile,clang = unpack(arg)
local handle = assert(io.popen(clang .. " -v src/dummy.c -o build/dummy.o 2>&1", "r"))
local theline
Expand Down
2 changes: 1 addition & 1 deletion src/geninternalizedfiles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ local function EmitRegister(name,contents)
table.insert(sizes,("\n%d"):format(#contents))
end

for i,entry in ipairs(listoffiles) do
for _,entry in ipairs(listoffiles) do
local file = io.open(entry.path)
local contents = file:read("*all")
file:close()
Expand Down
Loading