From cd5ea7a8c0605927b4d2572ea1f43e04898ba58d Mon Sep 17 00:00:00 2001
From: Andrii Balitskyi <10balian10@gmail.com>
Date: Wed, 6 Nov 2024 14:48:33 +0100
Subject: [PATCH 1/4] Format
---
lib/components/normal-components/Capacitor.ts | 16 ++++++++--
lib/components/normal-components/Diode.ts | 12 ++++++--
lib/components/normal-components/Inductor.ts | 6 +++-
lib/components/normal-components/Led.ts | 19 ++++++++++--
.../chip-cad-model-position-offset.test.tsx | 2 +-
.../normal-components/inductor.test.tsx | 8 ++++-
.../normal-components/power-source.test.tsx | 18 +++++------
.../json/manual-edits.json | 2 +-
.../manual-edits-layout.test.tsx | 2 +-
.../manual-trace-hints.test.tsx | 4 +--
.../primitive-components/net-alias.test.tsx | 16 +++++-----
.../silkscreen-rect.test.tsx | 30 +++++++++----------
.../silkscreenpath.test.tsx | 8 ++---
.../primitive-components/via.test.tsx | 22 +++++++-------
tests/examples/bug-high-port-number.test.tsx | 2 +-
tests/readme.test.tsx | 26 ++++++++--------
tsconfig.json | 2 +-
17 files changed, 119 insertions(+), 76 deletions(-)
diff --git a/lib/components/normal-components/Capacitor.ts b/lib/components/normal-components/Capacitor.ts
index 9bcd87c..71a479e 100644
--- a/lib/components/normal-components/Capacitor.ts
+++ b/lib/components/normal-components/Capacitor.ts
@@ -25,8 +25,20 @@ export class Capacitor extends NormalComponent<
}
initPorts() {
- this.add(new Port({ name: "pin1", pinNumber: 1, aliases: ["anode", "pos", "left"] }))
- this.add(new Port({ name: "pin2", pinNumber: 2, aliases: ["cathode", "neg", "right"] }))
+ this.add(
+ new Port({
+ name: "pin1",
+ pinNumber: 1,
+ aliases: ["anode", "pos", "left"],
+ }),
+ )
+ this.add(
+ new Port({
+ name: "pin2",
+ pinNumber: 2,
+ aliases: ["cathode", "neg", "right"],
+ }),
+ )
}
doInitialCreateNetsFromProps() {
diff --git a/lib/components/normal-components/Diode.ts b/lib/components/normal-components/Diode.ts
index 3a8fabd..3228d68 100644
--- a/lib/components/normal-components/Diode.ts
+++ b/lib/components/normal-components/Diode.ts
@@ -24,10 +24,18 @@ export class Diode extends NormalComponent<
initPorts() {
this.add(
- new Port({ name: "pin1", pinNumber: 1, aliases: ["anode", "pos", "left"] }),
+ new Port({
+ name: "pin1",
+ pinNumber: 1,
+ aliases: ["anode", "pos", "left"],
+ }),
)
this.add(
- new Port({ name: "pin2", pinNumber: 2, aliases: ["cathode", "neg", "right"] }),
+ new Port({
+ name: "pin2",
+ pinNumber: 2,
+ aliases: ["cathode", "neg", "right"],
+ }),
)
}
diff --git a/lib/components/normal-components/Inductor.ts b/lib/components/normal-components/Inductor.ts
index 8a2857a..b9e1f46 100644
--- a/lib/components/normal-components/Inductor.ts
+++ b/lib/components/normal-components/Inductor.ts
@@ -1,6 +1,10 @@
import { inductorProps } from "@tscircuit/props"
import type { SourceSimpleInductor } from "circuit-json"
-import { FTYPE, type BaseSymbolName,type PassivePorts } from "lib/utils/constants"
+import {
+ FTYPE,
+ type BaseSymbolName,
+ type PassivePorts,
+} from "lib/utils/constants"
import { NormalComponent } from "../base-components/NormalComponent"
import { Port } from "../primitive-components/Port"
diff --git a/lib/components/normal-components/Led.ts b/lib/components/normal-components/Led.ts
index dbf528c..59a3b4b 100644
--- a/lib/components/normal-components/Led.ts
+++ b/lib/components/normal-components/Led.ts
@@ -15,15 +15,28 @@ export class Led extends NormalComponent<
get config() {
return {
componentName: "Led",
- schematicSymbolName: this.props.symbolName ?? "led_horz" as BaseSymbolName,
+ schematicSymbolName:
+ this.props.symbolName ?? ("led_horz" as BaseSymbolName),
zodProps: ledProps,
sourceFtype: "simple_diode" as Ftype,
}
}
initPorts() {
- this.add(new Port({ name: "pin1", pinNumber: 1, aliases: ["anode", "pos", "left"] }))
- this.add(new Port({ name: "pin2", pinNumber: 2, aliases: ["cathode", "neg", "right"] }))
+ this.add(
+ new Port({
+ name: "pin1",
+ pinNumber: 1,
+ aliases: ["anode", "pos", "left"],
+ }),
+ )
+ this.add(
+ new Port({
+ name: "pin2",
+ pinNumber: 2,
+ aliases: ["cathode", "neg", "right"],
+ }),
+ )
}
pos = this.portMap.pin1
diff --git a/tests/components/normal-components/chip-cad-model-position-offset.test.tsx b/tests/components/normal-components/chip-cad-model-position-offset.test.tsx
index 4b20cf2..42f998c 100644
--- a/tests/components/normal-components/chip-cad-model-position-offset.test.tsx
+++ b/tests/components/normal-components/chip-cad-model-position-offset.test.tsx
@@ -16,7 +16,7 @@ test("chip with cadModel positionOffset", () => {
positionOffset: { x: 1, y: 2, z: 3 },
}}
/>
-
+ ,
)
project.render()
diff --git a/tests/components/normal-components/inductor.test.tsx b/tests/components/normal-components/inductor.test.tsx
index 6be812a..e03f2ef 100644
--- a/tests/components/normal-components/inductor.test.tsx
+++ b/tests/components/normal-components/inductor.test.tsx
@@ -6,7 +6,13 @@ test(" component", async () => {
circuit.add(
-
+
,
)
diff --git a/tests/components/normal-components/power-source.test.tsx b/tests/components/normal-components/power-source.test.tsx
index 90e0aca..a6aa91f 100644
--- a/tests/components/normal-components/power-source.test.tsx
+++ b/tests/components/normal-components/power-source.test.tsx
@@ -1,16 +1,16 @@
-import { expect, it } from "bun:test";
-import { getTestFixture } from "tests/fixtures/get-test-fixture";
+import { expect, it } from "bun:test"
+import { getTestFixture } from "tests/fixtures/get-test-fixture"
it("should render a power source", async () => {
- const { project } = getTestFixture();
+ const { project } = getTestFixture()
project.add(
-
- );
+ ,
+ )
- project.render();
- expect(project.db.schematic_component.list()).toHaveLength(1);
- expect(project.db.schematic_port.list()).toHaveLength(2);
-});
+ project.render()
+ expect(project.db.schematic_component.list()).toHaveLength(1)
+ expect(project.db.schematic_port.list()).toHaveLength(2)
+})
diff --git a/tests/components/primitive-components/json/manual-edits.json b/tests/components/primitive-components/json/manual-edits.json
index 284a72d..4dd901b 100644
--- a/tests/components/primitive-components/json/manual-edits.json
+++ b/tests/components/primitive-components/json/manual-edits.json
@@ -12,4 +12,4 @@
],
"edit_events": [],
"manual_trace_hints": []
-}
\ No newline at end of file
+}
diff --git a/tests/components/primitive-components/manual-edits-layout.test.tsx b/tests/components/primitive-components/manual-edits-layout.test.tsx
index 4d7baa3..effa8d9 100644
--- a/tests/components/primitive-components/manual-edits-layout.test.tsx
+++ b/tests/components/primitive-components/manual-edits-layout.test.tsx
@@ -7,7 +7,7 @@ test("Manual edits prop usage", () => {
project.add(
-
+
,
)
diff --git a/tests/components/primitive-components/manual-trace-hints.test.tsx b/tests/components/primitive-components/manual-trace-hints.test.tsx
index fea7cfe..92c3a2c 100644
--- a/tests/components/primitive-components/manual-trace-hints.test.tsx
+++ b/tests/components/primitive-components/manual-trace-hints.test.tsx
@@ -50,12 +50,12 @@ test("manual trace hints correctly change trace routes", async () => {
expect(traceRoute.map((p) => ("layer" in p ? p.layer : ""))).toContain(
"bottom",
)
-
+
expect(circuit.selectAll("tracehint").length).toBe(1)
expect(circuit.db.pcb_trace_hint.list().length).toBe(1)
expect(circuit.db.pcb_trace_hint.list()[0].pcb_port_id).toBeTruthy()
-
+
expect(circuit).toMatchPcbSnapshot(import.meta.path)
})
diff --git a/tests/components/primitive-components/net-alias.test.tsx b/tests/components/primitive-components/net-alias.test.tsx
index f1db0b4..a775d57 100644
--- a/tests/components/primitive-components/net-alias.test.tsx
+++ b/tests/components/primitive-components/net-alias.test.tsx
@@ -1,16 +1,16 @@
-import { expect, it } from "bun:test";
-import { getTestFixture } from "tests/fixtures/get-test-fixture";
+import { expect, it } from "bun:test"
+import { getTestFixture } from "tests/fixtures/get-test-fixture"
it("should render a net alias", async () => {
- const { project } = getTestFixture();
+ const { project } = getTestFixture()
project.add(
-
- );
+ ,
+ )
- project.render();
+ project.render()
- expect(project.db.schematic_net_label.list()).toHaveLength(1);
-});
+ expect(project.db.schematic_net_label.list()).toHaveLength(1)
+})
diff --git a/tests/components/primitive-components/silkscreen-rect.test.tsx b/tests/components/primitive-components/silkscreen-rect.test.tsx
index adb719d..3260dd1 100644
--- a/tests/components/primitive-components/silkscreen-rect.test.tsx
+++ b/tests/components/primitive-components/silkscreen-rect.test.tsx
@@ -1,8 +1,8 @@
-import { expect, test } from "bun:test";
-import { getTestFixture } from "tests/fixtures/get-test-fixture";
+import { expect, test } from "bun:test"
+import { getTestFixture } from "tests/fixtures/get-test-fixture"
test("SilkscreenRect rendering", () => {
- const { project } = getTestFixture();
+ const { project } = getTestFixture()
project.add(
{
height={"1.5mm"}
layer="bottom"
/>
-
- );
- project.render();
+ ,
+ )
+ project.render()
- const silkscreenRects = project.db.pcb_silkscreen_rect.list();
+ const silkscreenRects = project.db.pcb_silkscreen_rect.list()
- expect(silkscreenRects.length).toBe(1);
- expect(silkscreenRects[0].center.x).toBe(2);
- expect(silkscreenRects[0].center.y).toBe(3);
- expect(silkscreenRects[0].width).toBe(2);
- expect(silkscreenRects[0].height).toBe(1.5);
- expect(silkscreenRects[0].layer).toBe("bottom");
+ expect(silkscreenRects.length).toBe(1)
+ expect(silkscreenRects[0].center.x).toBe(2)
+ expect(silkscreenRects[0].center.y).toBe(3)
+ expect(silkscreenRects[0].width).toBe(2)
+ expect(silkscreenRects[0].height).toBe(1.5)
+ expect(silkscreenRects[0].layer).toBe("bottom")
- expect(project).toMatchPcbSnapshot(import.meta.path);
-});
+ expect(project).toMatchPcbSnapshot(import.meta.path)
+})
diff --git a/tests/components/primitive-components/silkscreenpath.test.tsx b/tests/components/primitive-components/silkscreenpath.test.tsx
index 5655e6e..ccc7061 100644
--- a/tests/components/primitive-components/silkscreenpath.test.tsx
+++ b/tests/components/primitive-components/silkscreenpath.test.tsx
@@ -10,12 +10,12 @@ test("SilkscreenPath rendering", () => {
route={[
{ x: "0mm", y: "0mm" },
{ x: "5mm", y: "5mm" },
- { x: "10mm", y: "0mm" }
+ { x: "10mm", y: "0mm" },
]}
strokeWidth="0.2mm"
layer="top"
/>
-
+ ,
)
project.render()
@@ -25,11 +25,11 @@ test("SilkscreenPath rendering", () => {
expect(silkscreenPaths.length).toBe(1)
expect(silkscreenPaths[0].layer).toBe("top")
expect(silkscreenPaths[0].stroke_width).toBe(0.2)
-
+
expect(silkscreenPaths[0].route).toEqual([
{ x: 0, y: 0 },
{ x: 5, y: 5 },
- { x: 10, y: 0 }
+ { x: 10, y: 0 },
])
expect(silkscreenPaths[0].pcb_silkscreen_path_id).toBeTruthy()
diff --git a/tests/components/primitive-components/via.test.tsx b/tests/components/primitive-components/via.test.tsx
index cc4c5ed..bd6e0f6 100644
--- a/tests/components/primitive-components/via.test.tsx
+++ b/tests/components/primitive-components/via.test.tsx
@@ -1,9 +1,9 @@
-import { expect, it } from "bun:test";
-import type { Via } from "lib/components";
-import { getTestFixture } from "tests/fixtures/get-test-fixture";
+import { expect, it } from "bun:test"
+import type { Via } from "lib/components"
+import { getTestFixture } from "tests/fixtures/get-test-fixture"
it("should create a Via component with correct properties", () => {
- const { project } = getTestFixture();
+ const { project } = getTestFixture()
project.add(
@@ -15,15 +15,15 @@ it("should create a Via component with correct properties", () => {
fromLayer="top"
toLayer="bottom"
/>
-
- );
+ ,
+ )
- project.render();
+ project.render()
expect(project).toMatchPcbSnapshot(import.meta.path)
- const via = project.selectOne("via") as Via;
+ const via = project.selectOne("via") as Via
- expect(via).not.toBeNull();
- expect(via.props.pcbX).toBe("0mm");
-});
+ expect(via).not.toBeNull()
+ expect(via.props.pcbX).toBe("0mm")
+})
diff --git a/tests/examples/bug-high-port-number.test.tsx b/tests/examples/bug-high-port-number.test.tsx
index 86da596..2d0317b 100644
--- a/tests/examples/bug-high-port-number.test.tsx
+++ b/tests/examples/bug-high-port-number.test.tsx
@@ -9,7 +9,7 @@ test("bug high port number", async () => {
width={10}
height={10}
// @ts-ignore
- // _schDebugObjectsEnabled
+ // _schDebugObjectsEnabled
>
{
- const project = new Circuit();
+ const project = new Circuit()
const board = new Board({
width: "10mm",
height: "10mm",
- });
- project.add(board);
+ })
+ project.add(board)
- const R1 = ;
- board.add(R1);
+ const R1 =
+ board.add(R1)
- board.add();
+ board.add()
- project.render();
+ project.render()
// Let's check the db to make sure everything we expect is there
- expect(project.db.source_component.select(".R1")?.name).toBe("R1");
+ expect(project.db.source_component.select(".R1")?.name).toBe("R1")
// expect(project.db.source_component.select(".LED1")?.name).toBe("LED1")
- expect(project.db.pcb_smtpad.list()).toHaveLength(4);
+ expect(project.db.pcb_smtpad.list()).toHaveLength(4)
// console.log("pcb_trace", project.db.pcb_trace.list())
// console.log(project.getSoup())
-});
+})
diff --git a/tsconfig.json b/tsconfig.json
index 43b7cdd..ae5da2b 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -11,7 +11,7 @@
"baseUrl": ".",
"paths": {
- "lib/*": ["lib/*"],
+ "lib/*": ["lib/*"]
},
// Bundler mode
From f29900e08cc3c95c9f10e1a31f7b555a0158476b Mon Sep 17 00:00:00 2001
From: Andrii Balitskyi <10balian10@gmail.com>
Date: Wed, 6 Nov 2024 14:52:57 +0100
Subject: [PATCH 2/4] Add formatbot
---
.github/workflows/formatbot.yml | 63 +++++++++++++++++++++++++++++++++
lib/hooks/use-diode.tsx | 2 +-
2 files changed, 64 insertions(+), 1 deletion(-)
create mode 100644 .github/workflows/formatbot.yml
diff --git a/.github/workflows/formatbot.yml b/.github/workflows/formatbot.yml
new file mode 100644
index 0000000..89c58e6
--- /dev/null
+++ b/.github/workflows/formatbot.yml
@@ -0,0 +1,63 @@
+name: Format PR
+
+on:
+ pull_request:
+ types: [opened, synchronize, reopened, ready_for_review]
+
+jobs:
+ format:
+ name: Format code
+ runs-on: ubuntu-latest
+ if: github.event.pull_request.draft == false
+
+ steps:
+ - name: Determine if fork
+ id: check_fork
+ run: |
+ if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
+ echo "is_fork=false" >> $GITHUB_OUTPUT
+ else
+ echo "is_fork=true" >> $GITHUB_OUTPUT
+ fi
+
+ - name: Checkout code
+ uses: actions/checkout@v3
+ with:
+ token: ${{ steps.check_fork.outputs.is_fork == 'true' && secrets.GITHUB_TOKEN || secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
+
+ - name: Setup bun
+ uses: oven-sh/setup-bun@v1
+ with:
+ bun-version: latest
+
+ - name: Get @biomejs/biome version
+ id: get-biome-version
+ run: echo "BIOME_VERSION=$(node -p "require('./package.json').devDependencies['@biomejs/biome']")" >> $GITHUB_OUTPUT
+
+ - name: Install @biomejs/biome
+ run: bun install @biomejs/biome@${{ steps.get-biome-version.outputs.BIOME_VERSION }}
+
+ - name: Run Formatter and autofix
+ if: steps.check_fork.outputs.is_fork == 'false'
+ run: biome format . --write
+
+ - name: Format Check (cannot autofix against forks)
+ if: steps.check_fork.outputs.is_fork == 'true'
+ run: biome format .
+
+ - name: Restore lock files
+ if: steps.check_fork.outputs.is_fork == 'false'
+ run: |
+ git checkout -- *lock.json || true
+ git checkout -- *.lock || true
+ git checkout -- *.lockb || true
+
+ - name: Commit changes
+ if: steps.check_fork.outputs.is_fork == 'false'
+ uses: stefanzweifel/git-auto-commit-action@v4
+ with:
+ commit_message: "formatbot: Automatically format code"
+ branch: ${{ github.head_ref }}
+ commit_user_name: tscircuitbot
+ commit_user_email: tscircuitbot@users.noreply.github.com
+ commit_author: tscircuitbot
diff --git a/lib/hooks/use-diode.tsx b/lib/hooks/use-diode.tsx
index 305ab5b..2b76e46 100644
--- a/lib/hooks/use-diode.tsx
+++ b/lib/hooks/use-diode.tsx
@@ -4,4 +4,4 @@ import { createUseComponent } from "./create-use-component"
export const useDiode = createUseComponent(
(props: DiodeProps) => ,
diodePins,
-)
+ )
From 5396fadf92f196f9dbfb0f374f391790794479bc Mon Sep 17 00:00:00 2001
From: Andrii Balitskyi <10balian10@gmail.com>
Date: Wed, 6 Nov 2024 14:53:51 +0100
Subject: [PATCH 3/4] Fix biome command in formatbot
---
.github/workflows/formatbot.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/formatbot.yml b/.github/workflows/formatbot.yml
index 89c58e6..cdb02e8 100644
--- a/.github/workflows/formatbot.yml
+++ b/.github/workflows/formatbot.yml
@@ -39,11 +39,11 @@ jobs:
- name: Run Formatter and autofix
if: steps.check_fork.outputs.is_fork == 'false'
- run: biome format . --write
+ run: npx @biomejs/biome format . --write
- name: Format Check (cannot autofix against forks)
if: steps.check_fork.outputs.is_fork == 'true'
- run: biome format .
+ run: npx @biomejs/biome format .
- name: Restore lock files
if: steps.check_fork.outputs.is_fork == 'false'
From 5dc7c46e9fa2ccacc9b5859031ad614f61691f51 Mon Sep 17 00:00:00 2001
From: tscircuitbot
Date: Wed, 6 Nov 2024 13:54:20 +0000
Subject: [PATCH 4/4] formatbot: Automatically format code
---
lib/hooks/use-diode.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/hooks/use-diode.tsx b/lib/hooks/use-diode.tsx
index 2b76e46..305ab5b 100644
--- a/lib/hooks/use-diode.tsx
+++ b/lib/hooks/use-diode.tsx
@@ -4,4 +4,4 @@ import { createUseComponent } from "./create-use-component"
export const useDiode = createUseComponent(
(props: DiodeProps) => ,
diodePins,
- )
+)