Skip to content

Commit 0ae16e4

Browse files
authored
feat: use oxlint (#298)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Enhanced development tooling by streamlining code formatting and quality checks. - Introduced automated pre-commit validations to ensure consistent style and error reporting. - Updated project scripts and dependencies to support the new toolchain for improved maintainability. - Added new linting and formatting configuration files to enforce coding standards. - Removed outdated linting configurations to transition to a new linting strategy. - Improved type safety and clarity across various files in the codebase. - Modified assertions in tests to reflect changes in expected behavior and module properties. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a616376 commit 0ae16e4

File tree

283 files changed

+2670
-1515
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

283 files changed

+2670
-1515
lines changed

.eslintignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 6 deletions
This file was deleted.

.github/workflows/nodejs.yml

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx lint-staged

.oxlintrc.json

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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+
"no-console": "allow",
55+
"no-extraneous-class": "allow",
56+
"no-empty-function": "error",
57+
"max-depth": ["error", 6],
58+
"max-lines-per-function": "allow",
59+
"no-lonely-if": "error",
60+
"max-lines": "allow",
61+
"require-await": "allow",
62+
"max-nested-callbacks": ["error", 5],
63+
"max-classes-per-file": "allow",
64+
"radix": "allow",
65+
"no-negated-condition": "error",
66+
"no-else-return": "error",
67+
"no-throw-literal": "error",
68+
69+
// import
70+
"import/exports-last": "allow",
71+
"import/max-dependencies": "allow",
72+
"import/no-cycle": "error",
73+
"import/no-anonymous-default-export": "allow",
74+
"import/no-namespace": "error",
75+
"import/named": "error",
76+
"import/export": "error",
77+
"import/no-default-export": "allow",
78+
"import/unambiguous": "error",
79+
80+
// promise
81+
"promise/no-return-wrap": "error",
82+
"promise/param-names": "error",
83+
"promise/prefer-await-to-callbacks": "allow",
84+
"promise/prefer-await-to-then": "error",
85+
"promise/prefer-catch": "error",
86+
"promise/no-return-in-finally": "error",
87+
"promise/avoid-new": "error",
88+
89+
// unicorn
90+
"unicorn/error-message": "error",
91+
"unicorn/no-null": "allow",
92+
"unicorn/filename-case": "allow",
93+
"unicorn/prefer-structured-clone": "error",
94+
"unicorn/prefer-logical-operator-over-ternary": "error",
95+
"unicorn/prefer-number-properties": "error",
96+
"unicorn/prefer-array-some": "error",
97+
"unicorn/prefer-string-slice": "error",
98+
// "unicorn/no-null": "error",
99+
"unicorn/throw-new-error": "error",
100+
"unicorn/catch-error-name": "allow",
101+
"unicorn/prefer-spread": "allow",
102+
"unicorn/numeric-separators-style": "error",
103+
"unicorn/prefer-string-raw": "error",
104+
"unicorn/text-encoding-identifier-case": "error",
105+
"unicorn/no-array-for-each": "error",
106+
"unicorn/explicit-length-check": "error",
107+
"unicorn/no-lonely-if": "error",
108+
"unicorn/no-useless-undefined": "allow",
109+
"unicorn/prefer-date-now": "error",
110+
"unicorn/no-static-only-class": "allow",
111+
"unicorn/no-typeof-undefined": "error",
112+
"unicorn/prefer-negative-index": "error",
113+
"unicorn/no-anonymous-default-export": "allow",
114+
"unicorn/prefer-event-target": "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+
"oxc/no-barrel-file": "allow",
122+
123+
// typescript
124+
"typescript/explicit-function-return-type": "allow",
125+
"typescript/consistent-type-imports": "error",
126+
"typescript/consistent-type-definitions": "error",
127+
"typescript/consistent-indexed-object-style": "allow",
128+
"typescript/no-inferrable-types": "error",
129+
"typescript/array-type": "error",
130+
"typescript/no-non-null-assertion": "error",
131+
"typescript/no-explicit-any": "allow",
132+
"typescript/no-import-type-side-effects": "error",
133+
"typescript/no-dynamic-delete": "error",
134+
"typescript/prefer-ts-expect-error": "error",
135+
"typescript/ban-ts-comment": "error",
136+
"typescript/prefer-enum-initializers": "error",
137+
138+
// jsdoc
139+
"jsdoc/require-returns": "allow",
140+
"jsdoc/require-param": "allow"
141+
},
142+
"overrides": [
143+
{
144+
"rules": {
145+
"unicorn/no-array-for-each": "allow",
146+
"promise/avoid-new": "allow",
147+
"max-nested-callbacks": "allow"
148+
},
149+
"files": ["test/**/*.ts"]
150+
}
151+
],
152+
"ignorePatterns": [
153+
"index.d.ts",
154+
"test/fixtures/**",
155+
"__snapshots__",
156+
"benchmark"
157+
]
158+
}

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CHANGELOG.md
2+
__snapshots__
3+
benchmark

.prettierrc

Lines changed: 6 additions & 0 deletions
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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Then you can start with code below
6262
import { EggCore as Application } from '@eggjs/core';
6363

6464
const app = new Application({
65-
baseDir: '/path/to/app'
65+
baseDir: '/path/to/app',
6666
});
6767
app.ready(() => {
6868
app.listen(3000);
@@ -140,13 +140,13 @@ Load app/service
140140
Retrieve application environment variable values via `serverEnv`.
141141
You can access directly by calling `this.serverEnv` after instantiation.
142142

143-
serverEnv | description
144-
--- | ---
145-
default | default environment
146-
test | system integration testing environment
147-
prod | production environment
148-
local | local environment on your own computer
149-
unittest | unit test environment
143+
| serverEnv | description |
144+
| --------- | -------------------------------------- |
145+
| default | default environment |
146+
| test | system integration testing environment |
147+
| prod | production environment |
148+
| local | local environment on your own computer |
149+
| unittest | unit test environment |
150150

151151
#### getEggPaths()
152152

@@ -163,7 +163,7 @@ This function will get add loadUnits follow the order:
163163
2. framework
164164
3. app
165165

166-
loadUnit has a path and a type. Type must be one of those values: *app*, *framework*, *plugin*.
166+
loadUnit has a path and a type. Type must be one of those values: _app_, _framework_, _plugin_.
167167

168168
```js
169169
{
@@ -174,7 +174,7 @@ loadUnit has a path and a type. Type must be one of those values: *app*, *framew
174174

175175
#### getAppname()
176176

177-
To get application name from *package.json*
177+
To get application name from _package.json_
178178

179179
#### appInfo
180180

@@ -228,18 +228,18 @@ await this.loadExtend('application', app);
228228

229229
### LoaderOptions
230230

231-
Param | Type | Description
232-
-------------- | -------------- | ------------------------
233-
directory | `String/Array` | directories to be loaded
234-
target | `Object` | attach the target object from loaded files
235-
match | `String/Array` | match the files when load, default to `**/*.js`(if process.env.EGG_TYPESCRIPT was true, default to `[ '**/*.(js|ts)', '!**/*.d.ts' ]`)
236-
ignore | `String/Array` | ignore the files when load
237-
initializer | `Function` | custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path`
238-
caseStyle | `String/Function` | set property's case when converting a filepath to property list.
239-
override | `Boolean` | determine whether override the property when get the same name
240-
call | `Boolean` | determine whether invoke when exports is function
241-
inject | `Object` | an object that be the argument when invoke the function
242-
filter | `Function` | a function that filter the exports which can be loaded
231+
| Param | Type | Description |
232+
| ----------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- |
233+
| directory | `String/Array` | directories to be loaded |
234+
| target | `Object` | attach the target object from loaded files |
235+
| match | `String/Array` | match the files when load, default to `**/*.js`(if process.env.EGG\*TYPESCRIPT was true, default to `[ '\*\*/\_.(js | ts)', '!\*_/_.d.ts' ]`) |
236+
| ignore | `String/Array` | ignore the files when load |
237+
| initializer | `Function` | custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path` |
238+
| caseStyle | `String/Function` | set property's case when converting a filepath to property list. |
239+
| override | `Boolean` | determine whether override the property when get the same name |
240+
| call | `Boolean` | determine whether invoke when exports is function |
241+
| inject | `Object` | an object that be the argument when invoke the function |
242+
| filter | `Function` | a function that filter the exports which can be loaded |
243243

244244
## Timing
245245

benchmark/middleware/app/middleware/async.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
let index = 0;
44

5-
module.exports = function () {
5+
module.exports = function exports() {
66
return async (ctx, next) => {
77
await next();
88
ctx.body.push(`async middleware #${++index}`);

benchmark/middleware/app/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ module.exports = app => {
99

1010
app.get('/', app.controller.home.index);
1111
app.get('/async', ...asyncMiddlewares, 'home.async');
12-
}
12+
};

benchmark/middleware/start.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ const app = new EggApplication({
77
type: 'application',
88
});
99

10-
app.loader.loadAll().then(() => {
11-
app.listen(7001);
12-
console.log('server started at 7001');
13-
}).catch(err => {
14-
throw err;
15-
});
16-
10+
app.loader
11+
.loadAll()
12+
.then(() => {
13+
app.listen(7001);
14+
console.log('server started at 7001');
15+
})
16+
.catch(err => {
17+
throw err;
18+
});

example/middleware/hello.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MiddlewareFunc } from '../../src/index.js';
1+
import type { MiddlewareFunc } from '../../src/index.js';
22

33
export const hello: MiddlewareFunc = async (ctx, next) => {
44
console.log('Hello middleware');

package.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@
1010
"description": "A core plugin framework based on @eggjs/koa",
1111
"scripts": {
1212
"clean": "rimraf dist",
13-
"lint": "eslint src test --ext ts",
13+
"lint": "oxlint",
1414
"pretest": "npm run clean && npm run lint -- --fix && npm run prepublishOnly",
1515
"test": "egg-bin test",
1616
"posttest": "npm run clean",
1717
"test-local": "egg-bin test",
1818
"preci": "npm run clean && npm run lint && npm run prepublishOnly",
1919
"ci": "egg-bin cov",
2020
"postci": "npm run clean",
21-
"prepublishOnly": "tshy && tshy-after && attw --pack"
21+
"prepublishOnly": "tshy && tshy-after && attw --pack",
22+
"prepare": "husky"
23+
},
24+
"lint-staged": {
25+
"*": "prettier --write --ignore-unknown --cache",
26+
"*.{ts,js,json,md,yml}": [
27+
"prettier --ignore-unknown --write",
28+
"oxlint --fix"
29+
]
2230
},
2331
"repository": {
2432
"type": "git",
@@ -51,7 +59,7 @@
5159
"utility": "^2.1.0"
5260
},
5361
"devDependencies": {
54-
"@arethetypeswrong/cli": "^0.17.1",
62+
"@arethetypeswrong/cli": "^0.17.4",
5563
"@eggjs/bin": "7",
5664
"@eggjs/supertest": "^8.1.1",
5765
"@eggjs/tsconfig": "1",
@@ -60,8 +68,10 @@
6068
"@types/node": "22",
6169
"await-event": "2",
6270
"coffee": "5",
63-
"eslint": "8",
64-
"eslint-config-egg": "14",
71+
"husky": "9",
72+
"lint-staged": "15",
73+
"oxlint": "^0.16.2",
74+
"prettier": "3",
6575
"gals": "1",
6676
"js-yaml": "3",
6777
"mm": "^4.0.2",

0 commit comments

Comments
 (0)