Skip to content

Commit 7f69524

Browse files
authored
chore(lint): enable e18e rules with oxlint (#6075)
Add `@e18e/eslint-plugin` to `oxlint` to detect avoidable allocations and older JavaScript patterns. Use the shared dependency catalog for the plugin version. Enable 12 compatible rules and update existing code to satisfy them. Keep dependency replacements and regular-expression relocation outside this change. Disable `.concat()` spread fixes because `oxlint` lacks the required type information. Defer the three array-copy rules because the TypeScript configuration targets `ES2022`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Updated code quality checks to enforce modern JavaScript patterns across the project. * **Refactor** * Applied consistent modern JavaScript methods across application logic and tests. These changes preserve existing behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 2448031 commit 7f69524

33 files changed

Lines changed: 60 additions & 46 deletions

File tree

‎.oxlintrc.json‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"$schema": "./node_modules/oxlint/configuration_schema.json",
3+
"jsPlugins": ["@e18e/eslint-plugin"],
34
"env": {
45
"node": true
56
},
@@ -11,6 +12,18 @@
1112
],
1213
"rules": {
1314
"no-unused-vars": "error",
14-
"preserve-caught-error": "error"
15+
"preserve-caught-error": "error",
16+
"e18e/prefer-array-at": "error",
17+
"e18e/prefer-array-fill": "error",
18+
"e18e/prefer-includes": "error",
19+
"e18e/prefer-nullish-coalescing": "error",
20+
"e18e/prefer-object-has-own": "error",
21+
"e18e/prefer-url-canparse": "error",
22+
"e18e/prefer-array-from-map": "error",
23+
"e18e/prefer-timer-args": "error",
24+
"e18e/prefer-date-now": "error",
25+
"e18e/prefer-regex-test": "error",
26+
"e18e/prefer-array-some": "error",
27+
"e18e/prefer-string-fromcharcode": "error"
1528
}
1629
}

‎.utoo.toml‎

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

33
[catalog]
44
"@clack/prompts" = "^0.11.0"
5+
"@e18e/eslint-plugin" = "^0.8.1"
56
"@eggjs/compressible" = "^3.0.0"
67
"@eggjs/cookies" = "^3.1.0"
78
"@eggjs/ip" = "^2.1.0"

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"version:rc": "node scripts/version.js prerelease --prerelease-tag=rc"
5252
},
5353
"devDependencies": {
54+
"@e18e/eslint-plugin": "catalog:",
5455
"@eggjs/bin": "workspace:*",
5556
"@eggjs/tsconfig": "workspace:*",
5657
"@oxc-node/core": "catalog:",

‎packages/cookies/test/cookies.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('test/cookies.test.ts', () => {
2828
cookies.ctx.request.headers.cookie = cookie;
2929
const value = cookies.get('foo', { encrypt: true });
3030
assert(value, 'bar');
31-
assert(cookie.indexOf('bar') === -1);
31+
assert(!cookie.includes('bar'));
3232
});
3333

3434
it('should cache keygrip', () => {
@@ -60,8 +60,8 @@ describe('test/cookies.test.ts', () => {
6060
cookies.ctx.request.headers.cookie = cookie;
6161
const value = cookies.get('foo', { encrypt: true });
6262
assert(value, 'bar');
63-
assert(cookie.indexOf('bar') === -1);
64-
assert(cookie.indexOf('sig') === -1);
63+
assert(!cookie.includes('bar'));
64+
assert(!cookie.includes('sig'));
6565
});
6666

6767
it('should work with secure ok', () => {
@@ -116,8 +116,8 @@ describe('test/cookies.test.ts', () => {
116116
const cookies = Cookies();
117117
cookies.set('foo', 'bar', { signed: true });
118118
const cookie = cookies.ctx.response.headers['set-cookie'].join(';');
119-
assert(cookie.indexOf('foo=bar') >= 0);
120-
assert(cookie.indexOf('foo.sig=') >= 0);
119+
assert(cookie.includes('foo=bar'));
120+
assert(cookie.includes('foo.sig='));
121121
cookies.ctx.request.headers.cookie = cookie;
122122
let value = cookies.get('foo', { signed: true });
123123
assert(value === 'bar');

‎packages/egg/src/app/extend/request.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export default class Request extends EggCoreRequest {
173173
*/
174174
get acceptJSON(): boolean {
175175
if (this.path.endsWith('.json')) return true;
176-
if (this.response.type && this.response.type.indexOf('json') >= 0) return true;
176+
if (this.response.type && this.response.type.includes('json')) return true;
177177
if (this.accepts('html', 'text', 'json') === 'json') return true;
178178
return false;
179179
}

‎packages/egg/src/lib/application.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class Application extends EggApplicationCore {
7979
return;
8080
}
8181

82-
const body = raw.body == null ? DEFAULT_BAD_REQUEST_HTML : raw.body;
82+
const body = raw.body ?? DEFAULT_BAD_REQUEST_HTML;
8383
const headers = raw.headers || {};
8484
const status = raw.status || 400;
8585

‎packages/egg/test/app/extend/application.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('test/app/extend/application.test.ts', () => {
5454
'config',
5555
'httpclient',
5656
'loggers',
57-
].every((p) => Object.prototype.hasOwnProperty.call(app.inspect(), p)),
57+
].every((p) => Object.hasOwn(app.inspect(), p)),
5858
);
5959
assert(app.inspect().name === 'demo');
6060
});

‎packages/egg/test/egg.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ describe('test/egg.test.ts', { concurrent: false }, () => {
149149

150150
it.skip('should disable timing after ready', () => {
151151
const json = app.timing.toJSON();
152-
const last = json[json.length - 1];
152+
const last = json.at(-1);
153+
assert(last);
153154
app.timing.start('a');
154155
app.timing.end('a');
155156
const json2 = app.timing.toJSON();

‎packages/egg/test/lib/core/loader/load_service.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ describe('test/lib/core/loader/load_service.test.ts', () => {
3232
it('should service support es6', async () => {
3333
app = createApp('apps/services_loader_verify');
3434
await app.ready();
35-
assert(Object.prototype.hasOwnProperty.call(app.serviceClasses, 'foo'));
36-
assert(['bar'].every((p) => Object.prototype.hasOwnProperty.call(app.serviceClasses.foo, p)));
35+
assert(Object.hasOwn(app.serviceClasses, 'foo'));
36+
assert(['bar'].every((p) => Object.hasOwn(app.serviceClasses.foo, p)));
3737
});
3838

3939
it('should support extend app.Service class', async () => {

‎packages/egg/test/lib/core/messenger/ipc.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ describe.skip('test/lib/core/messenger/ipc.test.ts', () => {
162162
it('app should accept agent message', async () => {
163163
function count(data: string, key: string) {
164164
return data.split('\n').filter((line) => {
165-
return line.indexOf(key) >= 0;
165+
return line.includes(key);
166166
}).length;
167167
}
168168
await scheduler.wait(500);
@@ -189,7 +189,7 @@ describe.skip('test/lib/core/messenger/ipc.test.ts', () => {
189189
it('app should accept agent message', async () => {
190190
function count(data: string, key: string) {
191191
return data.split('\n').filter((line) => {
192-
return line.indexOf(key) >= 0;
192+
return line.includes(key);
193193
}).length;
194194
}
195195

0 commit comments

Comments
 (0)