syncable_cli/analyzer/kubelint/context/
mod.rs

1//! Lint context for Kubernetes objects.
2//!
3//! The lint context holds all parsed Kubernetes objects and provides
4//! access to them during check execution.
5
6pub mod object;
7
8pub use object::{InvalidObject, K8sObject, Object, ObjectMetadata};
9
10/// A lint context provides access to all parsed Kubernetes objects.
11pub trait LintContext: Send + Sync {
12    /// Get all valid parsed objects.
13    fn objects(&self) -> &[Object];
14
15    /// Get all objects that failed to parse.
16    fn invalid_objects(&self) -> &[InvalidObject];
17}
18
19/// Default implementation of LintContext.
20#[derive(Debug, Default)]
21pub struct LintContextImpl {
22    objects: Vec<Object>,
23    invalid_objects: Vec<InvalidObject>,
24}
25
26impl LintContextImpl {
27    /// Create a new empty lint context.
28    pub fn new() -> Self {
29        Self::default()
30    }
31
32    /// Add a valid object to the context.
33    pub fn add_object(&mut self, object: Object) {
34        self.objects.push(object);
35    }
36
37    /// Add an invalid object to the context.
38    pub fn add_invalid_object(&mut self, invalid: InvalidObject) {
39        self.invalid_objects.push(invalid);
40    }
41
42    /// Get a mutable reference to the objects.
43    pub fn objects_mut(&mut self) -> &mut Vec<Object> {
44        &mut self.objects
45    }
46}
47
48impl LintContext for LintContextImpl {
49    fn objects(&self) -> &[Object] {
50        &self.objects
51    }
52
53    fn invalid_objects(&self) -> &[InvalidObject] {
54        &self.invalid_objects
55    }
56}