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