From 6c9678865cbb0e908b0fc13ed58aa176ed9ed3b8 Mon Sep 17 00:00:00 2001 From: Jared Wray Date: Sat, 16 Nov 2024 17:00:08 -0700 Subject: [PATCH] redis - fixing lint issues and clean up (#1218) --- packages/redis/package.json | 23 ++++------------------- packages/redis/src/index.ts | 12 +++++------- packages/redis/test/suite.ts | 2 +- packages/redis/test/test.ts | 3 ++- packages/redis/vitest.config.ts | 2 +- 5 files changed, 13 insertions(+), 29 deletions(-) diff --git a/packages/redis/package.json b/packages/redis/package.json index d6e8e410d..7ccc4454a 100644 --- a/packages/redis/package.json +++ b/packages/redis/package.json @@ -19,23 +19,6 @@ "test:ci": "xo && vitest --run --sequence.setupFiles=list", "clean": "rimraf ./node_modules ./coverage ./dist" }, - "xo": { - "rules": { - "import/no-named-as-default": "off", - "unicorn/prefer-module": "off", - "unicorn/prefer-event-target": "off", - "unicorn/prefer-node-protocol": "off", - "unicorn/no-typeof-undefined": "off", - "import/extensions": "off", - "@typescript-eslint/no-unsafe-call": "off", - "@typescript-eslint/no-unsafe-assignment": "off", - "@typescript-eslint/no-unsafe-return": "off", - "unicorn/prefer-ternary": "off", - "unicorn/no-array-callback-reference": "off", - "import/no-extraneous-dependencies": "off", - "@typescript-eslint/no-confusing-void-expression": "off" - } - }, "repository": { "type": "git", "url": "git+https://github.com/jaredwray/keyv.git" @@ -58,14 +41,16 @@ }, "homepage": "https://github.com/jaredwray/keyv", "dependencies": { - "redis": "^4.7.0", - "keyv": "*" + "keyv": "*", + "redis": "^4.7.0" }, "devDependencies": { "@keyv/test-suite": "*", + "@vitest/coverage-v8": "^2.1.5", "rimraf": "^6.0.1", "timekeeper": "^2.3.1", "tsd": "^0.31.2", + "vitest": "^2.1.5", "xo": "^0.59.3" }, "tsd": { diff --git a/packages/redis/src/index.ts b/packages/redis/src/index.ts index 2953d3b87..8a86dcd48 100644 --- a/packages/redis/src/index.ts +++ b/packages/redis/src/index.ts @@ -1,4 +1,4 @@ -import EventEmitter from 'events'; +import EventEmitter from 'node:events'; import {createClient, type RedisClientType, type RedisClientOptions} from 'redis'; import {Keyv, type KeyvStoreAdapter} from 'keyv'; @@ -47,7 +47,7 @@ export type KeyvRedisEntry = { */ ttl?: number; }; - +// eslint-disable-next-line unicorn/prefer-event-target export default class KeyvRedis extends EventEmitter implements KeyvStoreAdapter { private _client: RedisClientType = createClient() as RedisClientType; private _namespace: string | undefined; @@ -193,6 +193,7 @@ export default class KeyvRedis extends EventEmitter implements KeyvStoreAdapter public async set(key: string, value: string, ttl?: number): Promise { const client = await this.getClient(); key = this.createKeyPrefix(key, this._namespace); + // eslint-disable-next-line unicorn/prefer-ternary if (ttl) { // eslint-disable-next-line @typescript-eslint/naming-convention await client.set(key, value, {PX: ttl}); @@ -295,11 +296,7 @@ export default class KeyvRedis extends EventEmitter implements KeyvStoreAdapter const client = await this.getClient(); key = this.createKeyPrefix(key, this._namespace); let deleted = 0; - if (this._useUnlink) { - deleted = await client.unlink(key); - } else { - deleted = await client.del(key); - } + deleted = await (this._useUnlink ? client.unlink(key) : client.del(key)); return deleted > 0; } @@ -437,6 +434,7 @@ export default class KeyvRedis extends EventEmitter implements KeyvStoreAdapter } if (keys.length > 0) { + // eslint-disable-next-line unicorn/prefer-ternary if (this._useUnlink) { // eslint-disable-next-line no-await-in-loop await client.unlink(keys); diff --git a/packages/redis/test/suite.ts b/packages/redis/test/suite.ts index 04b82069a..b1e0e9894 100644 --- a/packages/redis/test/suite.ts +++ b/packages/redis/test/suite.ts @@ -1,6 +1,6 @@ import * as test from 'vitest'; import keyvTestSuite, {keyvIteratorTests} from '@keyv/test-suite'; -import Keyv from 'keyv'; +import {Keyv} from 'keyv'; import KeyvRedis from '../src/index.js'; const redisUrl = 'redis://localhost:6379/5'; diff --git a/packages/redis/test/test.ts b/packages/redis/test/test.ts index 4b3229c7a..edc7b69e2 100644 --- a/packages/redis/test/test.ts +++ b/packages/redis/test/test.ts @@ -20,8 +20,9 @@ describe('KeyvRedis', () => { expect(keyv).toBeDefined(); await keyv.set('mykey', 'myvalue'); await keyv.set('mykey2', {foo: 'bar'}); - const value = await keyv.get('mykey'); + const value = await keyv.get('mykey'); expect(value).toBe('myvalue'); + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const value2 = await keyv.get('mykey2'); expect(value2).toEqual({foo: 'bar'}); }); diff --git a/packages/redis/vitest.config.ts b/packages/redis/vitest.config.ts index 1ee8dcc07..772d21fe2 100644 --- a/packages/redis/vitest.config.ts +++ b/packages/redis/vitest.config.ts @@ -1,4 +1,4 @@ import {defineConfig, mergeConfig} from 'vitest/config'; -import vitestConfig from '../../vitest.general.config'; +import vitestConfig from '../../vitest.general.config.js'; export default mergeConfig(vitestConfig, defineConfig({}));