Skip to main content

Crate declint_lua

Crate declint_lua 

Source
Expand description

Lua match callbacks for declint.

A rule’s callback: value can be an inline Lua snippet (a block scalar) or a file path (checks/foo.lua, relative to the config file). attach compiles every such reference, registers it in the callback registry, and from then on the linter calls it per match.

§Contract

The snippet is a Lua chunk that returns the callback function (helpers and locals above the return just work):

return function(ctx)
  -- ctx.match      the matched text
  -- ctx.captures   { name = "..." } / { ["1"] = "..." }
  -- ctx.start      absolute byte offset
  -- ctx.finish     byte offset past the match
  -- ctx.line, ctx.col   1-based position of the match
  -- ctx.path, ctx.language, ctx.rule
end

Return values:

  • nil / false — allow: no diagnostic for this match;
  • true — violate with the rule’s own message template;
  • { message = "...", severity = "error" } — violate with overrides (severity optional, falls back to the rule’s severity);
  • a thrown Lua error — surfaced as an error-severity diagnostic naming the rule; the lint run itself is never affected.

Each call runs under an instruction budget, so a runaway loop fails instead of hanging the editor.

§Examples

use declint_core::{CallbackRef, Callbacks, ConfigSet};
let set = ConfigSet::discover(&dir)?;
let mut callbacks = Callbacks::new();
declint_lua::attach(&set, &mut callbacks)?;
assert!(!callbacks.is_empty());

Structs§

LuaCallback
A compiled Lua callback.
LuaParser
A compiled Lua parser: finds all matches for a rule in one call.

Functions§

attach
Compiles every inline and file callback and parser in set and registers them in callbacks. File paths resolve relative to each config file.