use crate::DeserializationDiagnostic;
use biome_console::markup;
use biome_rowan::TextRange;
pub trait DeserializableValidator {
fn validate(
&mut self,
name: &str,
range: TextRange,
diagnostics: &mut Vec<DeserializationDiagnostic>,
) -> bool;
}
pub fn non_empty<T: IsEmpty>(
value: &T,
name: &str,
range: TextRange,
diagnostics: &mut Vec<DeserializationDiagnostic>,
) -> bool {
if value.is_empty() {
diagnostics.push(
DeserializationDiagnostic::new(markup! {
<Emphasis>{name}</Emphasis>" may not be empty"
})
.with_range(range),
);
false
} else {
true
}
}
pub trait IsEmpty {
fn is_empty(&self) -> bool;
}
impl IsEmpty for String {
fn is_empty(&self) -> bool {
String::is_empty(self)
}
}
impl<T> IsEmpty for Vec<T> {
fn is_empty(&self) -> bool {
Vec::is_empty(self)
}
}