Skip to content

Commit 9900e87

Browse files
authored
feat: use oxlint and prettier (#48)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Updated dependencies, automation workflows, and build scripts to streamline development and maintain consistency. - **New Features** - Integrated an automated pre-commit hook to ensure code quality with every change. - **Style** - Standardized and improved code formatting and readability across configuration, source, and test files. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 0afe42b commit 9900e87

File tree

35 files changed

+334
-167
lines changed

35 files changed

+334
-167
lines changed

.eslintignore

-3
This file was deleted.

.eslintrc

-6
This file was deleted.

.github/workflows/nodejs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
7-
branches: [ master ]
7+
branches: [master]
88

99
jobs:
1010
Job:

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Release
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66

77
jobs:
88
release:

.husky/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx lint-staged

.oxlintrc.json

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
{
2+
"$schema": "./node_modules/oxlint/configuration_schema.json",
3+
"env": {
4+
"node": true,
5+
"mocha": true
6+
},
7+
"categories": {
8+
"correctness": "error",
9+
"perf": "error",
10+
"nursery": "error",
11+
"restriction": "error",
12+
"style": "error",
13+
"pedantic": "error",
14+
"suspicious": "error"
15+
},
16+
"plugins": [
17+
"import",
18+
"typescript",
19+
"unicorn",
20+
"jsdoc",
21+
"node",
22+
"promise",
23+
"oxc"
24+
],
25+
"rules": {
26+
// eslint
27+
"constructor-super": "error",
28+
"getter-return": "error",
29+
"no-undef": "error",
30+
"no-unreachable": "error",
31+
"no-var": "error",
32+
"no-eq-null": "error",
33+
"no-await-in-loop": "allow",
34+
"eqeqeq": ["error", "smart"],
35+
"init-declarations": "allow",
36+
"curly": "allow",
37+
"no-ternary": "allow",
38+
"max-params": ["error", 5],
39+
"no-await-expression-member": "error",
40+
"no-continue": "allow",
41+
"guard-for-in": "allow",
42+
"func-style": "allow",
43+
"sort-imports": "allow",
44+
"yoda": "allow",
45+
"sort-keys": "allow",
46+
"no-magic-numbers": "allow",
47+
"no-duplicate-imports": "error",
48+
"no-multi-assign": "error",
49+
"func-names": "error",
50+
"default-param-last": "error",
51+
"prefer-object-spread": "error",
52+
"no-undefined": "allow",
53+
"no-plusplus": "allow",
54+
// maybe warn
55+
"no-console": "warn",
56+
"no-extraneous-class": "allow",
57+
"no-empty-function": "error",
58+
"max-depth": ["error", 6],
59+
"max-lines-per-function": "allow",
60+
"no-lonely-if": "error",
61+
"max-lines": "allow",
62+
"require-await": "allow",
63+
"max-nested-callbacks": ["error", 5],
64+
"max-classes-per-file": "allow",
65+
"radix": "allow",
66+
"no-negated-condition": "error",
67+
"no-else-return": "error",
68+
"no-throw-literal": "error",
69+
70+
// import
71+
"import/exports-last": "allow",
72+
"import/max-dependencies": "allow",
73+
"import/no-cycle": "error",
74+
"import/no-anonymous-default-export": "allow",
75+
"import/no-namespace": "error",
76+
"import/named": "error",
77+
"import/export": "error",
78+
"import/no-default-export": "allow",
79+
"import/unambiguous": "error",
80+
81+
// promise
82+
"promise/no-return-wrap": "error",
83+
"promise/param-names": "error",
84+
"promise/prefer-await-to-callbacks": "error",
85+
"promise/prefer-await-to-then": "error",
86+
"promise/prefer-catch": "error",
87+
"promise/no-return-in-finally": "error",
88+
"promise/avoid-new": "error",
89+
90+
// unicorn
91+
"unicorn/error-message": "error",
92+
"unicorn/no-null": "allow",
93+
"unicorn/filename-case": "allow",
94+
"unicorn/prefer-structured-clone": "error",
95+
"unicorn/prefer-logical-operator-over-ternary": "error",
96+
"unicorn/prefer-number-properties": "error",
97+
"unicorn/prefer-array-some": "error",
98+
"unicorn/prefer-string-slice": "error",
99+
// "unicorn/no-null": "error",
100+
"unicorn/throw-new-error": "error",
101+
"unicorn/catch-error-name": "allow",
102+
"unicorn/prefer-spread": "allow",
103+
"unicorn/numeric-separators-style": "error",
104+
"unicorn/prefer-string-raw": "error",
105+
"unicorn/text-encoding-identifier-case": "error",
106+
"unicorn/no-array-for-each": "error",
107+
"unicorn/explicit-length-check": "error",
108+
"unicorn/no-lonely-if": "error",
109+
"unicorn/no-useless-undefined": "allow",
110+
"unicorn/prefer-date-now": "error",
111+
"unicorn/no-static-only-class": "allow",
112+
"unicorn/no-typeof-undefined": "error",
113+
"unicorn/prefer-negative-index": "error",
114+
"unicorn/no-anonymous-default-export": "allow",
115+
116+
// oxc
117+
"oxc/no-map-spread": "error",
118+
"oxc/no-rest-spread-properties": "allow",
119+
"oxc/no-optional-chaining": "allow",
120+
"oxc/no-async-await": "allow",
121+
122+
// typescript
123+
"typescript/explicit-function-return-type": "allow",
124+
"typescript/consistent-type-imports": "error",
125+
"typescript/consistent-type-definitions": "error",
126+
"typescript/consistent-indexed-object-style": "allow",
127+
"typescript/no-inferrable-types": "error",
128+
"typescript/array-type": "error",
129+
"typescript/no-non-null-assertion": "error",
130+
"typescript/no-explicit-any": "error",
131+
"typescript/no-import-type-side-effects": "error",
132+
"typescript/no-dynamic-delete": "error",
133+
"typescript/prefer-ts-expect-error": "error",
134+
"typescript/ban-ts-comment": "error",
135+
"typescript/prefer-enum-initializers": "error",
136+
137+
// jsdoc
138+
"jsdoc/require-returns": "allow",
139+
"jsdoc/require-param": "allow"
140+
},
141+
"ignorePatterns": ["index.d.ts", "test/fixtures/**", "__snapshots__"]
142+
}

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CHANGELOG.md
2+
__snapshots__

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5",
4+
"tabWidth": 2,
5+
"arrowParens": "avoid"
6+
}

README.md

+20-19
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,23 @@ Configure redis information in `${app_root}/config/config.default.js`:
4949
```javascript
5050
config.redis = {
5151
client: {
52-
port: 6379, // Redis port
53-
host: '127.0.0.1', // Redis host
52+
port: 6379, // Redis port
53+
host: '127.0.0.1', // Redis host
5454
password: 'auth',
5555
db: 0,
5656
},
57-
}
57+
};
5858
```
5959

6060
**Multi Clients**
6161

6262
```javascript
6363
config.redis = {
6464
clients: {
65-
foo: { // instanceName. See below
66-
port: 6379, // Redis port
67-
host: '127.0.0.1', // Redis host
65+
foo: {
66+
// instanceName. See below
67+
port: 6379, // Redis port
68+
host: '127.0.0.1', // Redis host
6869
password: 'auth',
6970
db: 0,
7071
},
@@ -74,8 +75,8 @@ config.redis = {
7475
password: 'auth',
7576
db: 1,
7677
},
77-
}
78-
}
78+
},
79+
};
7980
```
8081

8182
**Sentinel**
@@ -86,16 +87,16 @@ config.redis = {
8687
// Sentinel instances
8788
sentinels: [
8889
{
89-
port: 26379, // Sentinel port
90-
host: '127.0.0.1', // Sentinel host
90+
port: 26379, // Sentinel port
91+
host: '127.0.0.1', // Sentinel host
9192
},
9293
// other sentinel instance config
9394
],
94-
name: 'mymaster', // Master name
95+
name: 'mymaster', // Master name
9596
password: 'auth',
96-
db: 0
97+
db: 0,
9798
},
98-
}
99+
};
99100
```
100101

101102
**No password**
@@ -127,26 +128,26 @@ you can pass the instance by `config.redis.Redis`:
127128
config.redis = {
128129
Redis: require('ioredis'), // customize ioredis version, only set when you needed
129130
client: {
130-
port: 6379, // Redis port
131-
host: '127.0.0.1', // Redis host
131+
port: 6379, // Redis port
132+
host: '127.0.0.1', // Redis host
132133
password: 'auth',
133134
db: 0,
134135
},
135-
}
136+
};
136137
```
137138

138139
**weakDependent**
139140

140141
```javascript
141142
config.redis = {
142143
client: {
143-
port: 6379, // Redis port
144-
host: '127.0.0.1', // Redis host
144+
port: 6379, // Redis port
145+
host: '127.0.0.1', // Redis host
145146
password: 'auth',
146147
db: 0,
147148
weakDependent: true, // the redis instance won't block app start
148149
},
149-
}
150+
};
150151
```
151152

152153
## Usage

example/hello/app/router.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Application } from 'egg';
1+
import type { Application } from 'egg';
22

33
export default (app: Application) => {
44
const { router } = app;

example/hello/start.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'node:path';
22
import { fileURLToPath } from 'node:url';
3+
34
import { startEgg } from 'egg';
45

56
const __filename = fileURLToPath(import.meta.url);
@@ -9,4 +10,7 @@ const app = await startEgg({
910
baseDir: __dirname,
1011
});
1112

12-
console.log(`Server started at http://localhost:${app.config.cluster.listen.port}`);
13+
// oxlint-disable-next-line no-console
14+
console.log(
15+
`Server started at http://localhost:${app.config.cluster.listen.port}`
16+
);

package.json

+17-7
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,44 @@
3535
"node": ">= 18.19.0"
3636
},
3737
"dependencies": {
38-
"@eggjs/core": "^6.3.0",
38+
"@eggjs/core": "^6.4.1",
3939
"ioredis": "^5.4.2"
4040
},
4141
"devDependencies": {
42-
"@arethetypeswrong/cli": "^0.17.1",
42+
"@arethetypeswrong/cli": "^0.17.4",
4343
"@eggjs/bin": "7",
4444
"@eggjs/mock": "^6.0.5",
4545
"@eggjs/tsconfig": "1",
4646
"@types/mocha": "10",
4747
"@types/node": "22",
48-
"egg": "^4.0.3",
49-
"eslint": "8",
50-
"eslint-config-egg": "14",
48+
"egg": "4",
49+
"husky": "^9.1.7",
50+
"lint-staged": "^15.5.0",
51+
"oxlint": "^0.16.2",
52+
"prettier": "^3.5.3",
5153
"rimraf": "6",
5254
"snap-shot-it": "^7.9.10",
5355
"tshy": "3",
5456
"tshy-after": "1",
5557
"typescript": "5"
5658
},
5759
"scripts": {
58-
"lint": "eslint --cache src test --ext .ts",
60+
"lint": "oxlint",
5961
"pretest": "npm run clean && npm run lint -- --fix",
6062
"test": "egg-bin test",
6163
"preci": "npm run clean && npm run lint",
6264
"ci": "egg-bin cov",
6365
"postci": "npm run prepublishOnly && npm run clean",
6466
"clean": "rimraf dist",
65-
"prepublishOnly": "tshy && tshy-after && attw --pack"
67+
"prepublishOnly": "tshy && tshy-after && attw --pack",
68+
"prepare": "husky"
69+
},
70+
"lint-staged": {
71+
"*": "prettier --write --ignore-unknown --cache",
72+
"*.{ts,js,json,md,yml}": [
73+
"prettier --ignore-unknown --write",
74+
"oxlint --fix"
75+
]
6676
},
6777
"type": "module",
6878
"tshy": {

src/config/config.default.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RedisOptions, ClusterOptions } from 'ioredis';
1+
import type { RedisOptions, ClusterOptions, Redis } from 'ioredis';
22

33
export interface RedisClientOptions extends RedisOptions {
44
/**
@@ -54,7 +54,7 @@ export interface RedisConfig {
5454
*
5555
* Default to `undefined`, which means using the built-in ioredis
5656
*/
57-
Redis?: any;
57+
Redis?: typeof Redis;
5858
}
5959

6060
export default {

0 commit comments

Comments
 (0)