Skip to content

Commit 7021870

Browse files
committed
chore: adding eslint configs and scripts
Signed-off-by: Fawzi Abdulfattah <[email protected]>
1 parent 4367761 commit 7021870

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

core/connectors/ioredis.connector.ts

Whitespace-only changes.

core/producer/index.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { IClientConnector } from "@core/types";
2-
32
/**
43
* AbstractProducer is an abstract class that provides basic functionalities for adding data to queues.
54
* It ensures atomic operations if needed and handles graceful shutdown on process termination signals.
@@ -10,10 +9,7 @@ export default abstract class AbstractProducer<K> {
109
* @param name - The name of the queue.
1110
* @param client - An instance of IClientConnector to interact with the queue.
1211
*/
13-
constructor(
14-
private name: string,
15-
private client: IClientConnector<K>
16-
) {
12+
constructor(private name: string, private client: IClientConnector<K>) {
1713
process.once("SIGINT", this.handleShutdown.bind(this));
1814
process.once("SIGTERM", this.handleShutdown.bind(this));
1915
}
@@ -24,7 +20,7 @@ export default abstract class AbstractProducer<K> {
2420
* @param additionalQueues - Optional. Additional queues to which the data should be added atomically.
2521
* @returns A promise that resolves when the data has been added.
2622
*/
27-
public async add(data: any, additionalQueues?: string[]) {
23+
public async add(data: unknown, additionalQueues?: string[]) {
2824
await this.client.create();
2925
if (additionalQueues && additionalQueues.length) {
3026
await this.client.addAtomic(this.name, additionalQueues, data);
@@ -39,7 +35,7 @@ export default abstract class AbstractProducer<K> {
3935
* @param additionalQueues - Optional. Additional queues to which the data should be added atomically.
4036
* @returns A promise that resolves when the data has been added.
4137
*/
42-
public async bulk(data: any[], additionalQueues: string[] = []) {
38+
public async bulk(data: unknown[], additionalQueues: string[] = []) {
4339
await this.client.create();
4440
if (additionalQueues.length) {
4541
await this.client.bulkAtomic(this.name, additionalQueues, data);

core/types/client.connector.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface IClientConnector<K> {
3838
consumerId: string,
3939
count: number,
4040
block: number
41-
): Promise<any>;
41+
): Promise<unknown>; // TODO:: improve type
4242

4343
/**
4444
* Acknowledges a message in a consumer group as processed.
@@ -74,7 +74,7 @@ export interface IClientConnector<K> {
7474
* @param data - The data to add to the queue.
7575
* @returns A promise that resolves when the data is added.
7676
*/
77-
add(queue: string, data: any): Promise<void>;
77+
add(queue: string, data: unknown): Promise<void>;
7878

7979
/**
8080
* Adds data atomically to the specified queue and additional queues.
@@ -83,15 +83,15 @@ export interface IClientConnector<K> {
8383
* @param data - The data to add to the queues.
8484
* @returns A promise that resolves when the data is added.
8585
*/
86-
addAtomic(queue: string, additionalQueues: string[], data: any): Promise<void>;
86+
addAtomic(queue: string, additionalQueues: string[], data: unknown): Promise<void>;
8787

8888
/**
8989
* Adds multiple data entries to the specified queue.
9090
* @param queue - The name of the queue.
9191
* @param data - An array of data entries to add to the queue.
9292
* @returns A promise that resolves when the data is added.
9393
*/
94-
bulk(queue: string, data: any[]): Promise<void>;
94+
bulk(queue: string, data: unknown[]): Promise<void>;
9595

9696
/**
9797
* Adds multiple data entries atomically to the specified queue and additional queues.
@@ -100,7 +100,7 @@ export interface IClientConnector<K> {
100100
* @param data - An array of data entries to add to the queues.
101101
* @returns A promise that resolves when the data is added.
102102
*/
103-
bulkAtomic(queue: string, additionalQueues: string[], data: any[]): Promise<void>;
103+
bulkAtomic(queue: string, additionalQueues: string[], data: unknown[]): Promise<void>;
104104

105105
/**
106106
* Sets a heartbeat for the specified worker.

eslint.config.mjs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
import tseslint from "typescript-eslint";
4+
5+
export default [
6+
{ languageOptions: { globals: globals.browser } },
7+
pluginJs.configs.recommended,
8+
...tseslint.configs.recommended,
9+
{
10+
rules: {
11+
"sort-imports": ["error", {
12+
"ignoreCase": false,
13+
"ignoreDeclarationSort": false,
14+
"ignoreMemberSort": false,
15+
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"],
16+
"allowSeparatedGroups": false
17+
}]
18+
}
19+
}
20+
];

package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "RunMQ - A Pioneering message queue & batch processing solution for Node.js. Redefining task management like never before",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"lint": "eslint .",
8+
"lint:fix": "eslint --fix ."
89
},
910
"_moduleAliases": {
1011
"@": "dist"
@@ -19,7 +20,14 @@
1920
"url": "https://github.com/runmq/queue/issues"
2021
},
2122
"homepage": "https://github.com/runmq/queue#readme",
23+
"dependencies": {
24+
"ioredis": "^5.4.1"
25+
},
2226
"devDependencies": {
23-
"@types/node": "^20.12.13"
27+
"@eslint/js": "^9.4.0",
28+
"@types/node": "^20.12.13",
29+
"eslint": "^9.4.0",
30+
"globals": "^15.3.0",
31+
"typescript-eslint": "^7.11.0"
2432
}
2533
}

0 commit comments

Comments
 (0)