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(not(test), deny(clippy::disallowed_methods))]
19#![cfg_attr(
20 test,
21 allow(
22 clippy::unwrap_used,
23 clippy::expect_used,
24 reason = "tests use unwrap and expect to keep fixture setup concise"
25 )
26)]
27
28mod config;
29mod config_inputs;
30mod config_writer;
31mod external_plugin;
32/// Extglob groups, such as `!(*.spec)`, rewritten for `globset`.
33pub mod extglob;
34mod fixability;
35/// JSONC parsing helpers pinning the dialect fallow accepts.
36pub mod jsonc;
37pub mod levenshtein;
38mod rule_pack;
39mod source_walk;
40mod workspace;
41/// YAML parsing behind one internal API.
42pub mod yaml;
43
44pub use config::*;
45pub use config_inputs::*;
46pub use config_writer::*;
47pub use external_plugin::*;
48pub use fixability::*;
49pub use rule_pack::*;
50pub use source_walk::*;
51pub use workspace::*;
52
53use std::path::{Path, PathBuf};
54
55/// Basename of the local walkthrough viewed-state ledger inside the cache dir.
56const WALKTHROUGH_STATE_FILE: &str = "walkthrough-state.json";
57
58/// Path to the local `fallow review --walkthrough` viewed-state ledger inside a
59/// resolved cache directory (default `<root>/.fallow`, already gitignored).
60///
61/// Pure path join, mirroring the `cache.bin` / `graph-cache.bin` / `churn.bin`
62/// conventions; the file IO and serde live in the CLI crate to keep this crate
63/// free of side effects.
64#[must_use]
65pub fn walkthrough_state_path(cache_dir: &Path) -> PathBuf {
66 cache_dir.join(WALKTHROUGH_STATE_FILE)
67}
68
69#[cfg(test)]
70mod walkthrough_state_path_tests {
71 use super::walkthrough_state_path;
72 use std::path::Path;
73
74 #[test]
75 fn joins_state_file_under_cache_dir() {
76 let path = walkthrough_state_path(Path::new("/project/.fallow"));
77 assert_eq!(path, Path::new("/project/.fallow/walkthrough-state.json"));
78 }
79}