lint_tariff/
lint_tariff.rs1#![expect(clippy::unwrap_used, reason = "examples can panic")]
2#![expect(clippy::print_stderr, reason = "examples can log to stderr")]
3
4use ocpi_tariffs::{json, lint, schema, tariff, warning, Version};
5
6fn main() {
7 const TARIFF_JSON: &str = include_str!("data/tariff_misspelled_field.json");
8
9 let doc = json::parse_object(TARIFF_JSON).unwrap();
12 let (tariff, warnings) = tariff::from_json(doc, Version::V221).into_parts();
13
14 let report = tariff::lint(&tariff);
15
16 print_schema_warnings(&warnings);
19 print_lint_warnings(&report.warnings);
20}
21
22fn print_schema_warnings(warnings: &warning::Set<schema::Warning>) {
24 if warnings.is_empty() {
25 return;
26 }
27
28 eprintln!(
29 "WARN: {} schema warnings from the tariff:\n {}",
30 warnings.len_warnings(),
31 warning::SetWriter::new(warnings)
32 );
33}
34
35fn print_lint_warnings(warnings: &warning::Set<lint::tariff::Warning>) {
37 if warnings.is_empty() {
38 return;
39 }
40
41 eprintln!(
42 "WARN: {} warnings from the linting:\n {}",
43 warnings.len_warnings(),
44 warning::SetWriter::new(warnings)
45 );
46}