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
66 changes: 32 additions & 34 deletions bun.lock

Large diffs are not rendered by default.

44 changes: 24 additions & 20 deletions cli/check/netlist/register.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
import { convertCircuitJsonToReadableNetlist } from "circuit-json-to-readable-netlist"
import {
categorizeErrorOrWarning,
type DrcCategory,
} from "@tscircuit/circuit-json-util"
import path from "node:path"
import { categorizeErrorOrWarning } from "@tscircuit/circuit-json-util"
import type { PlatformConfig } from "@tscircuit/props"
import type { AnyCircuitElement } from "circuit-json"
import { convertCircuitJsonToReadableNetlist } from "circuit-json-to-readable-netlist"
import type { Command } from "commander"
import { getOrGenerateCircuitJson } from "lib/shared/get-or-generate-circuit-json"
import { getPlatformConfigWithCliDefaults } from "lib/shared/get-platform-config-with-cli-defaults"
import { getEntrypoint } from "lib/shared/get-entrypoint"
import { findCircuitProjectDir } from "lib/shared/circuit-json-build-cache"
import {
analyzeCircuitJson,
type CircuitJsonIssue,
analyzeCircuitJson,
} from "lib/shared/circuit-json-diagnostics"
import path from "node:path"
import { findCircuitProjectDir } from "lib/shared/circuit-json-build-cache"
import { getEntrypoint } from "lib/shared/get-entrypoint"
import { getOrGenerateCircuitJson } from "lib/shared/get-or-generate-circuit-json"
import { getPlatformConfigWithCliDefaults } from "lib/shared/get-platform-config-with-cli-defaults"

const normalizeCategory = (category: string): DrcCategory =>
category === "netlist" ||
category === "pin_specification" ||
category === "placement" ||
category === "routing"
? category
: "unknown"
export function isNetlistDiagnostic(issue: CircuitJsonIssue) {
if (categorizeErrorOrWarning(issue) === "netlist") {
return true
}

if (issue.type !== "source_property_ignored_warning") {
return false
}

const isNetlistDiagnostic = (issue: CircuitJsonIssue) =>
normalizeCategory(categorizeErrorOrWarning(issue)) === "netlist"
switch (issue.property_name) {
case "positiveConnection":
case "negativeConnection":
return true
default:
return false
}
}

const resolveInputFilePath = async (file?: string) => {
if (file) {
Expand Down
8 changes: 4 additions & 4 deletions lib/shared/circuit-json-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export function analyzeCircuitJson(circuitJson: any[]): {
const isTypedError = typeof t === "string" && t.endsWith("_error")
const isTypedWarning = typeof t === "string" && t.endsWith("_warning")

if (hasErrorType || isTypedError) {
errors.push(item as CircuitJsonIssue)
if (hasWarningType || isTypedWarning) {
warnings.push(item as CircuitJsonIssue)
continue
}

if (hasWarningType || isTypedWarning) {
warnings.push(item as CircuitJsonIssue)
if (hasErrorType || isTypedError) {
errors.push(item as CircuitJsonIssue)
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"spicets": "^0.0.4",
"stepts": "^0.0.3",
"tempy": "^3.1.0",
"tscircuit": "0.0.2142-libonly",
"tscircuit": "0.0.2233-libonly",
"tsx": "^4.7.1",
"typed-ky": "^0.0.4",
"zod": "^3.23.8"
Expand Down
16 changes: 16 additions & 0 deletions tests/analyze-circuit-json-warning-type-precedence.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect, test } from "bun:test"
import { analyzeCircuitJson } from "lib/shared/circuit-json-diagnostics"

test("analyzeCircuitJson prefers a warning type over error_type metadata", () => {
const { errors, warnings } = analyzeCircuitJson([
{
type: "source_property_ignored_warning",
error_type: "source_property_ignored_warning",
property_name: "positiveConnection",
message: "ambiguous differential-pair trace",
},
])

expect(errors).toHaveLength(0)
expect(warnings).toHaveLength(1)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from "bun:test"
import { isNetlistDiagnostic } from "cli/check/netlist/register"

test("only differential-pair connection properties are netlist warnings", () => {
const createPropertyWarning = (property_name: string) => ({
type: "source_property_ignored_warning",
property_name,
})

expect(isNetlistDiagnostic(createPropertyWarning("positiveConnection"))).toBe(
true,
)
expect(isNetlistDiagnostic(createPropertyWarning("negativeConnection"))).toBe(
true,
)
expect(isNetlistDiagnostic(createPropertyWarning("footprint"))).toBe(false)
})
40 changes: 40 additions & 0 deletions tests/cli/check/check-netlist-differential-pair-warnings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { expect, test } from "bun:test"
import { writeFile } from "node:fs/promises"
import path from "node:path"
import { getCliTestFixture } from "../../fixtures/get-cli-test-fixture"

const circuitCode = `
export default () => (
<board width="20mm" height="14mm" routingDisabled>
<differentialpair
name="USB_DATA"
positiveConnection="DP_FROM_J1"
negativeConnection="DM"
/>
<chip name="J1" footprint="soic8" />
<chip name="U1" footprint="soic8" />
<testpoint name="TP1" footprintVariant="pad" />
<trace name="DP_FROM_J1" from=".J1 > .pin1" to="net.DP" />
<trace from="net.DP" to=".U1 > .pin1" />
<trace from="net.DP" to=".TP1 > .pin1" />
<trace name="DM" from=".J1 > .pin2" to=".U1 > .pin2" />
</board>
)
`

test("check netlist displays Core differential-pair warnings", async () => {
const { tmpDir, runCommand } = await getCliTestFixture()
const circuitPath = path.join(tmpDir, "differential-pair.tsx")

await writeFile(circuitPath, circuitCode)

const { stdout, stderr, exitCode } = await runCommand(
`tsci check netlist ${circuitPath}`,
)

expect(exitCode).toBe(0)
expect(stderr).toBe("")
expect(stdout).toContain("Errors: 0")
expect(stdout).toContain("Warnings: 1")
expect(stdout).toContain("- source_property_ignored_warning:")
}, 20_000)
Loading