Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📐 formatting rules #153

Merged
merged 5 commits into from
Jan 20, 2025
Merged
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
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
plugins: ['@typescript-eslint', '@stylistic/eslint-plugin'],
extends: [
'eslint:recommended',
'plugin:react/recommended',
Expand All @@ -22,6 +22,11 @@ module.exports = {
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
}],
'@stylistic/indent': ['error', 2],
"@stylistic/space-infix-ops": 1,
'@stylistic/object-curly-spacing': ['error', 'always'],
// "semi": [1, "always"],
// "consistent-return": 2,
},
settings: {
react: {
Expand Down
223 changes: 222 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"scripts": {
"prebuild": "npm run lint",
"lint": "eslint --cache --ext .ts,.tsx src",
"lint": "eslint --cache --ext .ts,.tsx src && eslint --format stylish --fix src",
"build": "npm run build:server && npm run build:ui",
"build:server": "tsc",
"build:ui": "node --experimental-modules build.mjs",
Expand All @@ -36,6 +36,7 @@
"@craftamap/esbuild-plugin-html": "^0.7.0 || ^0.8.0",
"@rehooks/component-size": "^1.0.2",
"@serialport/bindings-cpp": "^12.0.0 || ^13.0.0",
"@stylistic/eslint-plugin": "^2.10.1",
"@types/cors": "^2.8.4",
"@types/express": "^4.17.9",
"@types/jest": "^29.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/background-planner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { replan } from './massager';

self.addEventListener("message", (m) => {
const {paths, planOptions} = m.data;
const { paths, planOptions } = m.data;
const plan = replan(paths, planOptions);
console.time("serializing");
const serialized = plan.serialize();
Expand Down
14 changes: 7 additions & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import yargs from "yargs";
import {connectEBB, startServer} from "./server";
import {replan} from "./massager";
import {Window} from "svgdom";
import { connectEBB, startServer } from "./server";
import { replan } from "./massager";
import { Window } from "svgdom";
import * as fs from "node:fs";
import {flattenSVG} from "flatten-svg";
import { flattenSVG } from "flatten-svg";
import type { Vec2 } from "./vec";
import { formatDuration } from "./util";
import { Device, type PlanOptions, defaultPlanOptions } from "./planning";
Expand Down Expand Up @@ -45,7 +45,7 @@ export function cli(argv: string[]): void {
} 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])})
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 @@ -219,7 +219,7 @@ export function cli(argv: string[]): void {
}
)
.command('pen [percent]', 'put the pen to [percent]', yargs => yargs
.positional('percent', { type: 'number', description: 'percent height between 0 and 100', required: true})
.positional('percent', { type: 'number', description: 'percent height between 0 and 100', required: true })
.check(args => args.percent >= 0 && args.percent <= 100),
async args => {
console.log('connecting to plotter...')
Expand Down Expand Up @@ -260,7 +260,7 @@ export function cli(argv: string[]): void {

function linesToVecs(lines: any[]): Vec2[][] {
return lines.map((line) => {
const a = line.points.map(([x, y]: [number, number]) => ({x, y}));
const a = line.points.map(([x, y]: [number, number]) => ({ x, y }));
(a as any).stroke = line.stroke;
(a as any).groupId = line.groupId;
return a;
Expand Down
6 changes: 3 additions & 3 deletions src/ebb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type Block, type Motion, PenMotion, type Plan, XYMotion} from "./planning";
import { type Block, type Motion, PenMotion, type Plan, XYMotion } from "./planning";
import { RegexParser } from "./regex-transform-stream";
import {type 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 @@ -21,7 +21,7 @@ export class EBB {
private microsteppingMode = 0;

/** Accumulated XY error, used to correct for movements with sub-step resolution */
private error: Vec2 = {x: 0, y: 0};
private error: Vec2 = { x: 0, y: 0 };

private cachedFirmwareVersion: [number, number, number] | undefined = undefined;

Expand Down
8 changes: 4 additions & 4 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, type Plan, type PlanOptions, plan} from "./planning";
import {dedupPoints, scaleToPaper, cropToMargins} from "./util";
import {type Vec2, vmul, vrot} from "./vec";
import { Device, type Plan, type PlanOptions, plan } from "./planning";
import { dedupPoints, scaleToPaper, cropToMargins } from "./util";
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 All @@ -19,7 +19,7 @@ export function replan(inPaths: Vec2[][], planOptions: PlanOptions): Plan {
if (planOptions.rotateDrawing !== 0) {
console.time("rotating paths");
paths = paths.map((pl) => pl.map((p) => vrot(p,
vmul({x:planOptions.paperSize.size.x/2, y: planOptions.paperSize.size.y/2}, 1/mmPerSvgUnit),
vmul({ x:planOptions.paperSize.size.x / 2, y: planOptions.paperSize.size.y / 2 }, 1 / mmPerSvgUnit),
planOptions.rotateDrawing)
));
console.timeEnd("rotating paths");
Expand Down
Loading
Loading