← Commit history

2.17.1: EAGLE-safe pin names + illegal-pin-name lint (Fusion refused libraries over KiCad pin names with spaces)

Colby Knox ·35f37dca21 ·1mo ago ·parent 6926bb9
2 files changed +24−2
VERSION+1−1
@@ -1 +1 @@-2.17.0+2.17.1
src/main.rs+23−1
@@ -657,6 +657,22 @@ fn pin_length_keyword(len: f64) -> &'static str {     else { "long" } } +/// EAGLE names cannot carry spaces or most punctuation; KiCad pin names can+/// ("GND (TAB)" on a real TI part). Fusion refuses the ENTIRE library over one+/// such name, so every emitted pin name passes through this. Illegal runs+/// collapse to one underscore, trimmed at the ends.+fn eagle_safe_name(name: &str) -> String {+    let mut out = String::with_capacity(name.len());+    let mut last_us = false;+    for ch in name.chars() {+        let ok = ch.is_ascii_alphanumeric() || matches!(ch, '_' | '+' | '-' | '.' | '/' | '!' | '@' | '$' | '#');+        if ok { out.push(ch); last_us = false; }+        else if !last_us { out.push('_'); last_us = true; }+    }+    let trimmed = out.trim_matches('_').to_string();+    if trimmed.is_empty() { "P".to_string() } else { trimmed }+}+ fn dedup_pin_names(pins: &[KicadPin]) -> Vec<String> {     // Effective EAGLE pin name: when the KiCad pin name is empty (common on     // mechanical / 1-pin parts: `(number "1")(name "")`), fall back to the pad@@ -666,7 +682,7 @@ fn dedup_pin_names(pins: &[KicadPin]) -> Vec<String> {     let eff: Vec<String> = pins.iter().enumerate().map(|(i, p)| {         let n = p.name.trim();         if !n.is_empty() {-            n.to_string()+            eagle_safe_name(n)         } else {             let num = p.number.trim();             if !num.is_empty() { num.to_string() } else { format!("P{}", i + 1) }@@ -1535,6 +1551,12 @@ pub(crate) fn lint_lbr(content: &str) -> LintResult {                 });                 continue;             }+            if pname.chars().any(|ch| !(ch.is_ascii_alphanumeric() || matches!(ch, '_' | '+' | '-' | '.' | '/' | '!' | '@' | '$' | '#'))) {+                errors.push(LintError {+                    code: "illegal-pin-name".into(),+                    message: format!("Symbol '{}' pin '{}' contains characters an EAGLE name cannot carry (space or punctuation outside _+-./!@$#) — Fusion refuses the whole library over it", sname, pname),+                });+            }             *within.entry(pname.clone()).or_insert(0) += 1;             set.insert(pname);         }