Skip to content

Commit 19fc1af

Browse files
author
Nichol Yip
committed
Implemented lint feature for EnvOp and TestSpec
Signed-off-by: Nichol Yip <[email protected]>
1 parent 1aeeb4d commit 19fc1af

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

crates/spk-schema/crates/ident/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ format_serde_error = { version = "0.3", default_features = false, features = [
1919
itertools = { workspace = true }
2020
nom = { workspace = true }
2121
nom-supreme = { workspace = true }
22+
lint_proc_macro = { workspace = true }
2223
relative-path = "1.3"
2324
serde = { workspace = true, features = ["derive"] }
2425
serde_yaml = { workspace = true }

crates/spk-schema/src/environ.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub enum OpKind {
3838
}
3939

4040
/// An operation performed to the environment
41-
#[derive(Clone, Debug, Eq, Hash, Lint, Ord, PartialEq, PartialOrd, Serialize)]
41+
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
4242
#[serde(untagged)]
4343
pub enum EnvOp {
4444
Append(AppendEnv),
@@ -341,7 +341,7 @@ impl<'de> serde::de::Visitor<'de> for EnvOpVisitor {
341341
///
342342
/// The separator used defaults to the path separator for the current
343343
/// host operating system (':' for unix, ';' for windows)
344-
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
344+
#[derive(Clone, Debug, Eq, Hash, Lint, Ord, PartialEq, PartialOrd, Serialize)]
345345
pub struct AppendEnv {
346346
pub append: String,
347347
pub value: String,
@@ -430,7 +430,7 @@ impl EnvPriority {
430430
///
431431
/// The separator used defaults to the path separator for the current
432432
/// host operating system (':' for unix, ';' for windows)
433-
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
433+
#[derive(Clone, Debug, Eq, Hash, Lint, Ord, PartialEq, PartialOrd, Serialize)]
434434
pub struct PrependEnv {
435435
pub prepend: String,
436436
pub value: String,
@@ -476,7 +476,7 @@ impl PrependEnv {
476476
}
477477

478478
/// Operates on an environment variable by setting it to a value
479-
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
479+
#[derive(Clone, Debug, Eq, Hash, Lint, Ord, PartialEq, PartialOrd, Serialize)]
480480
pub struct SetEnv {
481481
pub set: String,
482482
pub value: String,

crates/spk-schema/src/install_spec.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ where
3636
D: Default,
3737
{
3838
fn lints(&mut self) -> Vec<String> {
39-
// for env in self.environment.iter_mut() {
40-
// self.lints.extend(std::mem::take(&mut env.lints));
41-
// }
39+
for env in self.environment.iter_mut() {
40+
self.lints.extend(std::mem::take(
41+
&mut env.lints.iter().map(|l| env.item.lints(l)).collect_vec(),
42+
));
43+
}
44+
4245
std::mem::take(&mut self.lints)
4346
}
4447
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,13 @@ impl<B, T> Lints for SpecVisitor<B, T> {
10231023

10241024
if let Some(tests) = self.tests.as_mut() {
10251025
for test in tests.iter_mut() {
1026-
lint_messages.extend(std::mem::take(&mut test.lints));
1026+
lint_messages.extend(std::mem::take(
1027+
&mut test
1028+
.lints
1029+
.iter()
1030+
.map(|l| test.item.generate_lints(l))
1031+
.collect_vec(),
1032+
));
10271033
}
10281034
}
10291035

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'de> serde::de::Visitor<'de> for TestSpecVisitor {
101101
"selectors" => self.selectors = map.next_value::<Vec<OptionMap>>()?,
102102
"requirements" => self.requirements = map.next_value::<Vec<Request>>()?,
103103
unknown_key => {
104-
// self.lints.push(self.generate_lints(unknown_key));
104+
self.lints.push(unknown_key.to_string());
105105
map.next_value::<serde::de::IgnoredAny>()?;
106106
}
107107
}

0 commit comments

Comments
 (0)