diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml
new file mode 100644
index 000000000000..83f552b94806
--- /dev/null
+++ b/.github/workflows/luacheck.yml
@@ -0,0 +1,13 @@
+name: Luacheck
+
+on: [ push, pull_request ]
+
+jobs:
+
+ luacheck:
+ runs-on: ubuntu-22.04
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ - name: Luacheck
+ uses: lunarmodules/luacheck@v1
diff --git a/.luacheckrc b/.luacheckrc
new file mode 100644
index 000000000000..fe49afb937d0
--- /dev/null
+++ b/.luacheckrc
@@ -0,0 +1,27 @@
+std = "lua54"
+
+max_line_length = false
+
+files["**/test/lua/**"] = {
+ std = "+pandoc_filter"
+}
+
+files["**/test/*.lua"] = {
+ std = "+pandoc_custom"
+}
+
+files["data/**"] = {
+ std = "+pandoc_custom"
+}
+
+files["tools/**"] = {
+ std = "+pandoc_custom"
+}
+
+files["man/**"] = {
+ std = "+pandoc_script"
+}
+
+exclude_files = {
+ ".stack-work"
+}
diff --git a/data/creole.lua b/data/creole.lua
index 590dfc87179d..9084cb5efe40 100644
--- a/data/creole.lua
+++ b/data/creole.lua
@@ -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("/*~[]\\{}|")
@@ -52,7 +50,7 @@ local function ListItem(lev, ch)
end
-- Grammar
-G = P{ "Doc",
+local grammar = P{ "Doc",
Doc = Ct(V"Block"^0)
/ pandoc.Pandoc ;
Block = blankline^0
@@ -185,6 +183,6 @@ G = P{ "Doc",
/ pandoc.Strong ;
}
-function Reader(input, reader_options)
- return lpeg.match(G, tostring(input))
+function Reader(input, _reader_options)
+ return lpeg.match(grammar, tostring(input))
end
diff --git a/man/manfilter.lua b/man/manfilter.lua
index 6abd950fc7e1..b7797feb305c 100644
--- a/man/manfilter.lua
+++ b/man/manfilter.lua
@@ -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
@@ -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")
@@ -39,6 +39,6 @@ function Link(el)
end
-- remove notes
-function Note(el)
+function Note(_el)
return {}
end
diff --git a/pandoc-lua-engine/test/bytestring-reader.lua b/pandoc-lua-engine/test/bytestring-reader.lua
index 7908479ecb75..27ed0a8bbcd0 100644
--- a/pandoc-lua-engine/test/bytestring-reader.lua
+++ b/pandoc-lua-engine/test/bytestring-reader.lua
@@ -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)))
diff --git a/pandoc-lua-engine/test/bytestring.lua b/pandoc-lua-engine/test/bytestring.lua
index f872e28d497d..4499e8e839ab 100644
--- a/pandoc-lua-engine/test/bytestring.lua
+++ b/pandoc-lua-engine/test/bytestring.lua
@@ -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))
diff --git a/pandoc-lua-engine/test/extensions.lua b/pandoc-lua-engine/test/extensions.lua
index d286f5c416b0..538f5ede042d 100644
--- a/pandoc-lua-engine/test/extensions.lua
+++ b/pandoc-lua-engine/test/extensions.lua
@@ -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'
diff --git a/pandoc-lua-engine/test/lua/block-count.lua b/pandoc-lua-engine/test/lua/block-count.lua
index 508b05ea8733..0a54e45df878 100644
--- a/pandoc-lua-engine/test/lua/block-count.lua
+++ b/pandoc-lua-engine/test/lua/block-count.lua
@@ -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)}
}
diff --git a/pandoc-lua-engine/test/lua/hello-world-doc.lua b/pandoc-lua-engine/test/lua/hello-world-doc.lua
index 62236584e6b7..890d320ffa5e 100644
--- a/pandoc-lua-engine/test/lua/hello-world-doc.lua
+++ b/pandoc-lua-engine/test/lua/hello-world-doc.lua
@@ -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) }
diff --git a/pandoc-lua-engine/test/lua/implicit-doc-filter.lua b/pandoc-lua-engine/test/lua/implicit-doc-filter.lua
index f053dc1b2483..6ae03d898945 100644
--- a/pandoc-lua-engine/test/lua/implicit-doc-filter.lua
+++ b/pandoc-lua-engine/test/lua/implicit-doc-filter.lua
@@ -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) }
diff --git a/pandoc-lua-engine/test/lua/inlines-filter.lua b/pandoc-lua-engine/test/lua/inlines-filter.lua
index 69608bd77a34..54a76fa82c88 100644
--- a/pandoc-lua-engine/test/lua/inlines-filter.lua
+++ b/pandoc-lua-engine/test/lua/inlines-filter.lua
@@ -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
diff --git a/pandoc-lua-engine/test/lua/metatable-catch-all.lua b/pandoc-lua-engine/test/lua/metatable-catch-all.lua
index 05df16bbf875..f36fad7a772f 100644
--- a/pandoc-lua-engine/test/lua/metatable-catch-all.lua
+++ b/pandoc-lua-engine/test/lua/metatable-catch-all.lua
@@ -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)}
}
diff --git a/pandoc-lua-engine/test/lua/module/pandoc-list.lua b/pandoc-lua-engine/test/lua/module/pandoc-list.lua
index 27790ce96cee..de1da8117284 100644
--- a/pandoc-lua-engine/test/lua/module/pandoc-list.lua
+++ b/pandoc-lua-engine/test/lua/module/pandoc-list.lua
@@ -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)
@@ -109,25 +109,25 @@ 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 _ = primes:map(function (x) return x^2 end)
assert.are_same({2, 3, 5, 7}, primes)
end)
},
group 'new' {
test('make table usable as list', function ()
- local test = List:new{1, 1, 2, 3, 5}
+ local out = List:new{1, 1, 2, 3, 5}
assert.are_same(
{1, 1, 4, 9, 25},
- test:map(function (x) return x^2 end)
+ out:map(function (x) return x^2 end)
)
end),
test('return empty list if no argument is given', function ()
assert.are_same({}, List:new())
end),
test('metatable of result is pandoc.List', function ()
- local test = List:new{5}
- assert.are_equal(List, getmetatable(test))
+ local out = List:new{5}
+ assert.are_equal(List, getmetatable(out))
end)
},
diff --git a/pandoc-lua-engine/test/lua/module/pandoc-structure.lua b/pandoc-lua-engine/test/lua/module/pandoc-structure.lua
index af19785c92a5..bc3b661e2491 100644
--- a/pandoc-lua-engine/test/lua/module/pandoc-structure.lua
+++ b/pandoc-lua-engine/test/lua/module/pandoc-structure.lua
@@ -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
diff --git a/pandoc-lua-engine/test/lua/module/pandoc-template.lua b/pandoc-lua-engine/test/lua/module/pandoc-template.lua
index 65e0798f5c38..8e32e072badc 100644
--- a/pandoc-lua-engine/test/lua/module/pandoc-template.lua
+++ b/pandoc-lua-engine/test/lua/module/pandoc-template.lua
@@ -25,7 +25,7 @@ return {
)
end),
test('fails on unknown format', function ()
- local success, msg = pcall(function ()
+ local success, _ = pcall(function ()
return pandoc.utils.type(template.default 'nosuchformat')
end)
assert.is_falsy(success)
@@ -42,7 +42,7 @@ return {
)
end),
test('fails on non-existent file', function ()
- local success, msg = pcall(function ()
+ local success, _ = pcall(function ()
return pandoc.utils.type(template.get 'nosuchfile.nope')
end)
assert.is_falsy(success)
diff --git a/pandoc-lua-engine/test/lua/module/pandoc-utils.lua b/pandoc-lua-engine/test/lua/module/pandoc-utils.lua
index 573a5987ae5d..2c6f20da4c00 100644
--- a/pandoc-lua-engine/test/lua/module/pandoc-utils.lua
+++ b/pandoc-lua-engine/test/lua/module/pandoc-utils.lua
@@ -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')
@@ -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",
diff --git a/pandoc-lua-engine/test/lua/module/pandoc.lua b/pandoc-lua-engine/test/lua/module/pandoc.lua
index 5df547d2420e..99fee675a400 100644
--- a/pandoc-lua-engine/test/lua/module/pandoc.lua
+++ b/pandoc-lua-engine/test/lua/module/pandoc.lua
@@ -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
diff --git a/pandoc-lua-engine/test/sample.lua b/pandoc-lua-engine/test/sample.lua
index 0294cfbaf899..8e61e488bf1d 100644
--- a/pandoc-lua-engine/test/sample.lua
+++ b/pandoc-lua-engine/test/sample.lua
@@ -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.
@@ -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)
@@ -146,7 +145,7 @@ function Link(s, tgt, tit, attr)
escape(tit,true) .. '"' .. attributes(attr) .. '>' .. s .. ''
end
-function Image(s, src, tit, attr)
+function Image(_s, src, tit, _attr)
return ''
end
@@ -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 '