Expand description
Config and linting engine for declint — no LSP dependencies.
An declint configuration is a YAML file of regex rules:
version: 1
rules:
- id: no-tabs
pattern: '\t+'
message: "Use spaces, found '{match}'"
severity: warningLoad it, lint text, get violations:
use declint_core::{Config, Linter};
use declint_core::{Callbacks, Config, Linter};
let config = Config::from_str(
"version: 1\nrules:\n - id: no-tabs\n pattern: '\\t+'\n message: \"Use \
spaces\"\n severity: warning\n",
)?;
let linter = Linter::new(config, &Callbacks::new())?;
let violations = linter.lint("a\tb");
assert_eq!(violations.len(), 1);
assert_eq!(violations[0].rule_id, "no-tabs");
assert_eq!(violations[0].span.to_range(), 1..2);Everything is validated at load time — regex syntax, placeholder names, duplicate rule ids, unknown severities — so a rule file is either fully usable or rejected with the rule id and file line of the problem.
Rules can also be scoped: a scopes entry segments the file (a
start pattern begins a region, an optional end pattern closes it)
and its rules run only inside those regions — the lint equivalent of
a pass that expands, then subpasses that run per region:
version: 1
scopes:
- id: shell-fence
start: '^```sh$'
end: '^```$'
rules:
- id: no-sudo
pattern: '\bsudo\b'
message: "Don't use sudo in scripts"
severity: errorModules§
- presets
- The embedded preset library: curated config fragments importable as
import: preset:<name>. The embedded preset library: curated config fragments shipped with declint, imported asimport: preset:<name>. - store
- The global ruleset store: packages installed with
declint install -g, resolved byimport: global:<pkg>. The global ruleset store: wheredeclint install -gvendors packages, and whereimport: global:<pkg>finds them.
Structs§
- Callbacks
- A set of registered callbacks and parsers, keyed by name or by
CallbackRefidentity (inline source / file path). Callback and parser keys live in separate namespaces — the same name can name a callback for one rule and a parser for another. - Config
- A validated configuration: the schema version, global rules, and scopes.
- Config
Error - Everything that can go wrong while loading a config file.
- Config
Set - A set of config files loaded together — the whole
.declint.yaml, or everything in a.declint/directory. - DocInfo
- Per-document information callbacks can see: the file’s path and language id. Empty strings are fine when the caller has neither.
- Linter
- A compiled, ready-to-run rule set.
- Match
Context - Everything a callback knows about one match.
- Named
Config - One config file loaded as part of a
ConfigSet. - RawMatch
- One match found by a
MatchParser, in coordinates relative to the scanned text (add the scan offset for absolute positions). - Rule
- One validated lint rule.
- Rule
Test - One embedded rule test: a snippet and what the rule should do with
it. Run by
declint test. - Scope
- One validated scope: a segmenter (
start/end) plus the rules that run only inside its regions. - Scope
Entry - One scope from a
ConfigSet, with its position in the set: which config it belongs to and its index within that config. - Span
- A byte range in the linted source.
- Suppressions
- The suppressions found in one source snapshot.
- Template
- A rule message with placeholders resolved per match.
- Violation
- One rule hit: where, how bad, and the rendered message.
Enums§
- Callback
Ref - A rule’s reference to its callback or parser, as written in the config.
- Decision
- What a callback decided about one match.
- Severity
- How serious a violation is.
Constants§
- CONFIG_
DIR - The hidden config directory:
.declint/(every*.yamlinside is a config). - CONFIG_
FILE - The hidden config file:
.declint.yaml. - LEGACY_
CONFIG_ FILE - The legacy, non-hidden config file, still accepted last.
- SUPPORTED_
VERSION - The config schema version this declint understands.
Traits§
- Match
Callback - A callback implementation. Must be pure with respect to the match: same input, same decision.
- Match
Parser - A custom matcher: finds every hit for a rule in one scan unit (the whole file for global rules, a scope region for scoped rules).
Functions§
- language_
from_ extension - The language id for
path’s extension, orNonewhen unknown. - line_
col - Converts a byte offset to a 1-based
(line, column)pair for human-readable output. The column counts characters, not bytes, so it matches what most editors show. - segment
- Finds the regions of one scope in
source. - segment_
all - Segments
sourcefor every scope, as(scope index, region)pairs sorted by position (scope order breaks ties). Regions from different scopes may overlap — each scope’s family is independent.