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::{guess, lint, tariff, warning, Version};
5
6fn main() {
7 const TARIFF_JSON: &str =
8 include_str!("../test_data/v221/real_world/misspelled_field/tariff.json");
9
10 let report = tariff::parse_and_report(TARIFF_JSON).unwrap();
11 let guess::Report {
12 unexpected_fields,
13 version,
14 } = report;
15
16 if !unexpected_fields.is_empty() {
17 eprintln!("Strange... there are fields in the tariff that are not defined in the spec.");
18
19 for path in &unexpected_fields {
20 eprintln!(" * {path}");
21 }
22
23 eprintln!();
24 }
25
26 let tariff = version.certain_or(Version::V221);
27 let report = tariff::lint(&tariff);
28
29 print_lint_warnings(&report.warnings);
30}
31
32fn print_lint_warnings(warnings: &warning::Set<lint::tariff::Warning>) {
33 if warnings.is_empty() {
34 return;
35 }
36
37 eprintln!(
38 "WARN: {} warnings from the linting:\n {}",
39 warnings.len_warnings(),
40 warning::SetWriter::new(warnings)
41 );
42}