Skip to content

Commit

Permalink
Merge pull request #123 from protomaps/linting
Browse files Browse the repository at this point in the history
add linting to improve maintainability
  • Loading branch information
bdon committed Jan 23, 2024
2 parents 514458c + c0cccbe commit 2ef3814
Show file tree
Hide file tree
Showing 25 changed files with 1,056 additions and 797 deletions.
228 changes: 228 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"source": "src/index.ts",
"types": "dist/index.d.ts",
"devDependencies": {
"@biomejs/biome": "^1.5.3",
"@types/mapbox__point-geometry": "^0.1.2",
"@types/mapbox__vector-tile": "^1.3.0",
"@types/node": "^16.18.74",
Expand Down
24 changes: 12 additions & 12 deletions src/attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class StringAttr<T extends string = string> {

constructor(c: AttrOption<T> | undefined, defaultValue: T) {
this.str = c ?? defaultValue;
this.per_feature = typeof this.str == "function" && this.str.length == 2;
this.per_feature = typeof this.str === "function" && this.str.length === 2;
}

public get(z: number, f?: Feature): T {
Expand All @@ -24,14 +24,14 @@ 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;
typeof this.value === "function" && this.value.length === 2;
}

public get(z: number, f?: Feature): number {
if (typeof this.value == "function") {
if (typeof this.value === "function") {
return this.value(z, f);
} else {
return this.value;
Expand All @@ -57,12 +57,12 @@ export class TextAttr {
let retval: string | undefined;

let label_props: string[];
if (typeof this.label_props == "function") {
if (typeof this.label_props === "function") {
label_props = this.label_props(z, f);
} 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 Expand Up @@ -124,7 +124,7 @@ export class FontAttr {
return this.font;
}
} else {
var style = "";
let style = "";
if (this.style) {
if (typeof this.style === "function") {
style = this.style(z, f) + " ";
Expand All @@ -133,7 +133,7 @@ export class FontAttr {
}
}

var weight = "";
let weight = "";
if (this.weight) {
if (typeof this.weight === "function") {
weight = this.weight(z, f) + " ";
Expand All @@ -142,14 +142,14 @@ export class FontAttr {
}
}

var size;
let size;
if (typeof this.size === "function") {
size = this.size(z, f);
} else {
size = this.size;
}

var family;
let family;
if (typeof this.family === "function") {
family = this.family(z, f);
} else {
Expand All @@ -168,11 +168,11 @@ export class ArrayAttr<T = number> {
constructor(c: AttrOption<T[]>, defaultValue: T[] = []) {
this.value = c ?? defaultValue;
this.per_feature =
typeof this.value == "function" && this.value.length == 2;
typeof this.value === "function" && this.value.length === 2;
}

public get(z: number, f?: Feature): T[] {
if (typeof this.value == "function") {
if (typeof this.value === "function") {
return this.value(z, f);
} else {
return this.value;
Expand Down

0 comments on commit 2ef3814

Please sign in to comment.