Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrudd2 committed Apr 20, 2024
1 parent 7a50c18 commit f1810a0
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 32 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ module.exports = {
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
"indent": "off",
indent: "off",
"@typescript-eslint/indent": ["error", 2],
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-unused-vars": ["error", {
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
}],
},
settings: {
Expand Down
8 changes: 4 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import yargs from "yargs";
import {connectEBB, startServer} from "./server";
import {replan} from "./massager";
import {Window} from "svgdom";
import * as fs from "fs";
import * as fs from "node:fs";
import {flattenSVG} from "flatten-svg";
import { Vec2 } from "./vec";
import type { Vec2 } from "./vec";
import { formatDuration } from "./util";
import { Device, PlanOptions, defaultPlanOptions } from "./planning";
import { Device, type PlanOptions, defaultPlanOptions } from "./planning";
import { PaperSize } from "./paper-size";
import { Hardware } from "./ebb";
import type { Hardware } from "./ebb";

function parseSvg(svg: string) {
const window = new Window
Expand Down
9 changes: 7 additions & 2 deletions src/ebb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Block, Motion, PenMotion, Plan, XYMotion} from "./planning";
import {type Block, type Motion, PenMotion, type Plan, XYMotion} from "./planning";
import { RegexParser } from "./regex-transform-stream";
import {Vec2, vsub} from "./vec";
import {type Vec2, vsub} from "./vec";

/** Split d into its fractional and integral parts */
function modf(d: number): [number, number] {
Expand All @@ -27,6 +27,7 @@ export class EBB {

public constructor (port: SerialPort, hardware: Hardware = 'v3') {
this.hardware = hardware
console.log(this.hardware)
this.port = port;
this.writer = this.port.writable.getWriter();
this.commandQueue = [];
Expand Down Expand Up @@ -73,6 +74,10 @@ export class EBB {
return await this.port.close()
}

public changeHardware(hardware: Hardware) {
this.hardware = hardware;
}

private write(str: string): Promise<void> {
if (process.env.DEBUG_SAXI_COMMANDS) {
console.log(`writing: ${str}`)
Expand Down
1 change: 0 additions & 1 deletion src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ declare module 'flatten-svg/svg-to-paths' {
groupId?: string;
}
export function flattenSVG(svg: SVGElement, options?: Partial<Options>): Line[];
export {};

}
declare module 'flatten-svg' {
Expand Down
4 changes: 2 additions & 2 deletions src/massager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Optimization from "optimize-paths";
import {Device, Plan, PlanOptions, plan} from "./planning";
import {Device, type Plan, type PlanOptions, plan} from "./planning";
import {dedupPoints, scaleToPaper, cropToMargins} from "./util";
import {Vec2, vmul, vrot} from "./vec";
import {type Vec2, vmul, vrot} from "./vec";

// CSS, and thus SVG, defines 1px = 1/96th of 1in
// https://www.w3.org/TR/css-values-4/#absolute-lengths
Expand Down
2 changes: 1 addition & 1 deletion src/paper-size.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Vec2, vmul} from "./vec";
import {type Vec2, vmul} from "./vec";

function vround(v: Vec2, digits = 2): Vec2 {
return { x: Number(v.x.toFixed(digits)), y: Number(v.y.toFixed(digits)) };
Expand Down
4 changes: 2 additions & 2 deletions src/planning.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Cribbed from https://github.com/fogleman/axi/blob/master/axi/planner.py
import { Hardware } from './ebb'
import type { Hardware } from './ebb'
import { PaperSize } from './paper-size'
import { vadd, vdot, Vec2, vlen, vmul, vnorm, vsub } from './vec'
import { vadd, vdot, type Vec2, vlen, vmul, vnorm, vsub } from './vec'
const epsilon = 1e-9

export interface PlanOptions {
Expand Down
4 changes: 2 additions & 2 deletions src/serialport-serialport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from "events";
import { EventEmitter } from "node:events";
import { SerialPort as NodeSerialPort } from "serialport";
import { OpenOptions } from "@serialport/bindings-interface"
import type { OpenOptions } from "@serialport/bindings-interface"

function readableStreamFromAsyncIterable<T>(iterable: AsyncIterable<T>) {
const it = iterable[Symbol.asyncIterator]();
Expand Down
14 changes: 7 additions & 7 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import cors from "cors";
import "web-streams-polyfill/es2018"
import express from "express";
import http from "http";
import path from "path";
import { PortInfo } from "@serialport/bindings-interface"
import http from "node:http";
import path from "node:path";
import type { PortInfo } from "@serialport/bindings-interface"
import { WakeLock } from "wake-lock";
import WebSocket from "ws";
import { SerialPortSerialPort } from "./serialport-serialport";
import { Device, PenMotion, Motion, Plan } from "./planning";
import { Device, PenMotion, type Motion, Plan } from "./planning";
import { formatDuration } from "./util";
import { autoDetect } from '@serialport/bindings-cpp';
import * as _self from './server' // use self-import for test mocking

import { EBB, Hardware } from './ebb'
import { EBB, type Hardware } from './ebb'

type Com = string

Expand Down Expand Up @@ -293,10 +293,10 @@ async function * ebbs (path?: string, hardware: Hardware = 'v3') {
yield new EBB(port, hardware);
await closed;
yield null;
console.error(`Lost connection to EBB, reconnecting...`);
console.error("Lost connection to EBB, reconnecting...");
} catch (e) {
console.error(`Error connecting to EBB: ${e.message}`);
console.error(`Retrying in 5 seconds...`);
console.error("Retrying in 5 seconds...");
await sleep(5000);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/ui.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import useComponentSize from "@rehooks/component-size";
import React, { ChangeEvent, Fragment, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useReducer } from "react";
import React, { type ChangeEvent, Fragment, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useReducer } from "react";
import { createRoot } from 'react-dom/client';
import interpolator from "color-interpolate"
import colormap from "colormap"

import {flattenSVG} from "flatten-svg";
import {PaperSize} from "./paper-size";
import {Device, Plan, PlanOptions, defaultPlanOptions, XYMotion, PenMotion} from "./planning";
import {Device, Plan, type PlanOptions, defaultPlanOptions, XYMotion, PenMotion} from "./planning";
import {formatDuration} from "./util";
import {Vec2} from "./vec";
import type {Vec2} from "./vec";

import PlanWorker from "./plan.worker";

Expand All @@ -17,7 +17,7 @@ import "./style.css";
import pathJoinRadiusIcon from "./icons/path-joining radius.svg";
import pointJoinRadiusIcon from "./icons/point-joining radius.svg";
import rotateDrawingIcon from "./icons/rotate-drawing.svg";
import { EBB, Hardware } from "./ebb";
import { EBB, type Hardware } from "./ebb";

const defaultVisualizationOptions = {
penStrokeWidth: 0.5,
Expand Down Expand Up @@ -258,7 +258,7 @@ class SaxiDriver implements Driver {
this.socket = new WebSocket(`${websocketProtocol}://${document.location.host}/chat`);

this.socket.addEventListener("open", () => {
console.log(`Connected to EBB server.`);
console.log("Connected to EBB server.");
this.connected = true;
if (this.onconnectionchange) {
this.onconnectionchange(true);
Expand Down Expand Up @@ -310,7 +310,7 @@ class SaxiDriver implements Driver {
// TODO: something
});
this.socket.addEventListener("close", () => {
console.log(`Disconnected from EBB server, reconnecting in 5 seconds.`);
console.log("Disconnected from EBB server, reconnecting in 5 seconds.");
window.clearInterval(this.pingInterval);
this.pingInterval = null;
this.connected = false;
Expand Down
4 changes: 2 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PaperSize} from "./paper-size";
import {vadd, Vec2, vlen2, vmul, vsub} from "./vec";
import type {PaperSize} from "./paper-size";
import {vadd, type Vec2, vlen2, vmul, vsub} from "./vec";

/** Format a smallish duration in 2h30m15s form */
export function formatDuration(seconds: number): string {
Expand Down

0 comments on commit f1810a0

Please sign in to comment.