Skip to content
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
30 changes: 24 additions & 6 deletions src/fn/jst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,23 @@ function generateSilkscreenBody(
numPins?: number,
p?: number,
): PcbSilkscreenPath {
if (variant === "ph") {
if (variant === "ph" && numPins && p) {
const pinSpan = (numPins - 1) * p
const bodyLeft = -pinSpan / 2 - 1.5
const bodyRight = pinSpan / 2 + 1.5
const bodyTop = -2
const bodyBottom = 3

return {
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "",
route: [
{ x: -3, y: 3 },
{ x: 3, y: 3 },
{ x: 3, y: -2 },
{ x: -3, y: -2 },
{ x: -3, y: 3 },
{ x: bodyLeft, y: bodyTop },
{ x: bodyRight, y: bodyTop },
{ x: bodyRight, y: bodyBottom },
{ x: bodyLeft, y: bodyBottom },
{ x: bodyLeft, y: bodyTop },
],
stroke_width: 0.1,
pcb_silkscreen_path_id: "",
Expand Down Expand Up @@ -223,6 +229,8 @@ export const jst = (
const str = typeof raw_params.string === "string" ? raw_params.string : ""
const match = str.match(/(?:^|_)jst(\d+)(?:_|$)/)
const zhMatch = str.match(/(?:^|_)zh(\d+)(?:_|$)/)
// Also match trailing pin count after variant with underscore: jst_ph_4, jst_sh_6, etc.
const variantTrailingMatch = str.match(/(?:^|_)(?:ph|sh|zh)_(\d+)(?:_|$)/)
if (match && match[1]) {
const parsed = Number.parseInt(match[1], 10)
if (!Number.isNaN(parsed)) {
Expand All @@ -235,6 +243,16 @@ export const jst = (
numPins = parsed
}
}
if (
typeof numPins !== "number" &&
variantTrailingMatch &&
variantTrailingMatch[1]
) {
const parsed = Number.parseInt(variantTrailingMatch[1], 10)
if (!Number.isNaN(parsed)) {
numPins = parsed
}
}

if (typeof numPins !== "number") {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/jst.test.tsjst2_ph.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/__snapshots__/jst.test.tsjst4_ph.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/__snapshots__/jst.test.tsjst_ph_4.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 21 additions & 2 deletions tests/jst.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,27 @@ test("jst6_sh", () => {
expect(svgContent).toMatchSvgSnapshot(import.meta.path + "jst6_sh")
})

test("jst_sh6_is_invalid", () => {
expect(() => fp.string("jst_sh6").json()).toThrow()
test("jst_ph_4 (trailing pin count format)", () => {
const circuitJson = fp.string("jst_ph_4").circuitJson()
const holes = circuitJson.filter((e: any) => e.type === "pcb_plated_hole")
expect(holes.length).toBe(4)
const svgContent = convertCircuitJsonToPcbSvg(circuitJson)
expect(svgContent).toMatchSvgSnapshot(import.meta.path + "jst_ph_4")
})

test("jst4_ph generates 4 pads", () => {
const circuitJson = fp.string("jst4_ph").circuitJson()
const holes = circuitJson.filter((e: any) => e.type === "pcb_plated_hole")
expect(holes.length).toBe(4)
const svgContent = convertCircuitJsonToPcbSvg(circuitJson)
expect(svgContent).toMatchSvgSnapshot(import.meta.path + "jst4_ph")
})

test("jst_sh_6 (trailing pin count format)", () => {
const circuitJson = fp.string("jst_sh_6").circuitJson()
const pads = circuitJson.filter((e: any) => e.type === "pcb_smtpad")
// 6 signal pads + 2 mounting pads = 8
expect(pads.length).toBe(8)
})
Comment on lines +34 to 55
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file contains multiple test() functions, which violates the rule that a *.test.ts file may have AT MOST one test(...). The file has at least 4 test() functions: 'jst_ph_4 (trailing pin count format)', 'jst4_ph generates 4 pads', 'jst_sh_6 (trailing pin count format)', and others. To fix this, split the tests into multiple numbered files such as jst1.test.ts, jst2.test.ts, jst3.test.ts, etc., with each file containing only one test() function.

Spotted by Graphite (based on custom rule: Custom rule)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.


test("jst_without_num_pins_is_invalid", () => {
Expand Down
Loading