Skip to main content

declint_core/
presets.rs

1//! The embedded preset library: curated config fragments shipped with
2//! declint, imported as `import: preset:<name>`.
3//!
4//! The presets are ordinary YAML config files living in this crate's
5//! `presets/` directory (so they ship inside the published package) and
6//! embedded at compile time — binaries are self-contained, and CI needs
7//! nothing beyond the executable.
8
9/// One embedded preset.
10pub struct Preset {
11    /// The name used in `import: preset:<name>`.
12    pub name: &'static str,
13    /// One-line summary shown by `declint presets`.
14    pub description: &'static str,
15    /// The full YAML content.
16    pub content: &'static str,
17}
18
19/// Every embedded preset, in display order.
20pub static PRESETS: &[Preset] = &[
21    Preset {
22        name: "python",
23        description: "Python: PEP 8 warm-ups, == None, mutable defaults, \
24                      docstrings, top-level function/class scopes",
25        content: include_str!("../presets/python.yaml"),
26    },
27    Preset {
28        name: "ini",
29        description: "INI: tabs, trailing whitespace, empty values, \
30                      duplicate keys, a [server] section example",
31        content: include_str!("../presets/ini.yaml"),
32    },
33    Preset {
34        name: "markdown",
35        description: "Markdown: tabs, trailing whitespace, bare URLs",
36        content: include_str!("../presets/markdown.yaml"),
37    },
38    Preset {
39        name: "sh",
40        description: "Shell: rm with variables, sudo, [ x == y ], \
41                      missing shebang, strict-mode suggestion",
42        content: include_str!("../presets/sh.yaml"),
43    },
44    Preset {
45        name: "dockerfile",
46        description: "Dockerfile: unpinned/latest FROM, sudo in RUN, \
47                      ADD vs COPY, apt cleanup, missing HEALTHCHECK",
48        content: include_str!("../presets/dockerfile.yaml"),
49    },
50    Preset {
51        name: "toml",
52        description: "TOML: tabs, trailing whitespace, empty values, \
53                      spacing, duplicate keys per section",
54        content: include_str!("../presets/toml.yaml"),
55    },
56    Preset {
57        name: "json",
58        description: "JSON: trailing commas, single-quoted strings, \
59                      unquoted keys, comments",
60        content: include_str!("../presets/json.yaml"),
61    },
62    Preset {
63        name: "javascript",
64        description: "JavaScript: == vs ===, var declarations, \
65                      leftover console.log",
66        content: include_str!("../presets/javascript.yaml"),
67    },
68];
69
70/// Looks up an embedded preset by name.
71pub fn lookup(name: &str) -> Option<&'static Preset> {
72    PRESETS.iter().find(|preset| preset.name == name)
73}
74
75/// The names of every embedded preset, comma-separated — for error
76/// messages ("unknown preset `x` (available: python, ini, markdown)").
77pub fn names() -> String {
78    PRESETS
79        .iter()
80        .map(|preset| preset.name)
81        .collect::<Vec<_>>()
82        .join(", ")
83}