Skip to content

Commit 3f063e3

Browse files
authored
Warn if manufacturer is specified, but MPN is not (#289)
1 parent bf7c9f4 commit 3f063e3

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

crates/pcb-sch/src/physical.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3623,7 +3623,6 @@ mod tests {
36233623

36243624
let heap = Heap::new();
36253625
let range = heap.alloc(physical_range(3.0, 3.6, PhysicalUnit::Volts));
3626-
let gnd_str = heap.alloc("0V");
36273626

36283627
// Get the range from heap
36293628
let range_val = range.downcast_ref::<PhysicalRange>().unwrap();

crates/pcb-zen-core/src/lang/component.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,35 @@ where
10661066
.map(|s| s.to_owned())
10671067
});
10681068

1069+
// Warn if manufacturer is set but mpn is missing
1070+
if final_manufacturer.is_some() && final_mpn.is_none() {
1071+
if let Some(call_site) = eval_ctx.call_stack_top_location() {
1072+
use crate::lang::error::CategorizedDiagnostic;
1073+
use crate::Diagnostic;
1074+
use starlark::errors::EvalSeverity;
1075+
1076+
let body = "MPN must be specified if manufacturer is specified";
1077+
let kind = "bom.incomplete_manufacturer";
1078+
1079+
let source_error =
1080+
CategorizedDiagnostic::new(body.to_string(), kind.to_string())
1081+
.ok()
1082+
.map(|c| std::sync::Arc::new(anyhow::Error::new(c)));
1083+
1084+
let diag = Diagnostic {
1085+
path: call_site.filename().to_string(),
1086+
span: Some(call_site.resolve_span()),
1087+
severity: EvalSeverity::Warning,
1088+
body: body.to_string(),
1089+
call_stack: None,
1090+
child: None,
1091+
source_error,
1092+
suppressed: false,
1093+
};
1094+
eval_ctx.add_diagnostic(diag);
1095+
}
1096+
}
1097+
10691098
// If datasheet is not explicitly provided, try to get it from properties, then symbol properties
10701099
// Skip empty strings and "~" (KiCad's placeholder for no datasheet) - prefer None over empty
10711100
let final_datasheet = datasheet_val

crates/pcb-zen-core/tests/snapshots/component__component_manufacturer_from_symbol.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
source: crates/pcb-zen-core/tests/component.rs
33
expression: output
44
---
5+
Warning: test.zen:2:1-10:2 MPN must be specified if manufacturer is specified
56
{
67
<root>: Module {
78
path: <root>,

crates/pcb-zen-core/tests/snapshots/component__component_with_manufacturer.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
source: crates/pcb-zen-core/tests/component.rs
33
expression: output
44
---
5+
Warning: test.zen:2:1-14:2 MPN must be specified if manufacturer is specified
56
{
67
<root>: Module {
78
path: <root>,

0 commit comments

Comments
 (0)