Skip to content

Commit 77fbd44

Browse files
author
Nichol Yip
committed
add more context in linted message.
Signed-off-by: Nichol Yip <[email protected]>
1 parent 1d3dd1d commit 77fbd44

File tree

8 files changed

+15
-16
lines changed

8 files changed

+15
-16
lines changed

crates/spk-schema/src/build_spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl<'de> serde::de::Visitor<'de> for BuildSpecVisitor {
507507
"auto_host_vars" => unchecked.auto_host_vars = map.next_value::<AutoHostVars>()?,
508508
unknown_key => {
509509
self.lints.push(Lint::Key(UnknownKey::new(
510-
unknown_key,
510+
&format!("build.{unknown_key}"),
511511
BuildSpec::FIELD_NAMES_AS_ARRAY.to_vec(),
512512
)));
513513
map.next_value::<serde::de::IgnoredAny>()?;

crates/spk-schema/src/environ.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,4 +526,4 @@ impl SetEnv {
526526
pub fn tcsh_source(&self) -> String {
527527
format!("setenv {} \"{}\"", self.set, self.value)
528528
}
529-
}
529+
}

crates/spk-schema/src/install_spec.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use std::marker::PhantomData;
66

77
use serde::{Deserialize, Serialize};
88
use spk_schema_foundation::ident_component::Component;
9+
use spk_schema_foundation::option_map::Stringified;
910
use spk_schema_foundation::spec_ops::Named;
1011
use spk_schema_foundation::IsDefault;
1112
use spk_schema_ident::{BuildIdent, OptVersionIdent};
12-
use spk_schema_foundation::option_map::Stringified;
1313
use struct_field_names_as_array::FieldNamesAsArray;
1414

1515
use crate::component_embedded_packages::ComponentEmbeddedPackage;
@@ -19,8 +19,8 @@ use crate::{
1919
EmbeddedPackagesList,
2020
EnvOp,
2121
EnvOpList,
22-
LintedItem,
2322
Lint,
23+
LintedItem,
2424
Lints,
2525
OpKind,
2626
Package,
@@ -271,15 +271,14 @@ where
271271
deserializer.deserialize_seq(EnvConfVisitor)
272272
}
273273

274-
275274
impl<'de, D> serde::de::Visitor<'de> for InstallSpecVisitor<D>
276275
where
277276
D: Default + From<InstallSpecVisitor<D>>,
278277
{
279278
type Value = D;
280279

281280
fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
282-
f.write_str("a package specification")
281+
f.write_str("an install spec")
283282
}
284283

285284
fn visit_map<A>(mut self, mut map: A) -> std::result::Result<Self::Value, A::Error>
@@ -294,7 +293,7 @@ where
294293
"environment" => self.environment = map.next_value::<EnvOpList>()?,
295294
unknown_key => {
296295
self.lints.push(Lint::Key(UnknownKey::new(
297-
unknown_key,
296+
&format!("install.{unknown_key}"),
298297
InstallSpecVisitor::<D>::FIELD_NAMES_AS_ARRAY.to_vec(),
299298
)));
300299
map.next_value::<serde::de::IgnoredAny>()?;

crates/spk-schema/src/lints.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ impl UnknownKey {
2121
}
2222

2323
pub fn generate_message(&self) -> String {
24+
let key: &str = self.unknown_key.split('.').last().unwrap_or_default();
2425
let mut message = format!("Unrecognized key: {}. ", self.unknown_key);
2526
let mut corpus = CorpusBuilder::new().finish();
2627

2728
for field in self.struct_fields.iter() {
2829
corpus.add_text(field);
2930
}
3031

31-
match corpus.search(&self.unknown_key, 0.6).first() {
32+
match corpus.search(key, 0.6).first() {
3233
Some(s) => message.push_str(format!("(Did you mean: '{}'?)", s.text).as_str()),
33-
None => message
34-
.push_str(format!("(No similar keys found for: {}.)", self.unknown_key).as_str()),
34+
None => message.push_str(format!("(No similar keys found for: {}.)", key).as_str()),
3535
};
3636

3737
message.to_string()

crates/spk-schema/src/metadata/meta.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::process::{Command, Stdio};
77

88
use serde::{Deserialize, Serialize};
99
use spk_config::Metadata;
10-
use spk_schema_foundation::IsDefault;
1110
use spk_schema_foundation::option_map::Stringified;
11+
use spk_schema_foundation::IsDefault;
1212
use struct_field_names_as_array::FieldNamesAsArray;
1313

1414
use crate::{Error, Lint, LintedItem, Lints, Result, UnknownKey};
@@ -153,7 +153,7 @@ impl<'de> serde::de::Visitor<'de> for MetaVisitor {
153153
"labels" => self.labels = Some(map.next_value::<BTreeMap<String, String>>()?),
154154
unknown_key => {
155155
self.lints.push(Lint::Key(UnknownKey::new(
156-
unknown_key,
156+
&format!("meta.{unknown_key}"),
157157
MetaVisitor::FIELD_NAMES_AS_ARRAY.to_vec(),
158158
)));
159159
map.next_value::<serde::de::IgnoredAny>()?;

crates/spk-schema/src/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<'de> serde::de::Visitor<'de> for UncheckedOptVisitor {
328328
}
329329
unknown_key => {
330330
self.lints.push(Lint::Key(UnknownKey::new(
331-
unknown_key,
331+
&format!("options.{unknown_key}"),
332332
UncheckedOptVisitor::FIELD_NAMES_AS_ARRAY.to_vec(),
333333
)));
334334
map.next_value::<serde::de::IgnoredAny>()?;

crates/spk-schema/src/source_spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'de> serde::de::Visitor<'de> for SourceSpecVisitor {
175175
"subdir" => self.subdir = Some(map.next_value::<Stringified>()?.0),
176176
unknown_key => {
177177
self.lints.push(Lint::Key(UnknownKey::new(
178-
unknown_key,
178+
&format!("sources.{unknown_key}"),
179179
SourceSpecVisitor::FIELD_NAMES_AS_ARRAY.to_vec(),
180180
)));
181181
map.next_value::<serde::de::IgnoredAny>()?;

crates/spk-schema/src/v0/test_spec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// https://github.com/spkenv/spk
44

55
use serde::{Deserialize, Serialize};
6-
use spk_schema_ident::{RequestedBy, VersionIdent};
76
use spk_schema_foundation::option_map::Stringified;
7+
use spk_schema_ident::{RequestedBy, VersionIdent};
88
use struct_field_names_as_array::FieldNamesAsArray;
99

1010
use crate::ident::Request;
@@ -124,7 +124,7 @@ impl<'de> serde::de::Visitor<'de> for TestSpecVisitor {
124124
"requirements" => self.requirements = map.next_value::<Vec<Request>>()?,
125125
unknown_key => {
126126
self.lints.push(Lint::Key(UnknownKey::new(
127-
unknown_key,
127+
&format!("sources.{unknown_key}"),
128128
TestSpecVisitor::FIELD_NAMES_AS_ARRAY.to_vec(),
129129
)));
130130
map.next_value::<serde::de::IgnoredAny>()?;

0 commit comments

Comments
 (0)