From d6876ded180d6e173b0cb514cdadda46a01cd171 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 23 Mar 2025 20:53:56 +0800 Subject: [PATCH] feat: use oxlint and prettier --- .eslintignore | 3 - .eslintrc | 6 - .github/workflows/nodejs.yml | 4 +- .github/workflows/release.yml | 2 +- .husky/pre-commit | 1 + .oxlintrc.json | 142 ++++++++++++++++++ .prettierignore | 2 + .prettierrc | 6 + README.md | 39 ++--- example/hello/app/router.ts | 2 +- example/hello/start.ts | 6 +- package.json | 24 ++- src/config/config.default.ts | 4 +- src/lib/redis.ts | 91 +++++++---- .../apps/redisapp-customize/app/router.js | 2 +- .../apps/redisapp-customize/config/config.js | 2 +- .../apps/redisapp-default/app/router.js | 2 +- .../app/router.js | 2 +- .../app/router.js | 2 +- .../config/config.js | 2 +- .../apps/redisapp-weakdependent/app/router.js | 2 +- .../redisapp-weakdependent/config/config.js | 2 +- test/fixtures/apps/redisapp/app/router.js | 2 +- .../apps/redisclusterapp/app/router.js | 2 +- .../apps/redisclusterapp/config/config.js | 27 ++-- test/fixtures/apps/redispathapp/app/router.js | 2 +- .../apps/redispathapp/config/config.js | 4 +- .../apps/redissentinelapp/app/router.js | 2 +- .../apps/redissentinelapp/config/config.js | 21 +-- .../redisapp-ts/app/controller/home.ts | 2 +- .../apps/ts-multi/redisapp-ts/app/router.ts | 10 +- .../ts-multi/redisapp-ts/config/config.ts | 10 +- .../apps/ts/redisapp-ts/app/router.ts | 8 +- .../apps/ts/redisapp-ts/config/config.ts | 10 +- test/redis.test.ts | 53 ++----- 35 files changed, 334 insertions(+), 167 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc create mode 100644 .husky/pre-commit create mode 100644 .oxlintrc.json create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 618ef2b..0000000 --- a/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -test/fixtures -coverage -__snapshots__ diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 9bcdb46..0000000 --- a/.eslintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": [ - "eslint-config-egg/typescript", - "eslint-config-egg/lib/rules/enforce-node-prefix" - ] -} diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 25bb2a4..410d890 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: Job: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a2bf04a..4240f1c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: Release on: push: - branches: [ master ] + branches: [master] jobs: release: diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..2312dc5 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +npx lint-staged diff --git a/.oxlintrc.json b/.oxlintrc.json new file mode 100644 index 0000000..10f5656 --- /dev/null +++ b/.oxlintrc.json @@ -0,0 +1,142 @@ +{ + "$schema": "./node_modules/oxlint/configuration_schema.json", + "env": { + "node": true, + "mocha": true + }, + "categories": { + "correctness": "error", + "perf": "error", + "nursery": "error", + "restriction": "error", + "style": "error", + "pedantic": "error", + "suspicious": "error" + }, + "plugins": [ + "import", + "typescript", + "unicorn", + "jsdoc", + "node", + "promise", + "oxc" + ], + "rules": { + // eslint + "constructor-super": "error", + "getter-return": "error", + "no-undef": "error", + "no-unreachable": "error", + "no-var": "error", + "no-eq-null": "error", + "no-await-in-loop": "allow", + "eqeqeq": ["error", "smart"], + "init-declarations": "allow", + "curly": "allow", + "no-ternary": "allow", + "max-params": ["error", 5], + "no-await-expression-member": "error", + "no-continue": "allow", + "guard-for-in": "allow", + "func-style": "allow", + "sort-imports": "allow", + "yoda": "allow", + "sort-keys": "allow", + "no-magic-numbers": "allow", + "no-duplicate-imports": "error", + "no-multi-assign": "error", + "func-names": "error", + "default-param-last": "error", + "prefer-object-spread": "error", + "no-undefined": "allow", + "no-plusplus": "allow", + // maybe warn + "no-console": "warn", + "no-extraneous-class": "allow", + "no-empty-function": "error", + "max-depth": ["error", 6], + "max-lines-per-function": "allow", + "no-lonely-if": "error", + "max-lines": "allow", + "require-await": "allow", + "max-nested-callbacks": ["error", 5], + "max-classes-per-file": "allow", + "radix": "allow", + "no-negated-condition": "error", + "no-else-return": "error", + "no-throw-literal": "error", + + // import + "import/exports-last": "allow", + "import/max-dependencies": "allow", + "import/no-cycle": "error", + "import/no-anonymous-default-export": "allow", + "import/no-namespace": "error", + "import/named": "error", + "import/export": "error", + "import/no-default-export": "allow", + "import/unambiguous": "error", + + // promise + "promise/no-return-wrap": "error", + "promise/param-names": "error", + "promise/prefer-await-to-callbacks": "error", + "promise/prefer-await-to-then": "error", + "promise/prefer-catch": "error", + "promise/no-return-in-finally": "error", + "promise/avoid-new": "error", + + // unicorn + "unicorn/error-message": "error", + "unicorn/no-null": "allow", + "unicorn/filename-case": "allow", + "unicorn/prefer-structured-clone": "error", + "unicorn/prefer-logical-operator-over-ternary": "error", + "unicorn/prefer-number-properties": "error", + "unicorn/prefer-array-some": "error", + "unicorn/prefer-string-slice": "error", + // "unicorn/no-null": "error", + "unicorn/throw-new-error": "error", + "unicorn/catch-error-name": "allow", + "unicorn/prefer-spread": "allow", + "unicorn/numeric-separators-style": "error", + "unicorn/prefer-string-raw": "error", + "unicorn/text-encoding-identifier-case": "error", + "unicorn/no-array-for-each": "error", + "unicorn/explicit-length-check": "error", + "unicorn/no-lonely-if": "error", + "unicorn/no-useless-undefined": "allow", + "unicorn/prefer-date-now": "error", + "unicorn/no-static-only-class": "allow", + "unicorn/no-typeof-undefined": "error", + "unicorn/prefer-negative-index": "error", + "unicorn/no-anonymous-default-export": "allow", + + // oxc + "oxc/no-map-spread": "error", + "oxc/no-rest-spread-properties": "allow", + "oxc/no-optional-chaining": "allow", + "oxc/no-async-await": "allow", + + // typescript + "typescript/explicit-function-return-type": "allow", + "typescript/consistent-type-imports": "error", + "typescript/consistent-type-definitions": "error", + "typescript/consistent-indexed-object-style": "allow", + "typescript/no-inferrable-types": "error", + "typescript/array-type": "error", + "typescript/no-non-null-assertion": "error", + "typescript/no-explicit-any": "error", + "typescript/no-import-type-side-effects": "error", + "typescript/no-dynamic-delete": "error", + "typescript/prefer-ts-expect-error": "error", + "typescript/ban-ts-comment": "error", + "typescript/prefer-enum-initializers": "error", + + // jsdoc + "jsdoc/require-returns": "allow", + "jsdoc/require-param": "allow" + }, + "ignorePatterns": ["index.d.ts", "test/fixtures/**", "__snapshots__"] +} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..9ffa84d --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +CHANGELOG.md +__snapshots__ diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..43aee1a --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "singleQuote": true, + "trailingComma": "es5", + "tabWidth": 2, + "arrowParens": "avoid" +} diff --git a/README.md b/README.md index 61bd1da..6f340c8 100644 --- a/README.md +++ b/README.md @@ -49,12 +49,12 @@ Configure redis information in `${app_root}/config/config.default.js`: ```javascript config.redis = { client: { - port: 6379, // Redis port - host: '127.0.0.1', // Redis host + port: 6379, // Redis port + host: '127.0.0.1', // Redis host password: 'auth', db: 0, }, -} +}; ``` **Multi Clients** @@ -62,9 +62,10 @@ config.redis = { ```javascript config.redis = { clients: { - foo: { // instanceName. See below - port: 6379, // Redis port - host: '127.0.0.1', // Redis host + foo: { + // instanceName. See below + port: 6379, // Redis port + host: '127.0.0.1', // Redis host password: 'auth', db: 0, }, @@ -74,8 +75,8 @@ config.redis = { password: 'auth', db: 1, }, - } -} + }, +}; ``` **Sentinel** @@ -86,16 +87,16 @@ config.redis = { // Sentinel instances sentinels: [ { - port: 26379, // Sentinel port - host: '127.0.0.1', // Sentinel host + port: 26379, // Sentinel port + host: '127.0.0.1', // Sentinel host }, // other sentinel instance config ], - name: 'mymaster', // Master name + name: 'mymaster', // Master name password: 'auth', - db: 0 + db: 0, }, -} +}; ``` **No password** @@ -127,12 +128,12 @@ you can pass the instance by `config.redis.Redis`: config.redis = { Redis: require('ioredis'), // customize ioredis version, only set when you needed client: { - port: 6379, // Redis port - host: '127.0.0.1', // Redis host + port: 6379, // Redis port + host: '127.0.0.1', // Redis host password: 'auth', db: 0, }, -} +}; ``` **weakDependent** @@ -140,13 +141,13 @@ config.redis = { ```javascript config.redis = { client: { - port: 6379, // Redis port - host: '127.0.0.1', // Redis host + port: 6379, // Redis port + host: '127.0.0.1', // Redis host password: 'auth', db: 0, weakDependent: true, // the redis instance won't block app start }, -} +}; ``` ## Usage diff --git a/example/hello/app/router.ts b/example/hello/app/router.ts index 3f7682d..a24c628 100644 --- a/example/hello/app/router.ts +++ b/example/hello/app/router.ts @@ -1,4 +1,4 @@ -import { Application } from 'egg'; +import type { Application } from 'egg'; export default (app: Application) => { const { router } = app; diff --git a/example/hello/start.ts b/example/hello/start.ts index 0744c59..4df7b38 100644 --- a/example/hello/start.ts +++ b/example/hello/start.ts @@ -1,5 +1,6 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; + import { startEgg } from 'egg'; const __filename = fileURLToPath(import.meta.url); @@ -9,4 +10,7 @@ const app = await startEgg({ baseDir: __dirname, }); -console.log(`Server started at http://localhost:${app.config.cluster.listen.port}`); +// oxlint-disable-next-line no-console +console.log( + `Server started at http://localhost:${app.config.cluster.listen.port}` +); diff --git a/package.json b/package.json index c1fa6ba..98d7851 100644 --- a/package.json +++ b/package.json @@ -35,19 +35,21 @@ "node": ">= 18.19.0" }, "dependencies": { - "@eggjs/core": "^6.3.0", + "@eggjs/core": "^6.4.1", "ioredis": "^5.4.2" }, "devDependencies": { - "@arethetypeswrong/cli": "^0.17.1", + "@arethetypeswrong/cli": "^0.17.4", "@eggjs/bin": "7", "@eggjs/mock": "^6.0.5", "@eggjs/tsconfig": "1", "@types/mocha": "10", "@types/node": "22", - "egg": "^4.0.3", - "eslint": "8", - "eslint-config-egg": "14", + "egg": "4", + "husky": "^9.1.7", + "lint-staged": "^15.5.0", + "oxlint": "^0.16.2", + "prettier": "^3.5.3", "rimraf": "6", "snap-shot-it": "^7.9.10", "tshy": "3", @@ -55,14 +57,22 @@ "typescript": "5" }, "scripts": { - "lint": "eslint --cache src test --ext .ts", + "lint": "oxlint", "pretest": "npm run clean && npm run lint -- --fix", "test": "egg-bin test", "preci": "npm run clean && npm run lint", "ci": "egg-bin cov", "postci": "npm run prepublishOnly && npm run clean", "clean": "rimraf dist", - "prepublishOnly": "tshy && tshy-after && attw --pack" + "prepublishOnly": "tshy && tshy-after && attw --pack", + "prepare": "husky" + }, + "lint-staged": { + "*": "prettier --write --ignore-unknown --cache", + "*.{ts,js,json,md,yml}": [ + "prettier --ignore-unknown --write", + "oxlint --fix" + ] }, "type": "module", "tshy": { diff --git a/src/config/config.default.ts b/src/config/config.default.ts index 0db6dd8..a1c9621 100644 --- a/src/config/config.default.ts +++ b/src/config/config.default.ts @@ -1,4 +1,4 @@ -import type { RedisOptions, ClusterOptions } from 'ioredis'; +import type { RedisOptions, ClusterOptions, Redis } from 'ioredis'; export interface RedisClientOptions extends RedisOptions { /** @@ -54,7 +54,7 @@ export interface RedisConfig { * * Default to `undefined`, which means using the built-in ioredis */ - Redis?: any; + Redis?: typeof Redis; } export default { diff --git a/src/lib/redis.ts b/src/lib/redis.ts index 3393364..156ddc4 100644 --- a/src/lib/redis.ts +++ b/src/lib/redis.ts @@ -1,8 +1,12 @@ import assert from 'node:assert'; import { once } from 'node:events'; + import { Redis } from 'ioredis'; import type { ILifecycleBoot, EggCore } from '@eggjs/core'; -import type { RedisClusterOptions, RedisClientOptions } from '../config/config.default.js'; +import type { + RedisClusterOptions, + RedisClientOptions, +} from '../config/config.default.js'; export class RedisBoot implements ILifecycleBoot { constructor(private readonly app: EggCore) { @@ -19,48 +23,76 @@ export class RedisBoot implements ILifecycleBoot { } let count = 0; -function createClient(options: RedisClusterOptions | RedisClientOptions, app: EggCore) { - const RedisClass: typeof Redis = app.config.redis.Redis ?? Redis; +function createClient( + options: RedisClusterOptions | RedisClientOptions, + app: EggCore +) { + const RedisClass = app.config.redis.Redis ?? Redis; let client; if ('cluster' in options && options.cluster === true) { const config = options as RedisClusterOptions; - assert(config.nodes && config.nodes.length !== 0, '[@eggjs/redis] cluster nodes configuration is required when use cluster redis'); + assert( + config.nodes && config.nodes.length > 0, + '[@eggjs/redis] cluster nodes configuration is required when use cluster redis' + ); - config.nodes.forEach(client => { - assert(client.host && client.port, `[@eggjs/redis] 'host: ${client.host}', 'port: ${client.port}' are required on config`); - }); + for (const client of config.nodes) { + assert( + client.host && client.port, + `[@eggjs/redis] 'host: ${client.host}', 'port: ${client.port}' are required on config` + ); + } app.coreLogger.info('[@eggjs/redis] cluster connecting'); - client = new RedisClass.Cluster(config.nodes, config as any); + client = new RedisClass.Cluster(config.nodes, config); } else if ('sentinels' in options && options.sentinels) { const config = options as RedisClientOptions; - assert(config.sentinels && config.sentinels.length !== 0, '[@eggjs/redis] sentinels configuration is required when use redis sentinel'); + assert( + config.sentinels && config.sentinels.length > 0, + '[@eggjs/redis] sentinels configuration is required when use redis sentinel' + ); - config.sentinels.forEach(sentinel => { - assert(sentinel.host && sentinel.port, - `[@eggjs/redis] 'host: ${sentinel.host}', 'port: ${sentinel.port}' are required on config`); - }); + for (const sentinel of config.sentinels) { + assert( + sentinel.host && sentinel.port, + `[@eggjs/redis] 'host: ${sentinel.host}', 'port: ${sentinel.port}' are required on config` + ); + } const mask = config.password ? '***' : config.password; - assert(config.name && config.password !== undefined && config.db !== undefined, - `[@eggjs/redis] 'name of master: ${config.name}', 'password: ${mask}', 'db: ${config.db}' are required on config`); + assert( + config.name && config.password !== undefined && config.db !== undefined, + `[@eggjs/redis] 'name of master: ${config.name}', 'password: ${mask}', 'db: ${config.db}' are required on config` + ); app.coreLogger.info('[@eggjs/redis] sentinel connecting start'); - client = new RedisClass(config as any); + client = new RedisClass(config); } else { const config = options as RedisClientOptions; const mask = config.password ? '***' : config.password; - assert((config.host && config.port && config.password !== undefined && config.db !== undefined) || config.path, - `[@eggjs/redis] 'host: ${config.host}', 'port: ${config.port}', 'password: ${mask}', 'db: ${config.db}' or 'path:${config.path}' are required on config`); + assert( + (config.host && + config.port && + config.password !== undefined && + config.db !== undefined) || + config.path, + `[@eggjs/redis] 'host: ${config.host}', 'port: ${config.port}', 'password: ${mask}', 'db: ${config.db}' or 'path:${config.path}' are required on config` + ); if (config.host) { - app.coreLogger.info('[@eggjs/redis] server connecting redis://:***@%s:%s/%s', - config.host, config.port, config.db); + app.coreLogger.info( + '[@eggjs/redis] server connecting redis://:***@%s:%s/%s', + config.host, + config.port, + config.db + ); } else { - app.coreLogger.info('[@eggjs/redis] server connecting %s', - config.path || config); + app.coreLogger.info( + '[@eggjs/redis] server connecting %s', + config.path || config + ); } - client = new RedisClass(config as any); + client = new RedisClass(config); } client.on('connect', () => { @@ -74,18 +106,19 @@ function createClient(options: RedisClusterOptions | RedisClientOptions, app: Eg const index = count++; app.lifecycle.registerBeforeStart(async () => { if ('weakDependent' in options && options.weakDependent) { - app.coreLogger.info(`[@eggjs/redis] instance[${index}] is weak dependent and won't block app start`); + app.coreLogger.info( + `[@eggjs/redis] instance[${index}] is weak dependent and won't block app start` + ); client.once('ready', () => { app.coreLogger.info(`[@eggjs/redis] instance[${index}] status OK`); }); return; } - await Promise.race([ - once(client, 'ready'), - once(client, 'error'), - ]); - app.coreLogger.info(`[@eggjs/redis] instance[${index}] status OK, client ready`); + await Promise.race([once(client, 'ready'), once(client, 'error')]); + app.coreLogger.info( + `[@eggjs/redis] instance[${index}] status OK, client ready` + ); }, `[@eggjs/redis] instance[${index}] start check`); return client; diff --git a/test/fixtures/apps/redisapp-customize/app/router.js b/test/fixtures/apps/redisapp-customize/app/router.js index 96d8892..fc3bc94 100644 --- a/test/fixtures/apps/redisapp-customize/app/router.js +++ b/test/fixtures/apps/redisapp-customize/app/router.js @@ -1,5 +1,5 @@ 'use strict'; -module.exports = function(app) { +module.exports = function (app) { app.get('/', 'home.index'); }; diff --git a/test/fixtures/apps/redisapp-customize/config/config.js b/test/fixtures/apps/redisapp-customize/config/config.js index eb0b204..efd1261 100644 --- a/test/fixtures/apps/redisapp-customize/config/config.js +++ b/test/fixtures/apps/redisapp-customize/config/config.js @@ -7,7 +7,7 @@ exports.redis = { password: '', db: '0', }, - agent:true, + agent: true, Redis: require('ioredis'), }; diff --git a/test/fixtures/apps/redisapp-default/app/router.js b/test/fixtures/apps/redisapp-default/app/router.js index 96d8892..fc3bc94 100644 --- a/test/fixtures/apps/redisapp-default/app/router.js +++ b/test/fixtures/apps/redisapp-default/app/router.js @@ -1,5 +1,5 @@ 'use strict'; -module.exports = function(app) { +module.exports = function (app) { app.get('/', 'home.index'); }; diff --git a/test/fixtures/apps/redisapp-disable-offline-queue/app/router.js b/test/fixtures/apps/redisapp-disable-offline-queue/app/router.js index 96d8892..fc3bc94 100644 --- a/test/fixtures/apps/redisapp-disable-offline-queue/app/router.js +++ b/test/fixtures/apps/redisapp-disable-offline-queue/app/router.js @@ -1,5 +1,5 @@ 'use strict'; -module.exports = function(app) { +module.exports = function (app) { app.get('/', 'home.index'); }; diff --git a/test/fixtures/apps/redisapp-supportTimeCommand-false/app/router.js b/test/fixtures/apps/redisapp-supportTimeCommand-false/app/router.js index 96d8892..fc3bc94 100644 --- a/test/fixtures/apps/redisapp-supportTimeCommand-false/app/router.js +++ b/test/fixtures/apps/redisapp-supportTimeCommand-false/app/router.js @@ -1,5 +1,5 @@ 'use strict'; -module.exports = function(app) { +module.exports = function (app) { app.get('/', 'home.index'); }; diff --git a/test/fixtures/apps/redisapp-supportTimeCommand-false/config/config.js b/test/fixtures/apps/redisapp-supportTimeCommand-false/config/config.js index 70f74b1..03f1230 100644 --- a/test/fixtures/apps/redisapp-supportTimeCommand-false/config/config.js +++ b/test/fixtures/apps/redisapp-supportTimeCommand-false/config/config.js @@ -7,7 +7,7 @@ exports.redis = { password: '', db: '0', }, - agent:true, + agent: true, supportTimeCommand: false, }; diff --git a/test/fixtures/apps/redisapp-weakdependent/app/router.js b/test/fixtures/apps/redisapp-weakdependent/app/router.js index 96d8892..fc3bc94 100644 --- a/test/fixtures/apps/redisapp-weakdependent/app/router.js +++ b/test/fixtures/apps/redisapp-weakdependent/app/router.js @@ -1,5 +1,5 @@ 'use strict'; -module.exports = function(app) { +module.exports = function (app) { app.get('/', 'home.index'); }; diff --git a/test/fixtures/apps/redisapp-weakdependent/config/config.js b/test/fixtures/apps/redisapp-weakdependent/config/config.js index ed3bdef..ed6b72a 100644 --- a/test/fixtures/apps/redisapp-weakdependent/config/config.js +++ b/test/fixtures/apps/redisapp-weakdependent/config/config.js @@ -6,7 +6,7 @@ exports.redis = { password: '', db: '0', }, - agent:true, + agent: true, }; exports.logger = { diff --git a/test/fixtures/apps/redisapp/app/router.js b/test/fixtures/apps/redisapp/app/router.js index 96d8892..fc3bc94 100644 --- a/test/fixtures/apps/redisapp/app/router.js +++ b/test/fixtures/apps/redisapp/app/router.js @@ -1,5 +1,5 @@ 'use strict'; -module.exports = function(app) { +module.exports = function (app) { app.get('/', 'home.index'); }; diff --git a/test/fixtures/apps/redisclusterapp/app/router.js b/test/fixtures/apps/redisclusterapp/app/router.js index 96d8892..fc3bc94 100644 --- a/test/fixtures/apps/redisclusterapp/app/router.js +++ b/test/fixtures/apps/redisclusterapp/app/router.js @@ -1,5 +1,5 @@ 'use strict'; -module.exports = function(app) { +module.exports = function (app) { app.get('/', 'home.index'); }; diff --git a/test/fixtures/apps/redisclusterapp/config/config.js b/test/fixtures/apps/redisclusterapp/config/config.js index 38cdb12..e4e6275 100644 --- a/test/fixtures/apps/redisclusterapp/config/config.js +++ b/test/fixtures/apps/redisclusterapp/config/config.js @@ -3,19 +3,22 @@ exports.redis = { client: { cluster: true, - nodes: [{ - host: '127.0.0.1', - port: 7000, - password: '', - db: '0', - }, { - host: '127.0.0.1', - port: 7001, - password: '', - db: '0', - }] + nodes: [ + { + host: '127.0.0.1', + port: 7000, + password: '', + db: '0', + }, + { + host: '127.0.0.1', + port: 7001, + password: '', + db: '0', + }, + ], }, - agent: true + agent: true, }; exports.keys = 'keys'; diff --git a/test/fixtures/apps/redispathapp/app/router.js b/test/fixtures/apps/redispathapp/app/router.js index 96d8892..fc3bc94 100644 --- a/test/fixtures/apps/redispathapp/app/router.js +++ b/test/fixtures/apps/redispathapp/app/router.js @@ -1,5 +1,5 @@ 'use strict'; -module.exports = function(app) { +module.exports = function (app) { app.get('/', 'home.index'); }; diff --git a/test/fixtures/apps/redispathapp/config/config.js b/test/fixtures/apps/redispathapp/config/config.js index 198cc21..006287f 100644 --- a/test/fixtures/apps/redispathapp/config/config.js +++ b/test/fixtures/apps/redispathapp/config/config.js @@ -2,9 +2,9 @@ exports.redis = { client: { - path: '/tmp/redis.sock' + path: '/tmp/redis.sock', }, - agent: true + agent: true, }; exports.keys = 'keys'; diff --git a/test/fixtures/apps/redissentinelapp/app/router.js b/test/fixtures/apps/redissentinelapp/app/router.js index 96d8892..fc3bc94 100644 --- a/test/fixtures/apps/redissentinelapp/app/router.js +++ b/test/fixtures/apps/redissentinelapp/app/router.js @@ -1,5 +1,5 @@ 'use strict'; -module.exports = function(app) { +module.exports = function (app) { app.get('/', 'home.index'); }; diff --git a/test/fixtures/apps/redissentinelapp/config/config.js b/test/fixtures/apps/redissentinelapp/config/config.js index c22d345..da474fa 100644 --- a/test/fixtures/apps/redissentinelapp/config/config.js +++ b/test/fixtures/apps/redissentinelapp/config/config.js @@ -2,18 +2,21 @@ exports.redis = { client: { - sentinels: [{ - host: '127.0.0.1', - port: 26379 - },{ - host: '127.0.0.1', - port: 26380 - }], + sentinels: [ + { + host: '127.0.0.1', + port: 26379, + }, + { + host: '127.0.0.1', + port: 26380, + }, + ], name: 'mymaster', password: '', - db: '0' + db: '0', }, - agent: true + agent: true, }; exports.keys = 'keys'; diff --git a/test/fixtures/apps/ts-multi/redisapp-ts/app/controller/home.ts b/test/fixtures/apps/ts-multi/redisapp-ts/app/controller/home.ts index 792bbb8..c8d5988 100644 --- a/test/fixtures/apps/ts-multi/redisapp-ts/app/controller/home.ts +++ b/test/fixtures/apps/ts-multi/redisapp-ts/app/controller/home.ts @@ -13,7 +13,7 @@ declare module 'egg' { export default class HomeController extends Controller { async index() { - const { ctx,app } = this; + const { ctx, app } = this; // @deprecated please use `getSingletonInstance(id)` instead const redis = app.redis.get('cache') as unknown as Redis; await redis.set('foo', 'bar'); diff --git a/test/fixtures/apps/ts-multi/redisapp-ts/app/router.ts b/test/fixtures/apps/ts-multi/redisapp-ts/app/router.ts index ddad8e9..44fc65f 100644 --- a/test/fixtures/apps/ts-multi/redisapp-ts/app/router.ts +++ b/test/fixtures/apps/ts-multi/redisapp-ts/app/router.ts @@ -1,7 +1,7 @@ -import {Application} from 'egg'; +import { Application } from 'egg'; export default (app: Application) => { - const controller = app.controller; - app.logger.info("debug"); - app.get('/', controller.home.index); -} + const controller = app.controller; + app.logger.info('debug'); + app.get('/', controller.home.index); +}; diff --git a/test/fixtures/apps/ts-multi/redisapp-ts/config/config.ts b/test/fixtures/apps/ts-multi/redisapp-ts/config/config.ts index 5c59dc1..1d5b980 100644 --- a/test/fixtures/apps/ts-multi/redisapp-ts/config/config.ts +++ b/test/fixtures/apps/ts-multi/redisapp-ts/config/config.ts @@ -2,10 +2,10 @@ export default { keys: 'keys', - logger:{ + logger: { level: 'INFO', }, - redis :{ + redis: { clients: { session: { host: '127.0.0.1', @@ -20,6 +20,6 @@ export default { db: '1', }, }, - agent:true, - } -} \ No newline at end of file + agent: true, + }, +}; diff --git a/test/fixtures/apps/ts/redisapp-ts/app/router.ts b/test/fixtures/apps/ts/redisapp-ts/app/router.ts index 77c9635..44fc65f 100644 --- a/test/fixtures/apps/ts/redisapp-ts/app/router.ts +++ b/test/fixtures/apps/ts/redisapp-ts/app/router.ts @@ -1,7 +1,7 @@ import { Application } from 'egg'; export default (app: Application) => { - const controller = app.controller; - app.logger.info("debug"); - app.get('/', controller.home.index); -} + const controller = app.controller; + app.logger.info('debug'); + app.get('/', controller.home.index); +}; diff --git a/test/fixtures/apps/ts/redisapp-ts/config/config.ts b/test/fixtures/apps/ts/redisapp-ts/config/config.ts index 1a6a568..b7db4b2 100644 --- a/test/fixtures/apps/ts/redisapp-ts/config/config.ts +++ b/test/fixtures/apps/ts/redisapp-ts/config/config.ts @@ -2,16 +2,16 @@ export default { keys: 'keys', - logger:{ + logger: { level: 'INFO', }, - redis :{ + redis: { client: { host: '127.0.0.1', port: 6379, password: '', db: '0', }, - agent:true, - } -} \ No newline at end of file + agent: true, + }, +}; diff --git a/test/redis.test.ts b/test/redis.test.ts index 5ec1b86..f32b9be 100644 --- a/test/redis.test.ts +++ b/test/redis.test.ts @@ -1,6 +1,7 @@ import compile from 'node:child_process'; import path from 'node:path'; -import { mm, MockApplication } from '@eggjs/mock'; + +import { mm, type MockApplication } from '@eggjs/mock'; import snapshot from 'snap-shot-it'; describe('test/redis.test.js', () => { @@ -20,10 +21,7 @@ describe('test/redis.test.js', () => { }); it('should query', () => { - return app.httpRequest() - .get('/') - .expect(200) - .expect('bar'); + return app.httpRequest().get('/').expect(200).expect('bar'); }); }); @@ -39,10 +37,7 @@ describe('test/redis.test.js', () => { afterEach(mm.restore); it('should query', () => { - return app.httpRequest() - .get('/') - .expect(200) - .expect('bar'); + return app.httpRequest().get('/').expect(200).expect('bar'); }); }); @@ -58,10 +53,7 @@ describe('test/redis.test.js', () => { afterEach(mm.restore); it('should query', () => { - return app.httpRequest() - .get('/') - .expect(200) - .expect('bar'); + return app.httpRequest().get('/').expect(200).expect('bar'); }); }); @@ -77,10 +69,7 @@ describe('test/redis.test.js', () => { afterEach(mm.restore); it('should query', () => { - return app.httpRequest() - .get('/') - .expect(200) - .expect('bar'); + return app.httpRequest().get('/').expect(200).expect('bar'); }); }); @@ -96,10 +85,7 @@ describe('test/redis.test.js', () => { afterEach(mm.restore); it('should query', () => { - return app.httpRequest() - .get('/') - .expect(200) - .expect('bar'); + return app.httpRequest().get('/').expect(200).expect('bar'); }); }); @@ -126,10 +112,7 @@ describe('test/redis.test.js', () => { }); it('should query', () => { - return app.httpRequest() - .get('/') - .expect(200) - .expect('bar'); + return app.httpRequest().get('/').expect(200).expect('bar'); }); }); @@ -152,10 +135,7 @@ describe('test/redis.test.js', () => { }); it('should query', () => { - return app.httpRequest() - .get('/') - .expect(200) - .expect('bar'); + return app.httpRequest().get('/').expect(200).expect('bar'); }); }); @@ -172,10 +152,7 @@ describe('test/redis.test.js', () => { afterEach(mm.restore); it('should query', () => { - return app.httpRequest() - .get('/') - .expect(200) - .expect('bar'); + return app.httpRequest().get('/').expect(200).expect('bar'); }); }); @@ -191,10 +168,7 @@ describe('test/redis.test.js', () => { afterEach(mm.restore); it('should query', () => { - return app.httpRequest() - .get('/') - .expect(200) - .expect('bar'); + return app.httpRequest().get('/').expect(200).expect('bar'); }); }); @@ -211,10 +185,7 @@ describe('test/redis.test.js', () => { afterEach(mm.restore); it('should query', () => { - return app.httpRequest() - .get('/') - .expect(200) - .expect('bar'); + return app.httpRequest().get('/').expect(200).expect('bar'); }); }); });