Skip to main content

Crate declint_core

Crate declint_core 

Source
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: warning

Load 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: error

Modules§

presets
The embedded preset library: curated config fragments importable as import: preset:<name>. The embedded preset library: curated config fragments shipped with declint, imported as import: preset:<name>.
store
The global ruleset store: packages installed with declint install -g, resolved by import: global:<pkg>. The global ruleset store: where declint install -g vendors packages, and where import: global:<pkg> finds them.

Structs§

Callbacks
A set of registered callbacks and parsers, keyed by name or by CallbackRef identity (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.
ConfigError
Everything that can go wrong while loading a config file.
ConfigSet
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.
MatchContext
Everything a callback knows about one match.
NamedConfig
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.
RuleTest
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.
ScopeEntry
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§

CallbackRef
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 *.yaml inside 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§

MatchCallback
A callback implementation. Must be pure with respect to the match: same input, same decision.
MatchParser
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, or None when 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 source for 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.