Skip to main content

Crate lintel_config

Crate lintel_config 

Source
Expand description

§lintel-config

Crates.io docs.rs CI License

Configuration types and loader for Lintel. Defines the lintel.toml schema, parses config files, and provides utilities for schema URI rewriting and path resolution.

§Features

  • Config typesConfig and Override structs with serde deserialization and JSON Schema generation via schemars
  • Hierarchical loading — walks up the directory tree merging lintel.toml files until root = true
  • URI rewriting — prefix-based rewrite rules with longest-prefix-wins semantics
  • // path resolution — resolve //-prefixed paths relative to the config directory
  • Schema generation — generates the JSON Schema for lintel.toml (used at build time by lintel-check and as a standalone binary)

§Usage

use lintel_config::{find_and_load, apply_rewrites, resolve_double_slash};

// Load config by walking up from a directory
let config = find_and_load(std::path::Path::new("."))
    .unwrap()
    .unwrap_or_default();

// Check for custom schema mappings
if let Some(url) = config.find_schema_mapping("src/config.json", "config.json") {
    println!("Schema: {url}");
}

// Apply rewrite rules and resolve // paths
let uri = apply_rewrites("http://localhost:8000/schema.json", &config.rewrite);
let uri = resolve_double_slash(&uri, std::path::Path::new("/project"));
drop(uri);

§Standalone binary

cargo run -p lintel-config

Prints the JSON Schema for lintel.toml to stdout.

§License

Apache-2.0

Structs§

Config
Override

Functions§

apply_rewrites
Apply rewrite rules to a schema URI. If the URI starts with any key in rewrites, that prefix is replaced with the corresponding value. The longest matching prefix wins.
find_and_load
Search for lintel.toml files starting from start_dir, walking up. Merges all configs found until one with root = true is hit (inclusive). Returns the merged config, or None if no config file was found.
find_config_path
Find the nearest lintel.toml starting from start_dir, walking upward. Returns the path to lintel.toml, or None if not found.
load
Load config from the current working directory (walking upward).
resolve_double_slash
Resolve a //-prefixed path relative to the given root directory (the directory containing lintel.toml). Non-// paths are returned unchanged.
schema
Generate the JSON Schema for lintel.toml as a serde_json::Value.