Skip to content

Commit

Permalink
apply all safe linting changes [#112]
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Jan 23, 2024
1 parent 514458c commit c19b45d
Show file tree
Hide file tree
Showing 23 changed files with 639 additions and 616 deletions.
4 changes: 2 additions & 2 deletions src/attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class NumberAttr {
value: AttrOption<number>;
per_feature: boolean;

constructor(c: AttrOption<number> | undefined, defaultValue: number = 1) {
constructor(c: AttrOption<number> | undefined, defaultValue = 1) {
this.value = c ?? defaultValue;
this.per_feature =
typeof this.value == "function" && this.value.length == 2;
Expand Down Expand Up @@ -62,7 +62,7 @@ export class TextAttr {
} else {
label_props = this.label_props;
}
for (let property of label_props) {
for (const property of label_props) {
if (
f.props.hasOwnProperty(property) &&
typeof f.props[property] === "string"
Expand Down
50 changes: 25 additions & 25 deletions src/compat/json_style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Feature, JsonValue } from "../tilecache";
import {
CenteredTextSymbolizer,
CircleSymbolizer,
exp,
LineLabelSymbolizer,
LineSymbolizer,
PolygonSymbolizer,
exp,
} from "./../symbolizer";

function number(val: JsonValue, defaultValue: number) {
Expand All @@ -22,7 +22,7 @@ export function filterFn(arr: any[]): Filter {
} else if (arr[0] == "!=") {
return (z, f) => f.props[arr[1]] !== arr[2];
} else if (arr[0] == "!") {
let sub = filterFn(arr[1]);
const sub = filterFn(arr[1]);
return (z, f) => !sub(z, f);
} else if (arr[0] === "<") {
return (z, f) => number(f.props[arr[1]], Infinity) < arr[2];
Expand All @@ -41,13 +41,13 @@ export function filterFn(arr: any[]): Filter {
} else if (arr[0] === "!has") {
return (z, f) => !f.props.hasOwnProperty(arr[1]);
} else if (arr[0] === "all") {
let parts = arr.slice(1, arr.length).map((e) => filterFn(e));
const parts = arr.slice(1, arr.length).map((e) => filterFn(e));
return (z, f) =>
parts.every((p) => {
return p(z, f);
});
} else if (arr[0] === "any") {
let parts = arr.slice(1, arr.length).map((e) => filterFn(e));
const parts = arr.slice(1, arr.length).map((e) => filterFn(e));
return (z, f) =>
parts.some((p) => {
return p(z, f);
Expand All @@ -68,19 +68,19 @@ export function numberFn(obj: any): (z: number, f?: Feature) => number {
obj[1][0] == "exponential" &&
obj[2] == "zoom"
) {
let slice = obj.slice(3);
let stops: number[][] = [];
const slice = obj.slice(3);
const stops: number[][] = [];
for (var i = 0; i < slice.length; i += 2) {
stops.push([slice[i], slice[i + 1]]);
}
return (z: number) => {
return exp(obj[1][1], stops)(z - 1);
};
} else if (obj[0] == "step" && obj[1][0] == "get") {
let slice = obj.slice(2);
let prop = obj[1][1];
const slice = obj.slice(2);
const prop = obj[1][1];
return (z: number, f?: Feature) => {
let val = f?.props[prop];
const val = f?.props[prop];
if (typeof val === "number") {
if (val < slice[1]) return slice[0];
for (i = 1; i < slice.length; i += 2) {
Expand All @@ -97,7 +97,7 @@ export function numberFn(obj: any): (z: number, f?: Feature) => number {

export function numberOrFn(
obj: any,
defaultValue = 0
defaultValue = 0,
): number | ((z: number, f?: Feature) => number) {
if (!obj) return defaultValue;
if (typeof obj == "number") {
Expand All @@ -108,10 +108,10 @@ export function numberOrFn(
}

export function widthFn(width_obj: any, gap_obj: any) {
let w = numberOrFn(width_obj, 1);
let g = numberOrFn(gap_obj);
const w = numberOrFn(width_obj, 1);
const g = numberOrFn(gap_obj);
return (z: number, f?: Feature) => {
let tmp = typeof w == "number" ? w : w(z, f);
const tmp = typeof w == "number" ? w : w(z, f);
if (g) {
return tmp + (typeof g == "number" ? g : g(z, f));
}
Expand All @@ -126,15 +126,15 @@ interface FontSub {
}

export function getFont(obj: any, fontsubmap: any) {
let fontfaces: FontSub[] = [];
for (let wanted_face of obj["text-font"]) {
const fontfaces: FontSub[] = [];
for (const wanted_face of obj["text-font"]) {
if (fontsubmap.hasOwnProperty(wanted_face)) {
fontfaces.push(fontsubmap[wanted_face]);
}
}
if (fontfaces.length === 0) fontfaces.push({ face: "sans-serif" });

let text_size = obj["text-size"];
const text_size = obj["text-size"];
// for fallbacks, use the weight and style of the first font
var weight = "";
if (fontfaces.length && fontfaces[0].weight)
Expand All @@ -151,14 +151,14 @@ export function getFont(obj: any, fontsubmap: any) {
var base = 1.4;
if (text_size.base) base = text_size.base;
else text_size.base = base;
let t = numberFn(text_size);
const t = numberFn(text_size);
return (z: number, f?: Feature) => {
return `${style}${weight}${t(z, f)}px ${fontfaces
.map((f) => f.face)
.join(", ")}`;
};
} else if (text_size[0] == "step") {
let t = numberFn(text_size);
const t = numberFn(text_size);
return (z: number, f?: Feature) => {
return `${style}${weight}${t(z, f)}px ${fontfaces
.map((f) => f.face)
Expand All @@ -171,9 +171,9 @@ export function getFont(obj: any, fontsubmap: any) {
}

export function json_style(obj: any, fontsubmap: Map<string, FontSub>) {
let paint_rules = [];
let label_rules = [];
let refs = new Map<string, any>();
const paint_rules = [];
const label_rules = [];
const refs = new Map<string, any>();

for (var layer of obj.layers) {
refs.set(layer.id, layer);
Expand All @@ -183,14 +183,14 @@ export function json_style(obj: any, fontsubmap: Map<string, FontSub>) {
}

if (layer.ref) {
let referenced = refs.get(layer.ref);
const referenced = refs.get(layer.ref);
layer.type = referenced.type;
layer.filter = referenced.filter;
layer.source = referenced["source"];
layer["source-layer"] = referenced["source-layer"];
}

let sourceLayer = layer["source-layer"];
const sourceLayer = layer["source-layer"];
var symbolizer;

var filter = undefined;
Expand Down Expand Up @@ -227,7 +227,7 @@ export function json_style(obj: any, fontsubmap: Map<string, FontSub>) {
symbolizer: new LineSymbolizer({
width: widthFn(
layer.paint["line-width"],
layer.paint["line-gap-width"]
layer.paint["line-gap-width"],
),
dash: layer.paint["line-dasharray"],
dashColor: layer.paint["line-color"],
Expand All @@ -241,7 +241,7 @@ export function json_style(obj: any, fontsubmap: Map<string, FontSub>) {
color: layer.paint["line-color"],
width: widthFn(
layer.paint["line-width"],
layer.paint["line-gap-width"]
layer.paint["line-gap-width"],
),
}),
});
Expand Down
34 changes: 17 additions & 17 deletions src/default_style/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Rule } from "../painter";
import {
CenteredTextSymbolizer,
CircleSymbolizer,
exp,
FlexSymbolizer,
GroupSymbolizer,
LabelSymbolizer,
Expand All @@ -14,6 +13,7 @@ import {
PolygonLabelSymbolizer,
PolygonSymbolizer,
ShieldSymbolizer,
exp,
} from "../symbolizer";
import { Feature } from "../tilecache";

Expand Down Expand Up @@ -53,18 +53,18 @@ export interface DefaultStyleParams {
}

const doShading = (params: DefaultStyleParams, shade: string) => {
let shadeHsl = parseToHsla(shade);
let outParams: any = { ...params };
const shadeHsl = parseToHsla(shade);
const outParams: any = { ...params };
for (const [key, value] of Object.entries(params)) {
let o = parseToHsla(value);
const o = parseToHsla(value);
outParams[key] = hsla(shadeHsl[0], shadeHsl[1], o[2], o[3]);
}
return outParams;
};

export const paintRules = (
params: DefaultStyleParams,
shade?: string
shade?: string,
): Rule[] => {
if (shade) params = doShading(params, shade);
return [
Expand Down Expand Up @@ -320,13 +320,13 @@ export const labelRules = (
params: DefaultStyleParams,
shade?: string,
language1?: string[],
language2?: string[]
language2?: string[],
): LabelRule[] => {
if (shade) params = doShading(params, shade);
var nametags = ["name"];
if (language1) nametags = language1;

let languageStack = (symbolizer: LabelSymbolizer, fill: string) => {
const languageStack = (symbolizer: LabelSymbolizer, fill: string) => {
if (!language2) return symbolizer;
if (symbolizer instanceof OffsetTextSymbolizer) {
return new FlexSymbolizer([
Expand Down Expand Up @@ -361,7 +361,7 @@ export const labelRules = (
},
textTransform: "uppercase",
}),
params.countryLabel
params.countryLabel,
),
filter: (z, f) => {
return f.props["pmap:kind"] == "country";
Expand All @@ -375,7 +375,7 @@ export const labelRules = (
fill: params.stateLabel,
font: "300 16px sans-serif",
}),
params.stateLabel
params.stateLabel,
),
filter: (z, f) => {
return f.props["pmap:kind"] == "state";
Expand All @@ -402,7 +402,7 @@ export const labelRules = (
}
},
}),
params.cityLabel
params.cityLabel,
),
sort: (a: any, b: any) => {
return a["pmap:rank"] - b["pmap:rank"];
Expand Down Expand Up @@ -436,7 +436,7 @@ export const labelRules = (
}
},
}),
params.cityLabel
params.cityLabel,
),
]),
sort: (a: any, b: any) => {
Expand All @@ -453,7 +453,7 @@ export const labelRules = (
font: "500 10px sans-serif",
textTransform: "uppercase",
}),
params.neighbourhoodLabel
params.neighbourhoodLabel,
),
filter: (z, f) => {
return f.props["pmap:kind"] == "neighbourhood";
Expand All @@ -467,7 +467,7 @@ export const labelRules = (
fill: params.landuseLabel,
font: "300 12px sans-serif",
}),
params.landuseLabel
params.landuseLabel,
),
},
{
Expand All @@ -478,7 +478,7 @@ export const labelRules = (
fill: params.waterLabel,
font: "italic 600 12px sans-serif",
}),
params.waterLabel
params.waterLabel,
),
},
{
Expand All @@ -489,7 +489,7 @@ export const labelRules = (
fill: params.naturalLabel,
font: "italic 300 12px sans-serif",
}),
params.naturalLabel
params.naturalLabel,
),
},
{
Expand All @@ -500,7 +500,7 @@ export const labelRules = (
fill: params.roadsLabel,
font: "500 12px sans-serif",
}),
params.roadsLabel
params.roadsLabel,
),
minzoom: 12,
},
Expand Down Expand Up @@ -532,7 +532,7 @@ export const labelRules = (
offsetY: 2,
font: "300 10px sans-serif",
}),
params.poisLabel
params.poisLabel,
),
]),
},
Expand Down
24 changes: 12 additions & 12 deletions src/extra_styles/toner.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Justify } from "../symbolizer";
import { Rule } from "../painter";
import { LabelRule } from "../labeler";
import { Font, Sheet } from "../task";
import { arr, exp, createPattern } from "../symbolizer";
import { Rule } from "../painter";
import { Justify } from "../symbolizer";
import { arr, createPattern, exp } from "../symbolizer";
import { CircleSymbolizer, IconSymbolizer } from "../symbolizer";
import {
GroupSymbolizer,
CenteredTextSymbolizer,
GroupSymbolizer,
OffsetTextSymbolizer,
} from "../symbolizer";
import { LineSymbolizer, LineLabelSymbolizer } from "../symbolizer";
import { PolygonSymbolizer, PolygonLabelSymbolizer } from "../symbolizer";
import { LineLabelSymbolizer, LineSymbolizer } from "../symbolizer";
import { PolygonLabelSymbolizer, PolygonSymbolizer } from "../symbolizer";
import { Font, Sheet } from "../task";
// import icons from './toner-icons.html'

// https://github.com/stamen/toner-carto/blob/master/map.mss
Expand All @@ -31,7 +31,7 @@ import { PolygonSymbolizer, PolygonLabelSymbolizer } from "../symbolizer";
// }

const Toner = (variant: string) => {
let halftone = createPattern(4, 4, (c) => {
const halftone = createPattern(4, 4, (c) => {
var ctx = c.getContext("2d");
if (ctx) {
ctx.beginPath();
Expand All @@ -47,10 +47,10 @@ const Toner = (variant: string) => {
background = "#d9d9d9";
}

let lang = ["name:en", "name"];
const lang = ["name:en", "name"];
// let sprites = Sprites(icons);

let paint_rules: Rule[] = [
const paint_rules: Rule[] = [
{
dataLayer: "earth",
symbolizer: new PolygonSymbolizer({
Expand Down Expand Up @@ -192,7 +192,7 @@ const Toner = (variant: string) => {
},
];

let label_rules: LabelRule[] = [
const label_rules: LabelRule[] = [
{
dataLayer: "places",
symbolizer: new CenteredTextSymbolizer({
Expand Down Expand Up @@ -344,7 +344,7 @@ const Toner = (variant: string) => {
Font(
"Inter",
"https://cdn.protomaps.com/fonts/woff2/Inter.var.woff2",
"100 900"
"100 900",
),
],
paint_rules: paint_rules,
Expand Down
Loading

0 comments on commit c19b45d

Please sign in to comment.