luacheck
luacheck copied to clipboard
Unable to define custom sets of globals when using luacheck as module
.luacheckrc:
return {
stds = {custom={}},
std = "_G+custom",
}
This works as expected using luacheck cmdline utility.
But it fails when I try to pass same table as arg of luacheck.check_strings
function.
In this case I get such error:
init.lua:20: bad argument #2 to 'luacheck.check_strings'
(invalid value of option 'std')
Currently Lua interface does not read luacheck config. See #107. As a workaround, if you want to use config from Lua, you'd have to execute luacheck command line with io.popen and parse its output.
I know that luacheck module interface does not read config files, but my issue is about other problem. I just want to use custom set of globals, like this:
local text = [[some_code]]
local options = {
stds = {custom={}}, --some custom set (actually 2 sets for Far Manager)
std = "_G+custom",
}
local report = luacheck.check_strings({text}, options)[1]
Ah, I remember where I saw your username now :smile:
Yes, I agree that it should be possible to add custom sets of globals without using config. As a hack you could mutate built-in standards:
local builtin_standards = require "luacheck.builtin_standards"
builtin_standards.custom = {...}
But a proper way would be to accept stds
option in luacheck.check_strings
and the like.
Thank you very much, for now will use the hack you've suggested.
And I have another question, about custom globals sets when using commandline utility.
.luacheckrc
works fine, but what if I have several projects with own .luacheckrc
configs?
In this case I would prefer to define sets of global in one common file.
It is not possible now, only one config file allowed.
I wonder if luacheck could support several --config
arguments and read several config files (ideally with possibility to override values).
Yes, it would be useful to be able to specify a parent config to use as base in some way. It should be possible to do that in config itself, too, not only on the command-line. I'm not yet sure how they should be specified. It depends on the way these base configs are distributed.
For sharing custom sets of globals it's possible to put them in a module, e.g. luacheck.std.custom
, and then use stds.custom = require "luacheck.std.custom"
in all configs.