libscilo/config/file.rs
1//! Working with the configuration file written by the user.
2
3use serde::Deserialize;
4
5/// A temporary structure used to parse configuration files within a directory.
6///
7/// This temporary structure partially goes against the "parse, don't validate"
8/// maxim, but it is necessary for combining multiple configurations together
9/// from different locations on a user's system.
10///
11/// Every field within this struct is an [`Option`] or a [`Vec`], which allows
12/// the configuration files to be partially specified.
13/// Not every field needs to be included in every file, which is much more
14/// user-friendly.
15///
16/// Instead of using the `ConfigFile` directly, we will instantiate a set of configuration
17/// settings for all files within a given directory.
18/// [`InstantiatedConfig`][crate::InstantiatedConfig] contains the settings that
19/// will be used to lint all files within a given directory.
20#[derive(Clone, Debug, Default, Deserialize)]
21pub struct ConfigFile {
22 /// Required directories at the project root.
23 ///
24 /// See [`RootDirs`][crate::RootDirs] for details.
25 pub(super) root_dirs: Option<ConfigFileRootDirs>,
26
27 /// Required files at the project root.
28 pub(super) root_files: Option<Vec<String>>,
29
30 /// Regular expression for units of analysis within the code and their matching results.
31 pub(super) code_results_subdir_regex: Option<String>,
32
33 /// Names of the checks that should be performed when running the `lint` subcommand.
34 pub(super) lints: Option<Vec<String>>,
35
36 /// Acceptable file names for the READMEs that should be present within each
37 /// subdirectory in the [`code`][crate::RootDirs::code] and
38 /// [`data`][crate::RootDirs::data] directories.
39 pub(super) readme_names: Option<Vec<String>>,
40
41 /// Acceptable file names for the workflow files that should be present
42 /// within each subdirectory in the [`code`][crate::RootDirs::code]
43 pub(super) workflow_names: Option<Vec<String>>,
44
45 /// An array of paths that are ignored during checks.
46 /// These can be absolute paths or paths relative to the project root.
47 pub ignored: Option<Vec<String>>,
48}
49
50/// The directories that should be placed in the root of a project folder.
51///
52/// Any directory that is listed as an empty string `""` in the configuration
53/// file is counted as an ignored directory that is not required
54/// (i.e. will be stored as `None` in [`InstantiatedConfig`][crate::InstantiatedConfig]).
55#[derive(Clone, Debug, Default, Deserialize)]
56pub(crate) struct ConfigFileRootDirs {
57 /// Top-level path for [`code`][crate::RootDirs::code].
58 pub(super) code: Option<String>,
59
60 /// Top-level path for [`data`][crate::RootDirs::data].
61 pub(super) data: Option<String>,
62
63 /// Top-level path for [documentation][crate::RootDirs::docs].
64 pub(super) docs: Option<String>,
65
66 /// Top-level path for [vendored external code][crate::RootDirs::external].
67 pub(super) external: Option<String>,
68
69 /// Top-level path for [`results`][crate::RootDirs::results].
70 pub(super) results: Option<String>,
71}