diff options
author | mpeterv <mpeterval@gmail.com> | 2016-04-17 15:53:53 +0300 |
---|---|---|
committer | mpeterv <mpeterval@gmail.com> | 2016-04-17 15:53:53 +0300 |
commit | 31b109afa3e20761662c5ccc8f777e4b04e088ab (patch) | |
tree | d65bee5d36513005c586775a5dcad2005b5c70a5 | |
parent | 3cf3c6230d1a45ac08bbfab8a0a8416c9e7a4461 (diff) | |
download | luacov-31b109afa3e20761662c5ccc8f777e4b04e088ab.tar.gz |
Fix Luacheck warnings, add .luacheckrc
-rw-r--r-- | .luacheckrc | 2 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | src/luacov/reporter.lua | 11 | ||||
-rw-r--r-- | src/luacov/runner.lua | 14 | ||||
-rw-r--r-- | src/luacov/stats.lua | 6 |
5 files changed, 20 insertions, 14 deletions
diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..0030d5c --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,2 @@ +std = "max" +exclude_files = {"tests/*/*"} @@ -119,6 +119,7 @@ After cloning this repo, these commands may be useful: * `luarocks make` to install LuaCov from local sources; * `make test` to run tests (does not require installing beforehand); * `ldoc .` to regenerate documentation using [LDoc](https://github.com/stevedonovan/LDoc). +* `luacheck .` to lint using [Luacheck](https://github.com/mpeterv/luacheck). ## Credits diff --git a/src/luacov/reporter.lua b/src/luacov/reporter.lua index de11260..e5c8a83 100644 --- a/src/luacov/reporter.lua +++ b/src/luacov/reporter.lua @@ -414,6 +414,9 @@ function ReporterBase:stats(filename) return self._data[filename] end +-- Stub methods follow. +-- luacheck: push no unused args + --- Stub method called before reporting. function ReporterBase:on_start() end @@ -457,6 +460,8 @@ end function ReporterBase:on_end() end +-- luacheck: pop + function ReporterBase:run() self:on_start() @@ -526,15 +531,15 @@ function DefaultReporter:on_new_file(filename) self:write("==============================================================================\n") end -function DefaultReporter:on_empty_line(filename, lineno, line) +function DefaultReporter:on_empty_line(_, _, line) self:write(self._empty_format, "\t", line, "\n") end -function DefaultReporter:on_mis_line(filename, lineno, line) +function DefaultReporter:on_mis_line(_, _, line) self:write(self._zero_format, "\t", line, "\n") end -function DefaultReporter:on_hit_line(filename, lineno, line, hits) +function DefaultReporter:on_hit_line(_, _, line, hits) self:write(self._count_format:format(hits), "\t", line, "\n") end diff --git a/src/luacov/runner.lua b/src/luacov/runner.lua index 23d96f0..6013485 100644 --- a/src/luacov/runner.lua +++ b/src/luacov/runner.lua @@ -11,7 +11,7 @@ runner.defaults = require("luacov.defaults") local debug = require("debug") -local new_anchor = newproxy or function() return {} end +local new_anchor = newproxy or function() return {} end -- luacheck: compat -- Returns an anchor that runs fn when collected. local function on_exit_wrap(fn) @@ -109,7 +109,7 @@ function runner.debug_hook(_, line_nr, level) ctr = 0 if not paused then - stats.save(data, statsfile) + stats.save(data) end end end @@ -482,7 +482,7 @@ function runner.init(configuration) -- metatable trick on filehandle won't work if Lua exits through -- os.exit() hence wrap that with exit code as well local rawexit = os.exit - os.exit = function(...) + os.exit = function(...) -- luacheck: no global on_exit() rawexit(...) end @@ -494,7 +494,7 @@ function runner.init(configuration) -- hence wrap coroutine function to set the hook there -- as well local rawcoroutinecreate = coroutine.create - coroutine.create = function(...) + coroutine.create = function(...) -- luacheck: no global local co = rawcoroutinecreate(...) debug.sethook(co, runner.debug_hook, "l") return co @@ -509,7 +509,7 @@ function runner.init(configuration) end end - coroutine.wrap = function(...) + coroutine.wrap = function(...) -- luacheck: no global local co = rawcoroutinecreate(...) debug.sethook(co, runner.debug_hook, "l") return function(...) @@ -549,7 +549,7 @@ local function findfunction(t, searched) searched[t] = true - for k, v in pairs(t) do + for _, v in pairs(t) do if type(v) == "function" then return v elseif type(v) == "table" then @@ -690,4 +690,4 @@ function runner.includetree(name, level) end -return setmetatable(runner, { ["__call"] = function(self, configfile) runner.init(configfile) end }) +return setmetatable(runner, {__call = function(_, configfile) runner.init(configfile) end}) diff --git a/src/luacov/stats.lua b/src/luacov/stats.lua index 526d974..4c5c49b 100644 --- a/src/luacov/stats.lua +++ b/src/luacov/stats.lua @@ -23,8 +23,7 @@ function stats.load() if not max then break end - local skip = fd:read(1) - if skip ~= ":" then + if fd:read(1) ~= ":" then break end local filename = fd:read("*l") @@ -40,8 +39,7 @@ function stats.load() if not hits then break end - local skip = fd:read(1) - if skip ~= " " then + if fd:read(1) ~= " " then break end if hits > 0 then |