libscilo/lints/check.rs
1//! Structs and functions to organize and perform lint checks.
2
3use log::info;
4use strum::{EnumIter, EnumString};
5
6use super::LintError;
7use crate::InstantiatedConfig;
8
9/// The linting checks that are currently supported.
10///
11/// Lint codes available in a configuration file are `snake_case` versions of
12/// the enum names here.
13#[derive(Clone, Copy, Debug, strum::Display, EnumIter, EnumString)]
14#[strum(serialize_all = "snake_case")]
15pub enum LintCheck {
16 /// Check that every subdirectory within the project's [`code`][crate::RootDirs::code]
17 /// directory has a corresponding subdirectory with the same name in the
18 /// [`results`][crate::RootDirs::results] directory, and vice versa.
19 CodeResultsSubdirPairing,
20
21 /// All subdirectories within the project's [`code`][crate::RootDirs::code]
22 /// and [`results`][crate::RootDirs::results] directory should
23 /// have names that match the regular expression in
24 /// [`code_results_subdir_regex`][crate::InstantiatedConfig::code_results_subdir_regex].
25 CodeResultsSubdirRegex,
26
27 /// Each subdirectory within the project's [`code`][crate::RootDirs::code]
28 /// directory should contain a README file.
29 CodeSubdirReadmes,
30
31 /// Each subdirectory within the project's [`code`][crate::RootDirs::code]
32 /// directory should contain a workflow file.
33 CodeSubdirWorkflows,
34
35 /// Each subdirectory within the project's [`data`][crate::RootDirs::data]
36 /// directory should contain a README file.
37 DataSubdirReadmes,
38
39 /// Check for a set of required directories that should be present in the
40 /// project's root directory.
41 RootDirs,
42
43 /// Check for a set of required files that should be present in the
44 /// project's root directory.
45 RootFiles,
46}
47
48impl LintCheck {
49 /// Execute a lint check.
50 ///
51 /// This is effectively a large match statement that dispatches the relevant
52 /// checks to other functions.
53 pub fn check(self, cfg: &InstantiatedConfig) -> Result<(), LintError> {
54 info!("Checking lint: {}", self);
55 match self {
56 Self::CodeResultsSubdirPairing => cfg.check_code_results_subdir_pairing(),
57 Self::CodeResultsSubdirRegex => cfg.check_code_results_subdir_regex(),
58 Self::CodeSubdirReadmes => cfg.check_code_subdir_readmes(),
59 Self::CodeSubdirWorkflows => cfg.check_code_subdir_workflows(),
60 Self::DataSubdirReadmes => cfg.check_data_subdir_readmes(),
61 Self::RootDirs => cfg.check_root_dirs(),
62 Self::RootFiles => cfg.check_root_files(),
63 }
64 }
65}