Skip to content

Commit

Permalink
Fix biome checks
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Nov 24, 2024
1 parent b6897c9 commit 6c1e0e3
Show file tree
Hide file tree
Showing 26 changed files with 3,717 additions and 2,872 deletions.
20 changes: 0 additions & 20 deletions .eslintrc.cjs

This file was deleted.

10 changes: 8 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"files": {
"ignoreUnknown": false,
"ignore": []
"ignore": ["docs", "dist"]
},
"formatter": {
"enabled": true,
Expand All @@ -19,7 +19,13 @@
"linter": {
"enabled": true,
"rules": {
"recommended": true
"recommended": true,
"style": {
"noParameterAssign": "off"
},
"suspicious": {
"noExplicitAny": "off"
}
}
},
"javascript": {
Expand Down
2 changes: 1 addition & 1 deletion lib/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`toGeoJSON > addresses.kml 1`] = `
{
Expand Down
14 changes: 7 additions & 7 deletions lib/gpx.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type {
FeatureCollection,
Feature,
Point,
MultiLineString,
FeatureCollection,
LineString,
MultiLineString,
Point,
Position,
} from "geojson";
import { getLineStyle } from "./gpx/line";
import { coordPair } from "./gpx/coord_pair";
import { getLineStyle } from "./gpx/line";
import { extractProperties } from "./gpx/properties";
import { P, $, get1, getMulti, type NS } from "./shared";
import { $, type NS, type P, get1, getMulti } from "./shared";

/**
* Extract points from a trkseg or rte element.
Expand All @@ -29,7 +29,7 @@ function getPoints(node: Element, pointname: "trkpt" | "rtept") {
if (c.time) times.push(c.time);
for (const [name, val] of c.extendedValues) {
const plural =
name === "heart" ? name : name.replace("gpxtpx:", "") + "s";
name === "heart" ? name : `${name.replace("gpxtpx:", "")}s`;
if (!extendedValues[plural]) {
extendedValues[plural] = Array(pts.length).fill(null);
}
Expand Down Expand Up @@ -80,7 +80,7 @@ function getTrack(
const line = getPoints(segment, "trkpt");
if (line) {
extractedLines.push(line);
if (line.times && line.times.length) times.push(line.times);
if (line.times?.length) times.push(line.times);
}
}

Expand Down
12 changes: 6 additions & 6 deletions lib/gpx/coord_pair.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Position } from "geojson";
import { num1, get1, nodeVal } from "../shared";
import { ExtendedValues, getExtensions } from "./extensions";
import type { Position } from "geojson";
import { get1, nodeVal, num1 } from "../shared";
import { type ExtendedValues, getExtensions } from "./extensions";

interface CoordPair {
coordinates: Position;
Expand All @@ -10,11 +10,11 @@ interface CoordPair {

export function coordPair(node: Element): CoordPair | null {
const ll = [
parseFloat(node.getAttribute("lon") || ""),
parseFloat(node.getAttribute("lat") || ""),
Number.parseFloat(node.getAttribute("lon") || ""),
Number.parseFloat(node.getAttribute("lat") || ""),
];

if (isNaN(ll[0]) || isNaN(ll[1])) {
if (Number.isNaN(ll[0]) || Number.isNaN(ll[1])) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/gpx/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ function abbreviateName(name: string) {
}

function parseNumeric(val: string) {
const num = parseFloat(val);
return isNaN(num) ? val : num;
const num = Number.parseFloat(val);
return Number.isNaN(num) ? val : num;
}
2 changes: 1 addition & 1 deletion lib/gpx/line.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, P, val1, $num } from "../shared";
import { $num, type P, get, val1 } from "../shared";

export function getLineStyle(node: Element | null) {
return get(node, "line", (lineStyle) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/gpx/properties.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $, getMulti, nodeVal, type NS } from "../shared";
import { $, type NS, getMulti, nodeVal } from "../shared";

export function extractProperties(ns: NS, node: Element) {
const properties = getMulti(node, [
Expand Down
13 changes: 8 additions & 5 deletions lib/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { describe, it, expect } from "vitest";
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";
import { check } from "@placemarkio/check-geojson";
import * as tj from "./index";
import xmldom from "@xmldom/xmldom";
import { describe, expect, it } from "vitest";
import * as tj from "./index";

const d = "./test/data/";

function parse(file: string) {
return new xmldom.DOMParser().parseFromString(fs.readFileSync(file, "utf8"));
return new xmldom.DOMParser().parseFromString(
fs.readFileSync(file, "utf8"),
"text/xml"
);
}

describe("toGeoJSON", () => {
Expand Down
19 changes: 9 additions & 10 deletions lib/kml.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { FeatureCollection, Geometry } from "geojson";
import { extractStyle } from "./kml/extractStyle";
import { getPlacemark } from "./kml/placemark";
import { getGroundOverlay } from "./kml/ground_overlay";
import { FeatureCollection, Geometry } from "geojson";
import { getPlacemark } from "./kml/placemark";
import { type Schema, typeConverters } from "./kml/shared";
import {
$,
StyleMap,
P,
F,
val1,
nodeVal,
type F,
type P,
type StyleMap,
isElement,
nodeVal,
normalizeId,
val1,
} from "./shared";
import { Schema, typeConverters } from "./kml/shared";

/**
* Options to customize KML output.
Expand Down Expand Up @@ -102,8 +102,7 @@ function buildSchema(node: Document): Schema {
const schema: Schema = {};
for (const field of $(node, "SimpleField")) {
schema[field.getAttribute("name") || ""] =
typeConverters[field.getAttribute("type") || ""] ||
typeConverters["string"];
typeConverters[field.getAttribute("type") || ""] || typeConverters.string;
}
return schema;
}
Expand Down
7 changes: 4 additions & 3 deletions lib/kml/extractStyle.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { extractStyle } from "./extractStyle";
import { describe, it, expect } from "vitest";
import xmldom from "@xmldom/xmldom";
import { describe, expect, it } from "vitest";
import { extractStyle } from "./extractStyle";

function parse(xml: string): Element {
return new xmldom.DOMParser().parseFromString(xml).firstChild as Element;
return new xmldom.DOMParser().parseFromString(xml, "text/xml")
.firstChild as Element;
}

describe("extractStyle", () => {
Expand Down
8 changes: 4 additions & 4 deletions lib/kml/extractStyle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { P, get, num1, nodeVal, val1 } from "../shared";
import { type P, get, nodeVal, num1, val1 } from "../shared";
import { fixColor } from "./fixColor";

function numericProperty(node: Element, source: string, target: string): P {
Expand Down Expand Up @@ -29,11 +29,11 @@ export function extractIcon(node: Element) {
numericProperty(iconStyle, "scale", "icon-scale"),
numericProperty(iconStyle, "heading", "icon-heading"),
get(iconStyle, "hotSpot", (hotspot) => {
const left = parseFloat(hotspot.getAttribute("x") || "");
const top = parseFloat(hotspot.getAttribute("y") || "");
const left = Number.parseFloat(hotspot.getAttribute("x") || "");
const top = Number.parseFloat(hotspot.getAttribute("y") || "");
const xunits = hotspot.getAttribute("xunits") || "";
const yunits = hotspot.getAttribute("yunits") || "";
if (!isNaN(left) && !isNaN(top))
if (!Number.isNaN(left) && !Number.isNaN(top))
return {
"icon-offset": [left, top],
"icon-offset-units": [xunits, yunits],
Expand Down
2 changes: 1 addition & 1 deletion lib/kml/fixColor.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest";
import { describe, expect, it } from "vitest";
import { fixColor } from "./fixColor";

describe("fixColor", () => {
Expand Down
11 changes: 6 additions & 5 deletions lib/kml/fixColor.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { P } from "../shared";
import type { P } from "../shared";

export function fixColor(v: string, prefix: string): P {
const properties: P = {};
const colorProp =
prefix == "stroke" || prefix === "fill" ? prefix : prefix + "-color";
prefix === "stroke" || prefix === "fill" ? prefix : `${prefix}-color`;
if (v[0] === "#") {
v = v.substring(1);
}
if (v.length === 6 || v.length === 3) {
properties[colorProp] = "#" + v;
properties[colorProp] = `#${v}`;
} else if (v.length === 8) {
properties[prefix + "-opacity"] = parseInt(v.substring(0, 2), 16) / 255;
properties[`${prefix}-opacity`] =
Number.parseInt(v.substring(0, 2), 16) / 255;
properties[colorProp] =
"#" + v.substring(6, 8) + v.substring(4, 6) + v.substring(2, 4);
`#${v.substring(6, 8)}${v.substring(4, 6)}${v.substring(2, 4)}`;
}
return properties;
}
2 changes: 1 addition & 1 deletion lib/kml/geometry.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest";
import { describe, expect, it } from "vitest";
import { coord, coord1, fixRing } from "./geometry";

describe("coord1", () => {
Expand Down
10 changes: 5 additions & 5 deletions lib/kml/geometry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Position, Point, LineString, Geometry } from "geojson";
import { $, $ns, nodeVal, get1, isElement } from "../shared";
import type { Geometry, LineString, Point, Position } from "geojson";
import { $, $ns, get1, isElement, nodeVal } from "../shared";

const removeSpace = /\s*/g;
const trimSpace = /^\s*|\s*$/g;
Expand All @@ -12,8 +12,8 @@ export function coord1(value: string): Position {
return value
.replace(removeSpace, "")
.split(",")
.map(parseFloat)
.filter((num) => !isNaN(num))
.map(Number.parseFloat)
.filter((num) => !Number.isNaN(num))
.slice(0, 3);
}

Expand All @@ -39,7 +39,7 @@ function gxCoords(
}

const coordinates = elems.map((elem) => {
return nodeVal(elem).split(" ").map(parseFloat);
return nodeVal(elem).split(" ").map(Number.parseFloat);
});

if (coordinates.length === 0) {
Expand Down
14 changes: 7 additions & 7 deletions lib/kml/ground_overlay.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Feature, Polygon } from "geojson";
import { StyleMap, get1, num1, getMulti } from "../shared";
import type { Feature, Polygon } from "geojson";
import type { KMLOptions } from "lib/kml";
import { type StyleMap, get1, getMulti, num1 } from "../shared";
import { extractIconHref, extractStyle } from "./extractStyle";
import { coord, fixRing, getCoordinates } from "./geometry";
import {
type Schema,
extractCascadedStyle,
extractExtendedData,
extractTimeSpan,
extractTimeStamp,
getMaybeHTMLDescription,
Schema,
} from "./shared";
import { extractIconHref, extractStyle } from "./extractStyle";
import { coord, fixRing, getCoordinates } from "./geometry";
import { KMLOptions } from "lib/kml";

interface BoxGeometry {
bbox?: BBox;
Expand Down Expand Up @@ -48,7 +48,7 @@ function rotateBox(
coordinates[0].map((coordinate) => {
const dy = coordinate[1] - center[1];
const dx = coordinate[0] - center[0];
const distance = Math.sqrt(Math.pow(dy, 2) + Math.pow(dx, 2));
const distance = Math.sqrt(dy ** 2 + dx ** 2);
const angle = Math.atan2(dy, dx) + rotation * DEGREES_TO_RADIANS;

return [
Expand Down
12 changes: 6 additions & 6 deletions lib/kml/placemark.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Feature, Geometry } from "geojson";
import { StyleMap, getMulti } from "../shared";
import type { Feature, Geometry } from "geojson";
import type { KMLOptions } from "lib/kml";
import { type StyleMap, getMulti } from "../shared";
import { extractStyle } from "./extractStyle";
import { getGeometry } from "./geometry";
import {
type Schema,
extractCascadedStyle,
extractExtendedData,
extractTimeSpan,
extractTimeStamp,
getMaybeHTMLDescription,
Schema,
} from "./shared";
import { extractStyle } from "./extractStyle";
import { getGeometry } from "./geometry";
import { KMLOptions } from "lib/kml";

function geometryListToGeometry(geometries: Geometry[]): Geometry | null {
return geometries.length === 0
Expand Down
6 changes: 3 additions & 3 deletions lib/kml/shared.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
$,
type P,
type StyleMap,
get,
get1,
nodeVal,
$,
normalizeId,
P,
StyleMap,
val1,
} from "../shared";

Expand Down
Loading

0 comments on commit 6c1e0e3

Please sign in to comment.