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_inputs;
29mod config_writer;
30mod external_plugin;
31mod fixability;
32/// JSONC parsing helpers pinning the dialect fallow accepts.
33pub mod jsonc;
34pub mod levenshtein;
35mod rule_pack;
36mod workspace;
37
38pub use config::*;
39pub use config_inputs::*;
40pub use config_writer::*;
41pub use external_plugin::*;
42pub use fixability::*;
43pub use rule_pack::*;
44pub use workspace::*;
45
46use std::path::{Path, PathBuf};
47
48/// Basename of the local walkthrough viewed-state ledger inside the cache dir.
49const WALKTHROUGH_STATE_FILE: &str = "walkthrough-state.json";
50
51/// Path to the local `fallow review --walkthrough` viewed-state ledger inside a
52/// resolved cache directory (default `<root>/.fallow`, already gitignored).
53///
54/// Pure path join, mirroring the `cache.bin` / `graph-cache.bin` / `churn.bin`
55/// conventions; the file IO and serde live in the CLI crate to keep this crate
56/// free of side effects.
57#[must_use]
58pub fn walkthrough_state_path(cache_dir: &Path) -> PathBuf {
59 cache_dir.join(WALKTHROUGH_STATE_FILE)
60}
61
62#[cfg(test)]
63mod walkthrough_state_path_tests {
64 use super::walkthrough_state_path;
65 use std::path::Path;
66
67 #[test]
68 fn joins_state_file_under_cache_dir() {
69 let path = walkthrough_state_path(Path::new("/project/.fallow"));
70 assert_eq!(path, Path::new("/project/.fallow/walkthrough-state.json"));
71 }
72}