Skip to content

Commit b84bb92

Browse files
authored
style: replace unicorn/no-for-loop w/ typescript/prefer-for-of (#20798)
* style: replace unicorn/no-for-loop w/ typescript/prefer-for-of * style: fix typescript-eslint/prefer-for-of * style: fix typescript/no-inferrable-types * style: fix typescript-eslint/consistent-generic-constructors * style: typescript-eslint/consistent-type-assertions * style: fix typescript-eslint/array-type * fix: revert .entries() in d96ca62
1 parent 1352d30 commit b84bb92

File tree

214 files changed

+575
-566
lines changed

Some content is hidden

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

214 files changed

+575
-566
lines changed

eslint.config.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default [
2929
{
3030
ignores: ['**/coverage', '**/.vscode', '**/docker-compose.yml', '!.github', 'assets/build', 'lib/routes-deprecated', 'lib/router.js', '**/babel.config.js', 'scripts/docker/minify-docker.js', 'dist', 'dist-lib'],
3131
},
32-
...compat.extends('eslint:recommended', 'plugin:yml/recommended', 'plugin:@typescript-eslint/recommended'),
32+
...compat.extends('eslint:recommended', 'plugin:yml/recommended', 'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/stylistic'),
3333
n.configs['flat/recommended-script'],
3434
unicorn.configs.recommended,
3535
{
@@ -147,8 +147,16 @@ export default [
147147
'require-await': 'error',
148148

149149
// typescript
150+
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
151+
150152
'@typescript-eslint/ban-ts-comment': 'off',
153+
'@typescript-eslint/consistent-indexed-object-style': 'off', // stylistic
154+
'@typescript-eslint/consistent-type-definitions': 'off', // stylistic
155+
'@typescript-eslint/no-empty-function': 'off', // stylistic && tests
151156
'@typescript-eslint/no-explicit-any': 'off',
157+
158+
'@typescript-eslint/no-inferrable-types': ['error', { ignoreParameters: true, ignoreProperties: true }],
159+
152160
'@typescript-eslint/no-var-requires': 'off',
153161

154162
'@typescript-eslint/no-unused-expressions': [
@@ -167,6 +175,8 @@ export default [
167175
},
168176
],
169177

178+
'@typescript-eslint/prefer-for-of': 'error',
179+
170180
// unicorn
171181
'unicorn/consistent-function-scoping': 'warn',
172182
'unicorn/explicit-length-check': 'off',
@@ -184,6 +194,7 @@ export default [
184194
'unicorn/no-array-sort': 'warn',
185195
'unicorn/no-await-expression-member': 'off',
186196
'unicorn/no-empty-file': 'warn',
197+
'unicorn/no-for-loop': 'off',
187198
'unicorn/no-hex-escape': 'warn',
188199
'unicorn/no-null': 'off',
189200
'unicorn/no-object-as-default-parameter': 'warn',

lib/registry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ for (const namespace in namespaces) {
223223
continue;
224224
}
225225

226-
const sortedRoutes = Object.entries(namespaceData.apiRoutes) as [
226+
const sortedRoutes = Object.entries(namespaceData.apiRoutes) as Array<[
227227
string,
228228
APIRoute & {
229229
location: string;
230230
module?: () => Promise<{ apiRoute: APIRoute }>;
231231
},
232-
][];
232+
]>;
233233

234234
for (const [path, routeData] of sortedRoutes) {
235235
const wrappedHandler: Handler = async (ctx) => {

lib/routes-deprecated/lolapp/article.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module.exports = async (ctx) => {
1010
const name = data[0].feedNews.footer.source;
1111
const newData = [];
1212
let pubDate = [];
13-
for (const [i, datum] of data.entries()) {
14-
newData[i] = datum.feedNews.body;
13+
for (let i = 0; i < data.length; i++) {
14+
newData[i] = data[i].feedNews.body;
1515
newData[i].link = 'https://mlol.qt.qq.com/go/mlol_news/varcache_article?is_lqt=true&docid=' + newData[i].commentID;
1616
pubDate[i] = getPublishedDate(newData[i].link);
1717
}

lib/routes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async function checkRSS(response) {
5151
checkDate(parsed.lastBuildDate);
5252

5353
// check items
54-
const guids: (string | undefined)[] = [];
54+
const guids: Array<string | undefined> = [];
5555
for (const item of parsed.items) {
5656
expect(item).toEqual(expect.any(Object));
5757
expect(item.title).toEqual(expect.any(String));

lib/routes/0xxx/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
1515
const { filter } = ctx.req.param();
1616
const limit: number = Number.parseInt(ctx.req.query('limit') ?? '100', 10);
1717

18-
const baseUrl: string = 'https://0xxx.ws';
18+
const baseUrl = 'https://0xxx.ws';
1919
const targetUrl: string = new URL(filter ? `?${filter}` : '', baseUrl).href;
2020

2121
const response = await ofetch(targetUrl);

lib/routes/10000link/info.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
1515
const { category = 'newslists', id } = ctx.req.param();
1616
const limit: number = Number.parseInt(ctx.req.query('limit') ?? '30', 10);
1717

18-
const baseUrl: string = 'https://info.10000link.com';
18+
const baseUrl = 'https://info.10000link.com';
1919
const targetUrl: string = new URL(`${category}.aspx${id ? `?chid=${id}` : ''}`, baseUrl).href;
2020

2121
const response = await ofetch(targetUrl);
@@ -109,7 +109,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
109109
)
110110
).filter((_): _ is DataItem => true);
111111

112-
const author: string = '10000万联网';
112+
const author = '10000万联网';
113113
const title: string = $('h1').contents().first().text();
114114

115115
return {

lib/routes/121/weather-live.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const renderDescription = (description, images) =>
2727
export const handler = async (ctx: Context): Promise<Data> => {
2828
const limit: number = Number.parseInt(ctx.req.query('limit') ?? '100', 10);
2929

30-
const baseUrl: string = 'https://tf.121.com.cn';
31-
const imgBaseUrl: string = 'https://wx.121.com.cn';
30+
const baseUrl = 'https://tf.121.com.cn';
31+
const imgBaseUrl = 'https://wx.121.com.cn';
3232
const targetUrl: string = new URL('web/weatherLive/', baseUrl).href;
3333
const apiUrl: string = new URL('weather/weibo/message.js', baseUrl).href;
3434

@@ -52,7 +52,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
5252
);
5353
const pubDate: number | string = item.DDatetime;
5454
const linkUrl: string | undefined = targetUrl;
55-
const guid: string = `121-${title}-${pubDate}`;
55+
const guid = `121-${title}-${pubDate}`;
5656
const image: string | undefined = item.Img?.length > 0 ? new URL(`WeChat/data/weiweb/images/lwspic/${item.Img[0]}`, imgBaseUrl).href : undefined;
5757
const updated: number | string = pubDate;
5858

lib/routes/199it/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
1414
const { category = 'newly' } = ctx.req.param();
1515
const limit: number = Number.parseInt(ctx.req.query('limit') ?? '30', 10);
1616

17-
const baseUrl: string = 'https://www.199it.com';
17+
const baseUrl = 'https://www.199it.com';
1818
const targetUrl: string = new URL(category, baseUrl).href;
1919

2020
const response = await ofetch(targetUrl);

lib/routes/21caijing/channel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ export const handler = async (ctx: Context): Promise<Data> => {
4545
const { name = '热点' } = ctx.req.param();
4646
const limit: number = Number.parseInt(ctx.req.query('limit') ?? '30', 10);
4747

48-
const domain: string = 'm.21jingji.com';
49-
const baseUrl: string = `https://${domain}`;
50-
const staticBaseUrl: string = 'https://static.21jingji.com';
48+
const domain = 'm.21jingji.com';
49+
const baseUrl = `https://${domain}`;
50+
const staticBaseUrl = 'https://static.21jingji.com';
5151
const menuUrl: string = new URL('m/webMenu.json', staticBaseUrl).href;
5252

5353
const menuResponse = await ofetch(menuUrl);
@@ -97,7 +97,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
9797
const authors: DataItem['author'] = [...new Set([item.mp?.name, item.author, item.editor, item.source].filter(Boolean))].map((name) => ({
9898
name,
9999
}));
100-
const guid: string = `21jingji-${item.id}`;
100+
const guid = `21jingji-${item.id}`;
101101
const image: string | undefined = item.image ?? item.thumb ?? item.listthumb;
102102
const updated: number | string = item.updatetime;
103103

lib/routes/5eplay/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ const getAcwScV2ByArg1 = (arg1) => {
1616
const unsbox = function (str: string) {
1717
const code = [15, 35, 29, 24, 33, 16, 1, 38, 10, 9, 19, 31, 40, 27, 22, 23, 25, 13, 6, 11, 39, 18, 20, 8, 14, 21, 32, 26, 2, 30, 7, 4, 17, 5, 3, 28, 34, 37, 12, 36];
1818
const res: string[] = [];
19-
// eslint-disable-next-line unicorn/no-for-loop
2019
for (let i = 0; i < str.length; i++) {
2120
const cur = str[i];
22-
for (const [j, element] of code.entries()) {
23-
if (element === i + 1) {
21+
for (let j = 0; j < code.length; j++) {
22+
if (code[j] === i + 1) {
2423
res[j] = cur;
2524
}
2625
}

0 commit comments

Comments
 (0)