Skip to main content

fallow_config/
lib.rs

1//! Configuration loading and resolution for fallow.
2//!
3//! Owns the user-facing config model ([`FallowConfig`] and its sections),
4//! config-file discovery and `extends` inheritance, validation of
5//! user-supplied globs and patterns, and resolution into the pre-compiled
6//! [`ResolvedConfig`] the analysis crates consume. Also hosts workspace and
7//! `package.json` discovery, declarative external plugin definitions, rule
8//! packs, and the in-place config editing used by `fallow fix`.
9//!
10//! Config section structs such as [`RulesConfig`] are not `#[non_exhaustive]`
11//! and gain new public fields in minor releases as rules are added, so
12//! exhaustive struct literals in downstream code are source-breaking on
13//! upgrade. Construct them with struct update syntax, for example
14//! `RulesConfig { unused_files: Severity::Off, ..RulesConfig::default() }`,
15//! to stay source-compatible.
16
17#![warn(missing_docs)]
18#![cfg_attr(
19    test,
20    allow(
21        clippy::unwrap_used,
22        clippy::expect_used,
23        reason = "tests use unwrap and expect to keep fixture setup concise"
24    )
25)]
26
27mod config;
28mod config_writer;
29mod external_plugin;
30mod fixability;
31/// JSONC parsing helpers pinning the dialect fallow accepts.
32pub mod jsonc;
33pub mod levenshtein;
34mod rule_pack;
35mod workspace;
36
37pub use config::*;
38pub use config_writer::*;
39pub use external_plugin::*;
40pub use fixability::*;
41pub use rule_pack::*;
42pub use workspace::*;
43
44use std::path::{Path, PathBuf};
45
46/// Basename of the local walkthrough viewed-state ledger inside the cache dir.
47const WALKTHROUGH_STATE_FILE: &str = "walkthrough-state.json";
48
49/// Path to the local `fallow review --walkthrough` viewed-state ledger inside a
50/// resolved cache directory (default `<root>/.fallow`, already gitignored).
51///
52/// Pure path join, mirroring the `cache.bin` / `graph-cache.bin` / `churn.bin`
53/// conventions; the file IO and serde live in the CLI crate to keep this crate
54/// free of side effects.
55#[must_use]
56pub fn walkthrough_state_path(cache_dir: &Path) -> PathBuf {
57    cache_dir.join(WALKTHROUGH_STATE_FILE)
58}
59
60#[cfg(test)]
61mod walkthrough_state_path_tests {
62    use super::walkthrough_state_path;
63    use std::path::Path;
64
65    #[test]
66    fn joins_state_file_under_cache_dir() {
67        let path = walkthrough_state_path(Path::new("/project/.fallow"));
68        assert_eq!(path, Path::new("/project/.fallow/walkthrough-state.json"));
69    }
70}