Skip to content

Commit

Permalink
Merge pull request #36 from tscircuit/add-formatbot
Browse files Browse the repository at this point in the history
add formatbot
  • Loading branch information
seveibar authored Sep 19, 2024
2 parents 4587ccc + 44eec31 commit 71f05a2
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 48 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/formatbot.yml
Original file line number Diff line number Diff line change
@@ -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 Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- 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: npm install @biomejs/biome@${{ steps.get-biome-version.outputs.BIOME_VERSION }}

- name: Run Formatter and autofix
if: steps.check_fork.outputs.is_fork == 'false'
run: npx @biomejs/biome format . --write

- name: Format Check (cannot autofix against forks)
if: steps.check_fork.outputs.is_fork == 'true'
run: npx @biomejs/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 <tscircuitbot@users.noreply.github.com>
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
"version": "0.0.61",
"description": "",
"main": "dist/index.cjs",
"files": [
"dist"
],
"files": ["dist"],
"scripts": {
"test": "FULL_RUN=1 ava",
"dev": "cd previews && npm i && npm run storybook",
"build": "tsup ./src/index.ts --dts --sourcemap"
"build": "tsup ./src/index.ts --dts --sourcemap",
"format": "biome format . --write"
},
"keywords": [],
"author": "",
Expand Down
6 changes: 3 additions & 3 deletions src/fn/bga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ export const bga = (params: BgaDefInput): AnySoupElement[] => {
`not able to create bga component, unable to determine missing pins (try specifying them with "missing+1+2+..."\n\n${JSON.stringify(
bga_params,
null,
" "
)}`
" ",
)}`,
)
}

Expand All @@ -129,7 +129,7 @@ export const bga = (params: BgaDefInput): AnySoupElement[] => {

// TODO handle >26 rows
pads.push(
rectpad([pin_num, `${ALPHABET[y]}${x + 1}`], pad_x, pad_y, pad, pad)
rectpad([pin_num, `${ALPHABET[y]}${x + 1}`], pad_x, pad_y, pad, pad),
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/fn/dip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const getCcwDipCoords = (
pinCount: number,
pn: number,
w: number,
p: number
p: number,
) => {
/** pin height */
const ph = pinCount / 2
Expand Down Expand Up @@ -89,10 +89,10 @@ export const dip = (raw_params: {
params.num_pins,
i + 1,
params.w,
params.p ?? 2.54
params.p ?? 2.54,
)
platedHoles.push(
platedhole(i + 1, x, y, params.id ?? "0.8mm", params.od ?? "1mm")
platedhole(i + 1, x, y, params.id ?? "0.8mm", params.od ?? "1mm"),
)
}
/** silkscreen width */
Expand Down
8 changes: 4 additions & 4 deletions src/fn/quad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const base_quad_def = z.object({
})

export const quadTransform = <T extends z.infer<typeof base_quad_def>>(
v: T
v: T,
) => {
if (v.w && !v.h) {
v.h = v.w
Expand Down Expand Up @@ -107,7 +107,7 @@ export const getQuadCoords = (params: {
}

export const quad = (
raw_params: z.input<typeof quad_def>
raw_params: z.input<typeof quad_def>,
): AnySoupElement[] => {
const params = quad_def.parse(raw_params)
const pads: AnySoupElement[] = []
Expand Down Expand Up @@ -146,7 +146,7 @@ export const quad = (
pads.push(rectpad(["thermalpad"], 0, 0, ibw, ibh))
} else {
pads.push(
rectpad(["thermalpad"], 0, 0, params.thermalpad.x, params.thermalpad.y)
rectpad(["thermalpad"], 0, 0, params.thermalpad.x, params.thermalpad.y),
)
}
}
Expand Down Expand Up @@ -256,7 +256,7 @@ export const quad = (
},
],
type: "pcb_silkscreen_path",
}
},
)
}
if (arrow === "in1" || arrow === "in2") {
Expand Down
44 changes: 22 additions & 22 deletions src/fn/sot23.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import type { AnySoupElement } from "@tscircuit/soup";
import { z } from "zod";
import { rectpad } from "../helpers/rectpad";
import type { AnySoupElement } from "@tscircuit/soup"
import { z } from "zod"
import { rectpad } from "../helpers/rectpad"

export const sot23_def = z.object({
num_pins: z.number().default(3),
w: z.string().default("1.92mm"),
h: z.string().default("2.74mm"),
pl: z.string().default("0.8mm"),
pw: z.string().default("0.764mm"),
});
})

export const sot23 = (params: z.input<typeof sot23_def>): AnySoupElement[] => {
return sot23WithoutParsing(sot23_def.parse(params));
};
return sot23WithoutParsing(sot23_def.parse(params))
}

export const getCcwSot23Coords = (params: {
num_pins: number;
pn: number;
w: number;
h: number;
pl: number;
num_pins: number
pn: number
w: number
h: number
pl: number
}) => {
const { pn, w, h, pl } = params;
const { pn, w, h, pl } = params

if (pn === 1) {
return { x: -1.7, y: 0 };
return { x: -1.7, y: 0 }
} else if (pn === 2) {
return { x: 1.7, y: -0.95 };
return { x: 1.7, y: -0.95 }
} else {
return { x: 1.7, y: 0.95 };
return { x: 1.7, y: 0.95 }
}
};
}

export const sot23WithoutParsing = (params: z.infer<typeof sot23_def>) => {
const pads: AnySoupElement[] = [];
const pads: AnySoupElement[] = []

for (let i = 0; i < params.num_pins; i++) {
const { x, y } = getCcwSot23Coords({
Expand All @@ -42,11 +42,11 @@ export const sot23WithoutParsing = (params: z.infer<typeof sot23_def>) => {
w: parseFloat(params.w),
h: parseFloat(params.h),
pl: parseFloat(params.pl),
});
})
pads.push(
rectpad(i + 1, x, y, parseFloat(params.pl), parseFloat(params.pw))
);
rectpad(i + 1, x, y, parseFloat(params.pl), parseFloat(params.pw)),
)
}

return pads;
};
return pads
}
2 changes: 1 addition & 1 deletion src/fn/tssop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { extendSoicDef, soicWithoutParsing, type SoicInput } from "./soic"
export const tssop_def = extendSoicDef({
w: "6.1mm",
p: "0.65mm",
legsoutside: true
legsoutside: true,
})

export const tssop = (raw_params: SoicInput) => {
Expand Down
12 changes: 6 additions & 6 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ type CommonPassiveOptionKey =

export type Footprinter = {
dip: (
num_pins: number
num_pins: number,
) => FootprinterParamsBuilder<"w" | "p" | "id" | "od" | "wide" | "narrow">
cap: () => FootprinterParamsBuilder<CommonPassiveOptionKey>
res: () => FootprinterParamsBuilder<CommonPassiveOptionKey>
diode: () => FootprinterParamsBuilder<CommonPassiveOptionKey>
led: () => FootprinterParamsBuilder<CommonPassiveOptionKey>
lr: (num_pins: number) => FootprinterParamsBuilder<"w" | "l" | "pl" | "pr">
qfp: (
num_pins: number
num_pins: number,
) => FootprinterParamsBuilder<"w" | "p" | "id" | "od" | "wide" | "narrow">
quad: (
num_pins: number
num_pins: number,
) => FootprinterParamsBuilder<
"w" | "l" | "square" | "pl" | "pr" | "pb" | "pt" | "p" | "pw" | "ph"
>
bga: (
num_pins: number
num_pins: number,
) => FootprinterParamsBuilder<
"grid" | "p" | "w" | "h" | "ball" | "pad" | "missing"
>
Expand Down Expand Up @@ -89,7 +89,7 @@ export const footprinter = (): Footprinter & { string: typeof string } => {
return () => {
// TODO improve error
throw new Error(
`No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got \"${prop}\"`
`No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got \"${prop}\"`,
)
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ export const footprinter = (): Footprinter & { string: typeof string } => {
return proxy
}
},
}
},
)
return proxy as any
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/platedhole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const platedhole = (
x: number,
y: number,
id: number | string,
od: number | string
od: number | string,
): PCBPlatedHole => {
return {
type: "pcb_plated_hole",
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/rectpad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const rectpad = (
x: number,
y: number,
w: number,
h: number
h: number,
): PCBSMTPad => {
return {
type: "pcb_smtpad",
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/u-curve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const u_curve = Array.from({ length: 9 }, (_, i) =>
Math.cos((i / 8) * Math.PI - Math.PI)
Math.cos((i / 8) * Math.PI - Math.PI),
).map((x) => ({
x,
y: -Math.sqrt(1 - x ** 2),
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/zod/dim-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export const dim2d = z
z.object({
x: z.number(),
y: z.number(),
})
}),
)
2 changes: 1 addition & 1 deletion tests/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const toPinPositionString = (soup: AnySoupElement[]) => {
(e: any) =>
`${e.pn.padEnd(2)}: ${e.x.toFixed(2).padStart(5)} ${e.y
.toFixed(2)
.padStart(5)}`
.padStart(5)}`,
)
.join("\n")
}

0 comments on commit 71f05a2

Please sign in to comment.