Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture unrecognized fields with lint #851

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 48 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ itertools = "0.12"
libc = "0.2.80"
miette = "7.0"
nix = { version = "0.27.1", features = ["mount", "sched", "user"] }
ngrammatic = "0.4.0"
nom = "7.1"
nom-supreme = "0.8"
once_cell = "1.8"
Expand Down Expand Up @@ -135,6 +136,7 @@ spk-storage = { path = "crates/spk-storage" }
static_assertions = "1.1"
strip-ansi-escapes = "0.2.0"
strum = { version = "0.26.1", features = ["derive"] }
struct-field-names-as-array = "0.3.0"
tempfile = "3.3"
thiserror = "1.0"
tokio = { version = "1.39", features = ["rt"] }
Expand Down
26 changes: 21 additions & 5 deletions crates/spk-cli/group4/src/cmd_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use clap::Args;
use colored::Colorize;
use miette::Result;
use spk_cli_common::{flags, CommandArgs, Run};
use spk_schema::{SpecTemplate, Template, TemplateExt};
use spk_schema::v0::Spec;
use spk_schema::Lint::Key;
use spk_schema::{AnyIdent, LintedItem, SpecTemplate, Template, TemplateExt};

/// Validate spk yaml files
#[derive(Args)]
Expand All @@ -25,12 +27,26 @@ impl Run for Lint {
type Output = i32;

async fn run(&mut self) -> Result<Self::Output> {
let options = self.options.get_options()?;
let mut out = 0;
let options = self.options.get_options()?;
for spec in self.packages.iter() {
let result = SpecTemplate::from_file(spec).and_then(|t| t.render(&options));
match result {
Ok(_) => println!("{} {}", "OK".green(), spec.display()),
let yaml = SpecTemplate::from_file(spec).and_then(|t| t.render_to_string(&options))?;
let lints: std::result::Result<LintedItem<Spec<AnyIdent>>, serde_yaml::Error> =
serde_yaml::from_str(&yaml);

match lints {
Ok(s) => match s.lints.is_empty() {
true => println!("{} {}", "OK".green(), spec.display()),
false => {
println!("{} {}:", "Failed".red(), spec.display());
for lint in s.lints {
match lint {
Key(k) => println!("{} {}", "----->".red(), k.generate_message()),
}
}
out = 1;
}
},
Err(err) => {
println!(
"{} {}:\n{} {err}",
Expand Down
2 changes: 2 additions & 0 deletions crates/spk-schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ format_serde_error = { version = "0.3", default-features = false, features = [
ignore = "0.4.18"
indexmap = { workspace = true }
itertools = { workspace = true }
ngrammatic = { workspace = true }
nom = { workspace = true }
regex = { workspace = true }
relative-path = { workspace = true }
Expand All @@ -41,6 +42,7 @@ spk-schema-foundation = { workspace = true }
spk-schema-ident = { workspace = true }
spk-schema-tera = { workspace = true }
strum = { workspace = true }
struct-field-names-as-array = { workspace = true }
sys-info = "0.9.0"
tempfile = { workspace = true }
thiserror = { workspace = true }
Expand Down
Loading
Loading