Skip to content

Commit

Permalink
Merge pull request #168 from alexrudd2/biome-lint
Browse files Browse the repository at this point in the history
More linting from Biome.js
  • Loading branch information
alexrudd2 authored Feb 18, 2025
2 parents d05fc4c + 698f630 commit 319dccc
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 30 deletions.
17 changes: 17 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"formatter": {
"enabled": false
},
"linter": {
"enabled": true,
"rules": {
"style": {
"useNumberNamespace": "off"
}
}
},
"organizeImports": {
"enabled": true
}
}
4 changes: 2 additions & 2 deletions src/__tests__/ebb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { MockBinding } from '@serialport/binding-mock';
jest.doMock('serialport', () => ({
SerialPort: SerialPort,
}));
import {EBB} from "../ebb";
import {SerialPortSerialPort} from "../serialport-serialport";
import { EBB } from "../ebb";
import { SerialPortSerialPort } from "../serialport-serialport";

describe("EBB", () => {
afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/planning.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Plan, plan, Device, AxidrawFast, XYMotion, PenMotion, defaultPlanOptions} from '../planning';
import {Vec2} from '../vec';
import { Plan, plan, Device, AxidrawFast, XYMotion, PenMotion, defaultPlanOptions } from '../planning';
import type { Vec2 } from '../vec';

describe("plan", () => {
const device = Device()
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/server-smoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { startServer, waitForEbb } from '../server';
import type { Server } from 'http';
import type { Server } from 'node:http';
import request from 'supertest';

jest.mock("../serialport-serialport")
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cropToMargins } from '../util'
import { PaperSize } from '../paper-size'
import { Vec2 } from '../vec'
import type { Vec2 } from '../vec'

describe("crop to margins", () => {
const paper = new PaperSize({x: 100, y: 100})
Expand Down
13 changes: 6 additions & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import yargs from "yargs";
import { connectEBB, startServer } from "./server";
import { replan } from "./massager";
import { Window } from "svgdom";
import * as fs from "node:fs";
import { readFileSync } from "node:fs";
import { flattenSVG } from "flatten-svg";
import type { Vec2 } from "./vec";
import { formatDuration } from "./util";
Expand Down Expand Up @@ -42,11 +42,10 @@ export function cli(argv: string[]): void {
coerce: (value) => {
if (Object.prototype.hasOwnProperty.call(PaperSize.standard, value)) {
return PaperSize.standard[value];
} else {
const m = /^([0-9]*(?:\.[0-9]+)?)\s*x\s*([0-9]*(?:\.[0-9]+)?)\s*(cm|mm|in)$/i.exec(String(value).trim());
if (m) {
return new PaperSize({ x: Number(m[1]), y: Number(m[2]) });
}
}
const m = /^([0-9]*(?:\.[0-9]+)?)\s*x\s*([0-9]*(?:\.[0-9]+)?)\s*(cm|mm|in)$/i.exec(String(value).trim());
if (m) {
return new PaperSize({ x: Number(m[1]), y: Number(m[2]) });
}
throw new Error(`Paper size should be a standard size (${Object.keys(PaperSize.standard).join(", ")}) or a custom size such as "100x100mm" or "16x10in"`);
},
Expand Down Expand Up @@ -163,7 +162,7 @@ export function cli(argv: string[]): void {
}),
async args => {
console.log("reading svg...");
const svg = fs.readFileSync(args.file, 'utf8');
const svg = readFileSync(args.file, 'utf8');
console.log("parsing svg...");
const parsed = parseSvg(svg);
console.log("flattening svg...");
Expand Down
8 changes: 4 additions & 4 deletions src/massager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Optimization from "optimize-paths";
import { reorder as sortPaths, elideShorterThan, merge as joinNearbyPaths } from "optimize-paths";
import { Device, type Plan, type PlanOptions, plan } from "./planning";
import { dedupPoints, scaleToPaper, cropToMargins } from "./util";
import { type Vec2, vmul, vrot } from "./vec";
Expand Down Expand Up @@ -51,19 +51,19 @@ export function replan(inPaths: Vec2[][], planOptions: PlanOptions): Plan {

if (planOptions.sortPaths) {
console.time("sorting paths");
paths = Optimization.reorder(paths);
paths = sortPaths(paths);
console.timeEnd("sorting paths");
}

if (planOptions.minimumPathLength > 0) {
console.time("eliding short paths");
paths = Optimization.elideShorterThan(paths, planOptions.minimumPathLength);
paths = elideShorterThan(paths, planOptions.minimumPathLength);
console.timeEnd("eliding short paths");
}

if (planOptions.pathJoinRadius > 0) {
console.time("joining nearby paths");
paths = Optimization.merge(
paths = joinNearbyPaths(
paths,
planOptions.pathJoinRadius
);
Expand Down
3 changes: 2 additions & 1 deletion src/planning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ export class Plan {
return new Plan(this.motions.map((motion, j) => {
if (motion instanceof XYMotion) {
return motion;
} else if (motion instanceof PenMotion) {
}
if (motion instanceof PenMotion) {
// TODO: Remove this hack by storing the pen-up/pen-down heights
// in a single place, and reference them from the PenMotions.
if (j === this.motions.length - 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function sleep(ms: number) {
}

function isEBB(p: PortInfo): boolean {
return p.manufacturer === "SchmalzHaus" || p.manufacturer === "SchmalzHaus LLC" || (p.vendorId == "04D8" && p.productId == "FD92");
return p.manufacturer === "SchmalzHaus" || p.manufacturer === "SchmalzHaus LLC" || (p.vendorId === "04D8" && p.productId === "FD92");
}

async function listEBBs() {
Expand Down
26 changes: 16 additions & 10 deletions src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ function PenHeight({ state, driver }: { state: State; driver: Driver }) {
</label>
</div>
<div className="flex">
<button onClick={penUp}>pen up</button>
<button onClick={penDown}>pen down</button>
<button type="button" onClick={penUp}>pen up</button>
<button type="button" onClick={penDown}>pen down</button>
</div>
</Fragment>;
}
Expand Down Expand Up @@ -518,6 +518,7 @@ function SwapPaperSizesButton({ onClick }: { onClick: () => void }) {
viewBox="0 0 14.05 11.46"
onClick={onClick}
>
<title>swap width and height</title>
<g>
<polygon points="14.05 3.04 8.79 0 8.79 1.78 1.38 1.78 1.38 4.29 8.79 4.29 8.79 6.08 14.05 3.04" />
<polygon points="0 8.43 5.26 11.46 5.26 9.68 12.67 9.68 12.67 7.17 5.26 7.17 5.26 5.39 0 8.43" />
Expand Down Expand Up @@ -608,7 +609,7 @@ function PaperConfig({ state }: { state: State }) {

function MotorControl({ driver }: { driver: Driver }) {
return <div>
<button onClick={() => driver.limp()}>disengage motors</button>
<button type="button" onClick={() => driver.limp()}>disengage motors</button>
</div>;
}

Expand Down Expand Up @@ -668,11 +669,10 @@ function PlanPreview(
const palette = colorPathsByStrokeOrder
? interpolator(colormap({ colormap: 'spring' }))
: () => 'rgba(0, 0, 0, 0.8)';
const lines = plan.motions.map((m) => {
if (m instanceof XYMotion) {
return m.blocks.map((b) => b.p1).concat([m.p2]);
} else { return []; }
}).filter((m) => m.length);
const lines = plan.motions
.filter((m) => m instanceof XYMotion)
.map((m) => m.blocks.map((b) => b.p1).concat([m.p2])) // Map each XYMotion to its start/end points
.filter((m) => m.length);
return <g transform={`scale(${1 / device.stepsPerMm})`}>
<title>Plot origin</title>
<text x={lines[0][0].x} y={lines[0][0].y}
Expand Down Expand Up @@ -740,6 +740,7 @@ function PlanPreview(
`translate(${posXMm / ps.size.x * 50}%,${posYMm / ps.size.y * 50}%)`
}}
>
<title>Progress percentage bar</title>
<g>
<path
d={`M-${width} 0l${width * 2} 0M0 -${height}l0 ${height * 2}`}
Expand Down Expand Up @@ -770,6 +771,7 @@ function PlanPreview(
height={height}
viewBox={`0 0 ${ps.size.x} ${ps.size.y}`}
>
<title>Plot preview</title>
{memoizedPlanPreview}
{margins}
</svg>
Expand Down Expand Up @@ -848,11 +850,13 @@ function PlotButtons(
{
isPlanning
? <button
type="button"
className="replan-button"
disabled={true}>
Replanning...
</button>
: <button
type="button"
className={`plot-button ${state.progress != null ? "plot-button--plotting" : ""}`}
disabled={plan == null || state.progress != null}
onClick={() => plot(plan)}>
Expand All @@ -861,11 +865,12 @@ function PlotButtons(
}
<div className={`button-row`}>
<button
type="button"
className={`cancel-button ${state.progress != null ? "cancel-button--active" : ""}`}
onClick={state.paused ? resume : pause}
disabled={plan == null || state.progress == null}
>{state.paused ? "Resume" : "Pause"}</button>
<button
<button type="button"
className={`cancel-button ${state.progress != null ? "cancel-button--active" : ""}`}
onClick={cancel}
disabled={plan == null || state.progress == null}
Expand All @@ -882,7 +887,7 @@ function ResetToDefaultsButton() {
dispatch({ type: "SET_PLAN_OPTION", value: { ...defaultPlanOptions } });
};

return <button className="button-link" onClick={onClick}>reset all options</button>;
return <button type="reset" className="button-link" onClick={onClick}>reset all options</button>;

}

Expand Down Expand Up @@ -1066,6 +1071,7 @@ function PortSelector({ driver, setDriver, hardware }: PortSelectorProps) {
{driver ? `Connected: ${driver.name()}` : null}
{!driver ?
<button
type="button"
disabled={initializing}
onClick={async () => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function liangBarsky(aabb: [Vec2, Vec2], seg: [Vec2, Vec2]): Vec2 | null {
let u2 = Infinity;

for (let i = 0; i < 4; i++) {
if (p[i] == 0) {
if (p[i] === 0) {
if (q[i] < 0)
return null;
} else {
Expand Down

0 comments on commit 319dccc

Please sign in to comment.