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