luacheck icon indicating copy to clipboard operation
luacheck copied to clipboard

Add higher level Lua interface that can load config

Open mpeterv opened this issue 8 years ago • 2 comments

Currently functions in public luacheck module do not load config, which limits their usability when embedding luacheck in an editor with Lua interface (e.g. dit, far). Implement a new interface that uses config and possibly other features available from CLI but not current luacheck module: multithreading, caching.

mpeterv avatar Apr 26 '17 19:04 mpeterv

This will be added in the next version (0.24.0), interface draft:

-- `options` may include `config`/`default_config` fields specifying how
-- the config should be loaded, and all the fields allowed in config
-- including `stds` and `files`.
local checker, err = luacheck.new_checker(options)

if not checker then
   -- Prints one of:
   -- `options_validation`, `config_location`,
   -- `config_load`, `config_validation`, `cache_read`, `cache_write`.
   print(err.type)
   -- Prints a readable message:
   print(err.message)
end

-- `inputs` - an array of tables.
-- Each table specifies an input:
-- * if `string` field is present, checks the string.
-- * if `path` field is present, checks file or directory with that path.
-- * if `file_handler` is present, reads the file handler with `:read("*a")`
--   and checks that.
-- Additional fields:
-- * `name`: file name used for applying per-path options from config instead of `path`.
-- * `label`: label used in formatted report for this input.
-- Returns report in the same format as current `luacheck.check_files`.
local report = checker:check(inputs)

-- Returns formatted report as a string.
local formatted_report = checker:format_report(report)

mpeterv avatar Oct 12 '18 10:10 mpeterv

@Alloyed @johnd0e you may be interested in this

mpeterv avatar Oct 12 '18 10:10 mpeterv