Skip to content

Commit

Permalink
chore(deps-dev): 🔧 fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
iwpnd committed Sep 28, 2024
1 parent 6ea65c9 commit a1181c3
Show file tree
Hide file tree
Showing 22 changed files with 271 additions and 223 deletions.
21 changes: 21 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{
ignores: ['eslint.config.mjs', 'node_modules', 'dist'],
},
{
languageOptions: {
parserOptions: {
warnOnUnsupportedTypeScriptVersion: false,
projectService: true,
tsconfigRootDir: import.meta.dirname,
project: ['./tsconfig.eslint.json'],
},
},
},
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked
);
29 changes: 22 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "2.4.0",
"description": "A Node.js Tile38 client written in TypeScript",
"main": "dist/index.js",
"files": ["dist"],
"files": [
"dist"
],
"typings": "dist/index.d.ts",
"repository": {
"type": "git",
Expand All @@ -13,9 +15,16 @@
"access": "public"
},
"author": "B. Ramser <iwpnd@posteo.de>",
"contributors": ["V. Priem <vinzent.priem@gmail.com>"],
"contributors": [
"V. Priem <vinzent.priem@gmail.com>"
],
"license": "MIT",
"keywords": ["tile38", "geofence", "geo-spatial", "database"],
"keywords": [
"tile38",
"geofence",
"geo-spatial",
"database"
],
"engines": {
"node": ">=20.x",
"yarn": "^1.22.x"
Expand All @@ -28,7 +37,7 @@
"build": "tsc -p tsconfig.build.json",
"build:watch": "tsc --watch -p tsconfig.build.json",
"clean": "rimraf {dist,tsconfig.tsbuildinfo,yarn-error.log,coverage}",
"lint": "eslint --ext .ts ./src",
"lint": "eslint ./src",
"test": "jest --runInBand",
"format": "prettier --write src/{*.ts,**/*.ts}",
"u": "yarn upgrade-interactive --latest",
Expand All @@ -43,19 +52,21 @@
"devDependencies": {
"@commitlint/cli": "19.5.0",
"@commitlint/config-conventional": "19.5.0",
"@eslint/js": "9.11.1",
"@semantic-release/changelog": "6.0.3",
"@semantic-release/git": "10.0.1",
"@semantic-release/github": "11.0.0",
"@semantic-release/npm": "12.0.1",
"@semantic-release/release-notes-generator": "14.0.1",
"@types/eslint__js": "8.42.3",
"@types/jest": "29.5.13",
"@types/node": "22.7.4",
"@typescript-eslint/eslint-plugin": "8.7.0",
"@typescript-eslint/parser": "8.7.0",
"conventional-changelog-conventionalcommits": "8.0.0",
"coveralls": "3.1.1",
"devmoji": "2.3.0",
"eslint": "8.57.0",
"eslint": "9.11.1",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "9.1.0",
"eslint-import-resolver-typescript": "3.6.3",
Expand All @@ -69,9 +80,13 @@
"rimraf": "6.0.1",
"semantic-release": "24.1.2",
"ts-jest": "29.2.5",
"typescript": "5.6.2"
"typescript": "5.6.2",
"typescript-eslint": "8.7.0"
},
"lint-staged": {
"*.ts": ["eslint --fix", "prettier --write"]
"*.ts": [
"eslint --fix",
"prettier --write"
]
}
}
9 changes: 6 additions & 3 deletions src/Client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable @typescript-eslint/use-unknown-in-catch-callback-variable */
/* eslint-disable @typescript-eslint/no-confusing-void-expression */

import EventEmitter from 'events';
import { Redis, RedisOptions } from 'ioredis';
import { forwardEvents } from './events';
Expand Down Expand Up @@ -89,15 +92,15 @@ export enum SubCommand {

export type ConstructorArgs = (string | number | RedisOptions | undefined)[];

export type CommandArgs = Array<SubCommand | string | number | object>;
export type CommandArgs = (SubCommand | string | number | object)[];

enum Format {
RESP = 'resp',
JSON = 'json',
}

const toString = (s: string | number): string =>
typeof s === 'string' ? s : `${s}`;
typeof s === 'string' ? s : s.toString();

const applyDefaults = (args: ConstructorArgs) => {
const options = args.find((arg) => typeof arg === 'object');
Expand Down Expand Up @@ -153,7 +156,7 @@ export class Client extends EventEmitter {
): Promise<string> {
return this.redis.call(
command,
...(args || []).map(toString)
...(args ?? []).map(toString)
) as Promise<string>;
}

Expand Down
4 changes: 1 addition & 3 deletions src/Follower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ import {
export class Follower extends EventEmitter implements FollowerInterface {
readonly client: Client;

constructor(port: number, options?: Tile38Options);
constructor(port: string | number, options?: Tile38Options);

constructor(port: number, host: string, options?: Tile38Options);

constructor(path: string, options?: Tile38Options);

constructor(options?: Tile38Options);

constructor(...args: ConstructorArgs) {
Expand Down
4 changes: 1 addition & 3 deletions src/Tile38.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import { FollowerInterface, Tile38Options } from './specs';
export class Tile38 extends Leader {
readonly _follower?: Follower;

constructor(port: number, options?: Tile38Options);

constructor(port: number, host: string, options?: Tile38Options);

constructor(path: string, options?: Tile38Options);
constructor(path: number | string, options?: Tile38Options);

constructor(path?: string, followerPath?: string, options?: Tile38Options);

Expand Down
1 change: 0 additions & 1 deletion src/commands/Executable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface Compilable {

export class Executable extends WithClient implements Compilable {
// istanbul ignore next
// eslint-disable-next-line class-methods-use-this
compile(): [Command, CommandArgs] {
// istanbul ignore next
throw new Error('Not implemented');
Expand Down
8 changes: 6 additions & 2 deletions src/commands/Get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export class Get extends Executable implements GetInterface {
if (format === SubCommand.OBJECT) {
this._output = undefined;
} else if (format === SubCommand.HASH) {
this._output = [format, precision as number];
/* istanbul ignore if */
if (typeof precision == 'undefined') {
throw Error('HASHES output requires hash precision');
}
this._output = [format, precision];
} else {
this._output = [format];
}
Expand Down Expand Up @@ -103,7 +107,7 @@ export class Get extends Executable implements GetInterface {
this._key,
this._id,
...(this._withFields ? [SubCommand.WITHFIELDS] : []),
...(this._output || []),
...(this._output ?? []),
],
];
}
Expand Down
12 changes: 9 additions & 3 deletions src/commands/Intersects.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-parameters */

import { GeoJSON } from '@vpriem/geojson';
import { Compilable } from './Executable';
import { Whereable } from './Whereable';
Expand Down Expand Up @@ -213,7 +215,11 @@ export class Intersects extends Whereable implements IntersectsInterface {
if (format === SubCommand.OBJECTS) {
this._output = undefined;
} else if (format === SubCommand.HASHES) {
this._output = [format, precision as number];
/* istanbul ignore if */
if (typeof precision == 'undefined') {
throw Error('HASHES output requires hash precision');
}
this._output = [format, precision];
} else {
this._output = [format];
}
Expand Down Expand Up @@ -342,8 +348,8 @@ export class Intersects extends Whereable implements IntersectsInterface {
...this.compileFence(),
...super.compileWhere(),
...super.compileWherein(),
...(this._output || []),
...(this._query || []),
...(this._output ?? []),
...(this._query ?? []),
],
];

Expand Down
6 changes: 5 additions & 1 deletion src/commands/Scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export class Scan extends Search implements ScanInterface {
if (format === SubCommand.OBJECTS) {
this._output = undefined;
} else if (format === SubCommand.HASHES) {
this._output = [format, precision as number];
/* istanbul ignore if */
if (typeof precision == 'undefined') {
throw Error('HASHES output requires hash precision');
}
this._output = [format, precision];
} else {
this._output = [format];
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class Search extends Whereable implements SearchInterface {
...this.compileOptions(),
...super.compileWhere(),
...super.compileWherein(),
...(this._output || []),
...(this._output ?? []),
],
];
}
Expand Down
3 changes: 3 additions & 0 deletions src/commands/Set.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-parameters */

import { GeoJSON } from '@vpriem/geojson';
import { Executable } from './Executable';
import { Client, Command, CommandArgs, SubCommand } from '../Client';
Expand Down Expand Up @@ -111,6 +113,7 @@ export class Set extends Executable implements SetInterface {
? [SubCommand.EX, this._ex]
: []),
...(this._nxOrXx ? [this._nxOrXx] : []),
/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */
...(this._input || []),
],
];
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Whereable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type WhereInValues = (number | string)[];
* @typedef {Array} WhereInType
* @property {Array} 0 - SubCommand.WHEREIN with field name and values
*/
type WhereInType = [SubCommand.WHEREIN, string, ...Array<string | number>][];
type WhereInType = [SubCommand.WHEREIN, string, ...(string | number)[]][];

export interface Where {
/**
Expand Down
1 change: 0 additions & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line max-classes-per-file
export class Tile38Error extends Error {}
export class Tile38KeyNotFoundError extends Tile38Error {}
export class Tile38IdNotFoundError extends Tile38Error {}
Expand Down
11 changes: 6 additions & 5 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const events = [
'wait',
];

export const forwardEvents = (from: EventEmitter, to: EventEmitter): void =>
events.forEach((event) =>
from.on(event, (...eventArgs) =>
export const forwardEvents = (from: EventEmitter, to: EventEmitter): void => {
events.forEach((event) => {
return from.on(event, (...eventArgs) =>
to.emit(event, ...(eventArgs as [Error]))
)
);
);
});
};
6 changes: 4 additions & 2 deletions src/parseResponse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-parameters */

import {
Tile38Error,
Tile38IdNotFoundError,
Expand All @@ -12,11 +14,11 @@ export const parseResponse = <R extends JSONResponse>(response: string): R => {
try {
obj = JSON.parse(response) as R;
} catch (error) /* istanbul ignore next */ {
throw new Tile38Error((error as Error)?.message || 'unknown');
throw new Tile38Error((error as Error).message || 'unknown');
}

if (!obj.ok) {
const message = obj.err || /* istanbul ignore next */ 'unknown';
const message = obj.err ?? /* istanbul ignore next */ 'unknown';

if (message.includes('key not found')) {
throw new Tile38KeyNotFoundError(message);
Expand Down
17 changes: 8 additions & 9 deletions src/responses.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
/* eslint-disable camelcase */
import { GeoJSON, Polygon } from '@vpriem/geojson';

export type JSONResponse = {
export interface JSONResponse {
ok: boolean;
elapsed: string;
err?: string;
};
}

type ExtendResponse<E extends object> = JSONResponse & E;

export type LatLon = {
export interface LatLon {
lat: number;
lon: number;
};
}

export type Fields<O extends object = {}> = Record<
export type Fields<O extends object = object> = Record<
string,
string | number | object | O
>;
Expand Down Expand Up @@ -149,12 +148,12 @@ export type TTLResponse = ExtendResponse<{

// STATS
export type StatsResponse = ExtendResponse<{
stats: Array<{
stats: ({
in_memory_size: number;
num_objects: number;
num_points: number;
num_strings: number;
} | null>;
} | null)[];
}>;

// SERVER
Expand Down Expand Up @@ -291,7 +290,7 @@ export interface InfoFollowerResponse extends InfoResponse {
export interface InfoLeaderResponse extends InfoResponse {
info: InfoResponse['info'] & {
role: 'master';
} & { [key: string]: string | number };
} & Record<string, string | number>;
}

// CONFIG
Expand Down
Loading

0 comments on commit a1181c3

Please sign in to comment.