ignore_files/lib.rs
1//! Find, parse, and interpret ignore files.
2//!
3//! Ignore files are files that contain ignore patterns, often following the `.gitignore` format.
4//! There may be one or more global ignore files, which apply everywhere, and one or more per-folder
5//! ignore files, which apply to a specific folder and its subfolders. Furthermore, there may be
6//! more ignore files in _these_ subfolders, and so on. Discovering and interpreting all of these in
7//! a single context is not a simple task: this is what this crate provides.
8
9#![cfg_attr(not(test), warn(unused_crate_dependencies))]
10
11use std::path::{Path, PathBuf};
12
13use normalize_path::NormalizePath;
14use project_origins::ProjectType;
15
16#[doc(inline)]
17pub use discover::*;
18mod discover;
19
20#[doc(inline)]
21pub use error::*;
22mod error;
23
24#[doc(inline)]
25pub use filter::*;
26mod filter;
27
28/// An ignore file.
29///
30/// This records both the path to the ignore file and some basic metadata about it: which project
31/// type it applies to if any, and which subtree it applies in if any (`None` = global ignore file).
32#[derive(Debug, Clone, PartialEq, Eq, Hash)]
33pub struct IgnoreFile {
34 /// The path to the ignore file.
35 pub path: PathBuf,
36
37 /// The path to the subtree the ignore file applies to, or `None` for global ignores.
38 pub applies_in: Option<PathBuf>,
39
40 /// Which project type the ignore file applies to, or was found through.
41 pub applies_to: Option<ProjectType>,
42}
43
44pub(crate) fn simplify_path(path: &Path) -> PathBuf {
45 dunce::simplified(path).normalize()
46}