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(crate) 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
46/// The directories that should be placed in the root of a project folder.
47///
48/// Any directory that is listed as an empty string `""` in the configuration
49/// file is counted as an ignored directory that is not required
50/// (i.e. will be stored as `None` in [`InstantiatedConfig`][crate::InstantiatedConfig]).
51#[derive(Clone, Debug, Default, Deserialize)]
52pub(crate) struct ConfigFileRootDirs {
53    /// Top-level path for [`code`][crate::RootDirs::code].
54    pub(super) code: Option<String>,
55
56    /// Top-level path for [`data`][crate::RootDirs::data].
57    pub(super) data: Option<String>,
58
59    /// Top-level path for [documentation][crate::RootDirs::docs].
60    pub(super) docs: Option<String>,
61
62    /// Top-level path for [vendored external code][crate::RootDirs::external].
63    pub(super) external: Option<String>,
64
65    /// Top-level path for [`results`][crate::RootDirs::results].
66    pub(super) results: Option<String>,
67}