Skip to content

Commit

Permalink
Don't allow console logging statements (#96)
Browse files Browse the repository at this point in the history
* Don't allow `console` logging statements
  • Loading branch information
mondeja authored May 12, 2022
1 parent 3980277 commit bf44c72
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
]
],
"rules": { "no-console": ["error", { "allow": ["time", "timeEnd"] }] }
}
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ $ svg-path-bbox "M5 10c3 0 3 3 0 3z" "M2 8m5 5z"
import svgPathBbox from "svg-path-bbox";
import type { BBox } from "svg-path-bbox";

type CasesTuple = Array<[string, BBox]>;

const cases: CasesTuple = [["M0 0H3V6Z", [0, 0, 3, 6]]];
const cases: [string, BBox][] = [["M0 0H3V6Z", [0, 0, 3, 6]]];
console.log(svgPathBbox(cases[0]));
```

Expand Down
4 changes: 3 additions & 1 deletion examples/common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const util = require("util")
const svgPathBbox = require("../dist/wrapper.js");

console.log(svgPathBbox("M0 0H3V6Z"));
const bbox = svgPathBbox("M0 0H3V6Z");
process.stdout.write(`${util.inspect(bbox)}\n`)
4 changes: 3 additions & 1 deletion examples/esm.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { inspect } from "node:util";
import svgPathBbox from "../dist/wrapper.js";

console.log(svgPathBbox("M0 0H3V6Z"));
const bbox = svgPathBbox("M0 0H3V6Z");
process.stdout.write(`${inspect(bbox)}\n`)
14 changes: 6 additions & 8 deletions examples/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { inspect } from "node:util";
import svgPathBbox from "../src";
import type { BBox } from "../src";

type CasesTuple = Array<[string, BBox]>;

const cases: CasesTuple = [["M0 0H3V6Z", [0, 0, 3, 6]]];
const cases: [string, BBox][] = [["M0 0H3V6Z", [0, 0, 3, 6]]];

for (const [path, expectedBbox] of cases) {
const result = svgPathBbox(path);
const stringResult = JSON.stringify(result);
if (stringResult !== JSON.stringify(expectedBbox)) {
console.error(`UNEXPECTED BBOX: ${result}`);
const bbox = svgPathBbox(path);
if (JSON.stringify(bbox) !== JSON.stringify(expectedBbox)) {
process.stderr.write(`UNEXPECTED BBOX: ${inspect(bbox)}\n`);
process.exit(1);
} else {
console.log(result);
process.stdout.write(`${inspect(bbox)}\n`);
}
}
18 changes: 12 additions & 6 deletions scripts/benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { inspect } from "node:util";

import svgPathBbox from "../src";
import * as svgPathBoundingBox from "svg-path-bounding-box";
import type { BBox } from "../src";
Expand Down Expand Up @@ -47,7 +49,7 @@ const runLibrariesBenchmark = (
process.stdout.write(`${key} - `);
}

console.log(`${pathSummary} (type ${pathType}) [${e} epochs]`);
process.stdout.write(`${pathSummary} (type ${pathType}) [${e} epochs]\n`);
for (const library in LIBRARIES) {
console.time(library);
const func = LIBRARIES[library]["func"];
Expand All @@ -56,10 +58,12 @@ const runLibrariesBenchmark = (
for (let r = 0; r < e; r++) {
try {
result = func(path);
} catch (Error) {
} catch (err) {
if (!_errorRaised) {
console.error(`Error computing bbox with library ${library}:`);
console.error(Error);
process.stderr.write(
`Error computing bbox with library ${library}:\n`
);
process.stderr.write(`${err}\n`);
}
_errorRaised = true;
}
Expand All @@ -72,10 +76,12 @@ const runLibrariesBenchmark = (
result = resultParser(result as BoundingBoxView);
}
if (result) {
console.log(" + result:", result);
process.stdout.write(
` + result: ${inspect(result, { colors: true })}\n`
);
}
}
console.log();
process.stdout.write("\n");
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/changelog.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "node:fs";

test("Latest version has a CHANGELOG entry", () => {
test("Current version has a CHANGELOG entry", () => {
const changelog = fs.readFileSync("CHANGELOG.md", "utf8");
const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));

Expand Down

0 comments on commit bf44c72

Please sign in to comment.