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