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

Add builtin standarts for Pandoc filter globals #115

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions docsrc/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ Option Meaning
* ``rockspec`` - globals allowed in rockspecs, by default added for files ending with ``.rockspec``;
* ``luacheckrc`` - globals allowed in Luacheck configs, by default added for files ending with ``.luacheckrc``;
* ``ldoc`` - globals allowed in LDoc config, by default added for files named ``config.ld``;
* ``pandoc`` - globals allowed in Pandoc Lua in any context;
* ``pandoc_filter`` - globals allowed in Pandoc Lua, subset specific to filters;
* ``pandoc_custom`` - globals allowed in Pandoc Lua, subset specific to custom reader/writers;
* ``pandoc_script`` - globals allowed in Pandoc Lua, subset specific to scripts;
* ``sile`` - globals allowed in The SILE Typesetter and its package ecosystem;
* ``none`` - no standard globals.

Expand Down
1 change: 1 addition & 0 deletions luacheck-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ build = {
["luacheck.builtin_standards"] = "src/luacheck/builtin_standards/init.lua",
["luacheck.builtin_standards.love"] = "src/luacheck/builtin_standards/love.lua",
["luacheck.builtin_standards.minetest"] = "src/luacheck/builtin_standards/minetest.lua",
["luacheck.builtin_standards.pandoc"] = "src/luacheck/builtin_standards/pandoc.lua",
["luacheck.builtin_standards.playdate"] = "src/luacheck/builtin_standards/playdate.lua",
["luacheck.builtin_standards.ngx"] = "src/luacheck/builtin_standards/ngx.lua",
["luacheck.cache"] = "src/luacheck/cache.lua",
Expand Down
6 changes: 6 additions & 0 deletions src/luacheck/builtin_standards/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local love = require "luacheck.builtin_standards.love"
local minetest = require "luacheck.builtin_standards.minetest"
local pandoc = require "luacheck.builtin_standards.pandoc"
local playdate = require "luacheck.builtin_standards.playdate"
local ngx = require "luacheck.builtin_standards.ngx"
local standards = require "luacheck.standards"
Expand Down Expand Up @@ -344,6 +345,11 @@ builtin_standards.sile = {
}
}

builtin_standards.pandoc = pandoc.pandoc
builtin_standards.pandoc_filter = pandoc.filter
builtin_standards.pandoc_custom = pandoc.custom
builtin_standards.pandoc_script = pandoc.script

builtin_standards.none = {}

return builtin_standards
61 changes: 61 additions & 0 deletions src/luacheck/builtin_standards/pandoc.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
local add_std_table = require "luacheck.standards".add_std_table

local function combine(...)
local res = {}
for _, def in ipairs({...}) do
add_std_table(res, def)
end
return res.fields
end

local common = {
read_globals = {
"PANDOC_VERSION", "PANDOC_API_VERSION", "PANDOC_STATE",
"pandoc", "lpeg", "re",
},
globals = {
-- document types
"Inlines", "Inline", "Blocks", "Block", "Meta", "Pandoc",
-- inline types
"Cite", "Code", "Emph", "Image", "LineBreak", "Link", "Math", "Note", "Quoted", "RawInline", "SmallCaps",
"SoftBreak", "Space", "Span", "Str", "Strikeout", "Strong", "Subscript", "Superscript", "Underline",
-- block types
"BlockQuote", "BulletList", "CodeBlock", "DefinitionList", "Div", "Figure", "Header", "HorizontalRule",
"LineBlock", "OrderedList", "Para", "Plain", "RawBlock", "Table",
},
}

-- https://pandoc.org/lua-filters.html
local filter = {
read_globals = {
"FORMAT",
"PANDOC_READER_OPTIONS", "PANDOC_WRITER_OPTIONS", "PANDOC_SCRIPT_FILE",
},
}

-- https://pandoc.org/custom-readers.html
-- https://pandoc.org/custom-writers.html
local custom = {
globals = {
-- custom scope
"PANDOC_DOCUMENT",
"PANDOC_READER_OPTIONS", "PANDOC_WRITER_OPTIONS", "PANDOC_SCRIPT_FILE",
"ByteStringReader", "ByteStringWriter", "Doc", "Extensions", "Reader", "Template", "Writer",
-- extra types applicable to readers/writers
"Blocksep", "CaptionedImage", "DisplayMath", "DoubleQuoted", "InlineMath", "SingleQuoted",
},
}

local script = {
globals = {
}
}

local variants = {
pandoc = { globals = combine(common, filter, custom, script) },
filter = { globals = combine(common, filter) },
custom = { globals = combine(common, custom) },
script = { globals = combine(common, script) },
}

return variants
Loading