Skip to content

Commit

Permalink
Handle lints raised by Luacheck
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Aug 29, 2024
1 parent d7aa0a0 commit a86c913
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 44 deletions.
6 changes: 2 additions & 4 deletions data/creole.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
-- http://www.wikicreole.org/wiki/CheatSheet

-- For better performance we put these functions in local variables:
local P, S, R, Cf, Cc, Ct, V, Cs, Cg, Cb, B, C, Cmt =
lpeg.P, lpeg.S, lpeg.R, lpeg.Cf, lpeg.Cc, lpeg.Ct, lpeg.V,
lpeg.Cs, lpeg.Cg, lpeg.Cb, lpeg.B, lpeg.C, lpeg.Cmt
local P, S, Cc, Ct, V, C = lpeg.P, lpeg.S, lpeg.Cc, lpeg.Ct, lpeg.V, lpeg.C

local whitespacechar = S(" \t\r\n")
local specialchar = S("/*~[]\\{}|")
Expand Down Expand Up @@ -185,6 +183,6 @@ local grammar = P{ "Doc",
/ pandoc.Strong ;
}

function Reader(input, reader_options)
function Reader(input, _reader_options)
return lpeg.match(grammar, tostring(input))
end
12 changes: 6 additions & 6 deletions man/manfilter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ local text = require('text')
function Header(el)
if el.level == 1 then
return pandoc.walk_block(el, {
Str = function(el)
return pandoc.Str(text.upper(el.text))
Str = function(str_el)
return pandoc.Str(text.upper(str_el.text))
end })
end
end
Expand All @@ -17,11 +17,11 @@ function Table(el)
local rendered = pandoc.write(pandoc.Pandoc({el}), "plain")
local adjusted = rendered -- tame grid table lines
:gsub("%+([=:][=:]+)",
function(s)
return " " .. string.rep("-", #s - 1)
function(str)
return " " .. string.rep("-", #str - 1)
end)
:gsub("(%+[-:][-:]+)",
function(s)
function(_str)
return ""
end)
:gsub("%+\n","\n")
Expand All @@ -39,6 +39,6 @@ function Link(el)
end

-- remove notes
function Note(el)
function Note(_el)
return {}
end
2 changes: 1 addition & 1 deletion pandoc-lua-engine/test/bytestring-reader.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function ByteStringReader (input, opts)
function ByteStringReader (input, _opts)
local chars = pandoc.List{}
for i = 1, #input do
chars:insert(utf8.char(input:byte(i,i)))
Expand Down
2 changes: 1 addition & 1 deletion pandoc-lua-engine/test/bytestring.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function ByteStringWriter (doc, opts)
function ByteStringWriter (_doc, _opts)
local buffer = {}
for i=0, 255 do
table.insert(buffer, string.char(i))
Expand Down
2 changes: 1 addition & 1 deletion pandoc-lua-engine/test/extensions.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Writer (doc, opts)
function Writer (_doc, opts)
local output = 'smart extension is %s;\ncitations extension is %s\n'
local status = function (ext)
return opts.extensions:includes(ext) and 'enabled' or 'disabled'
Expand Down
4 changes: 2 additions & 2 deletions pandoc-lua-engine/test/lua/block-count.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
local num_blocks = 0

function Block(el)
function Block(_el)
num_blocks = num_blocks + 1
end

function Pandoc(blocks, meta)
function Pandoc(_blocks, _meta)
return pandoc.Pandoc {
pandoc.Para{pandoc.Str(num_blocks)}
}
Expand Down
2 changes: 1 addition & 1 deletion pandoc-lua-engine/test/lua/hello-world-doc.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
return {
{
Pandoc = function(doc)
Pandoc = function(_doc)
local meta = {}
local hello = { pandoc.Str "Hello,", pandoc.Space(), pandoc.Str "World!" }
local blocks = { pandoc.Para(hello) }
Expand Down
2 changes: 1 addition & 1 deletion pandoc-lua-engine/test/lua/implicit-doc-filter.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Pandoc (doc)
function Pandoc (_doc)
local meta = {}
local hello = { pandoc.Str "Hello,", pandoc.Space(), pandoc.Str "World!" }
local blocks = { pandoc.Para(hello) }
Expand Down
2 changes: 1 addition & 1 deletion pandoc-lua-engine/test/lua/inlines-filter.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function isWorldAfterSpace (fst, snd)
local function isWorldAfterSpace (fst, snd)
return fst and fst.t == 'LineBreak'
and snd and snd.t == 'Str' and snd.text == 'World!'
end
Expand Down
4 changes: 2 additions & 2 deletions pandoc-lua-engine/test/lua/metatable-catch-all.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
local num_inlines = 0

function catch_all(el)
local function catch_all(el)
if el.tag and pandoc.Inline.constructor[el.tag] then
num_inlines = num_inlines + 1
end
end

function Pandoc(blocks, meta)
function Pandoc(_blocks, _meta)
return pandoc.Pandoc {
pandoc.Para{pandoc.Str(num_inlines)}
}
Expand Down
4 changes: 2 additions & 2 deletions pandoc-lua-engine/test/lua/module/pandoc-list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local group = tasty.test_group

return {
group 'List as function' {
test('equivalent to List:new', function (x)
test('equivalent to List:new', function ()
local new = List:new {'ramen'}
local list = List {'ramen'}
assert.are_same(new, list)
Expand Down Expand Up @@ -109,7 +109,7 @@ return {
end),
test('leaves original list unchanged', function ()
local primes = List:new {2, 3, 5, 7}
local squares = primes:map(function (x) return x^2 end)
local _squares = primes:map(function (x) return x^2 end)
assert.are_same({2, 3, 5, 7}, primes)
end)
},
Expand Down
2 changes: 0 additions & 2 deletions pandoc-lua-engine/test/lua/module/pandoc-structure.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
local tasty = require 'tasty'
local structure = require 'pandoc.structure'
local path = require 'pandoc.path'
local system = require 'pandoc.system'

local assert = tasty.assert
local test = tasty.test_case
Expand Down
4 changes: 2 additions & 2 deletions pandoc-lua-engine/test/lua/module/pandoc-template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ return {
)
end),
test('fails on unknown format', function ()
local success, msg = pcall(function ()
local success, _msg = pcall(function ()
return pandoc.utils.type(template.default 'nosuchformat')
end)
assert.is_falsy(success)
Expand All @@ -42,7 +42,7 @@ return {
)
end),
test('fails on non-existent file', function ()
local success, msg = pcall(function ()
local success, _msg = pcall(function ()
return pandoc.utils.type(template.get 'nosuchfile.nope')
end)
assert.is_falsy(success)
Expand Down
3 changes: 2 additions & 1 deletion pandoc-lua-engine/test/lua/module/pandoc-utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ return {
test("doesn't change the local environment by default", function ()
pandoc.system.with_temporary_directory('lua-filter', function (dir)
local filter_path = pandoc.path.join{dir, 'test.lua'}
-- luacheck: ignore foo
local foo
local filter = 'foo = 42'
local fh = io.open(filter_path, 'wb')
Expand Down Expand Up @@ -284,7 +285,7 @@ return {

group 'to_simple_table' {
test('convertes Table', function ()
function simple_cell (blocks)
local function simple_cell (blocks)
return {
attr = pandoc.Attr(),
alignment = "AlignDefault",
Expand Down
2 changes: 1 addition & 1 deletion pandoc-lua-engine/test/lua/module/pandoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local test = tasty.test_case
local group = tasty.test_group
local assert = tasty.assert

function os_is_windows ()
local function os_is_windows ()
return package.config:sub(1,1) == '\\'
end

Expand Down
7 changes: 3 additions & 4 deletions pandoc-lua-engine/test/sample.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function Writer (doc, opts)
end

local pipe = pandoc.pipe
local stringify = (require 'pandoc.utils').stringify

-- Choose the image format based on the value of the
-- `image_format` environment variable.
Expand Down Expand Up @@ -80,7 +79,7 @@ end
-- This gives you a fragment. You could use the metadata table to
-- fill variables in a custom lua template. Or, pass `--template=...`
-- to pandoc, and pandoc will do the template processing as usual.
function Doc(body, metadata, variables)
function Doc(body, _metadata, _variables)
local buffer = {}
local function add(s)
table.insert(buffer, s)
Expand Down Expand Up @@ -146,7 +145,7 @@ function Link(s, tgt, tit, attr)
escape(tit,true) .. '"' .. attributes(attr) .. '>' .. s .. '</a>'
end

function Image(s, src, tit, attr)
function Image(_s, src, tit, _attr)
return '<img src="' .. escape(src,true) .. '" title="' ..
escape(tit,true) .. '"/>'
end
Expand Down Expand Up @@ -283,7 +282,7 @@ local function html_align(align)
end
end

function CaptionedImage(src, tit, caption, attr)
function CaptionedImage(src, _tit, caption, attr)
if #caption == 0 then
return '<p><img src="' .. escape(src,true) .. '" id="' .. attr.id ..
'"/></p>'
Expand Down
2 changes: 1 addition & 1 deletion tools/extract-changes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function Pandoc(el)
local newblocks = {}
i = 1
local i = 1
while i <= #el.blocks and
not (el.blocks[i].t == "Header" and el.blocks[i].level == 2) do
i = i+1
Expand Down
6 changes: 3 additions & 3 deletions tools/moduledeps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ end

local transitive = {}

function prind(ind, s)
local function prind(ind, s)
io.write(string.rep(" ",ind) .. s .. "\n")
end

function add_transitive_deps(mod)
local function add_transitive_deps(mod)
if transitive[mod] then
return
end
Expand All @@ -53,7 +53,7 @@ function add_transitive_deps(mod)
end
end

function print_direct_deps(mod, ind)
local function print_direct_deps(mod, ind)
ind = ind or 0
prind(ind, mod)
for dep,_ in pairs(dependencies[mod]) do
Expand Down
11 changes: 5 additions & 6 deletions tools/update-lua-module-docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,9 @@ local function render_type (name, level, modulename)
local properties = Blocks{}
if next(metatable.docs.properties) then
local propattr = {'type-' .. id .. '-properties'}
local attr
properties:insert(Header(level + 1, "Properties", propattr))
for propname, prop in sorted(metatable.docs.properties) do
attr = {'type-' .. nameprefix .. '.' .. name .. '.' .. propname}
local attr = {'type-' .. nameprefix .. '.' .. name .. '.' .. propname}
properties:insert(Header(level + 2, propname, attr))
properties:insert(
Plain(read_inlines(prop.description) ..
Expand All @@ -280,6 +279,7 @@ local function render_type (name, level, modulename)
if next(metatable.methods) then
local attr = {'type-' .. id .. '-methods'}
methods:insert(Header(level + 1, "Methods", attr))
-- luacheck: ignore propname
for propname, method in sorted(metatable.methods) do
-- attr = {'type-' .. modulename .. '.' .. name .. '.' .. propname}
-- methods:insert(Header(level + 2, propname, attr))
Expand Down Expand Up @@ -342,12 +342,11 @@ end
local function render_main_pandoc_module (doc)
local constants_section = Blocks{Header(2, "Constants")}
local fields = List{}
for i, field in ipairs(doc.fields) do
for _, field in ipairs(doc.fields) do
if tostring(field.type) == 'string' then
constants_section:extend(render_field(field, 2, "pandoc"))
elseif field.name:match '^[A-Z]' then
-- Ignore (these are the `Block` and `Inline` tables)
else
-- Ignore (these are the `Block` and `Inline` tables)
elseif not field.name:match '^[A-Z]' then
fields:insert(field)
end
end
Expand Down
4 changes: 2 additions & 2 deletions tools/update-readme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

local f = assert(io.open("MANUAL.txt", "r"))
local manual = f:read("*all")
mdoc = pandoc.read(manual, "markdown")
local mdoc = pandoc.read(manual, "markdown")
f:close()
result = {}
local result = {}

function Div(elem)
local ident = elem.identifier or ""
Expand Down

0 comments on commit a86c913

Please sign in to comment.