Skip to content

Commit 03969f3

Browse files
authored
refactor: fix lint issue (#18963)
* fix: unicorn/no-empty-file * fix: unicorn/prefer-node-protocol * fix: unicorn/prefer-number-properties * fix: unicorn/consistent-destructuring * fix: unicorn/no-array-callback-reference * fix: unicorn/new-for-builtins * fix: set checkNaN to false in unicorn/prefer-number-properties * fix: unicorn/prefer-string-slice * fix: update eslint ignore
1 parent 794021a commit 03969f3

File tree

131 files changed

+181
-186
lines changed

Some content is hidden

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

131 files changed

+181
-186
lines changed

.puppeteerrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path');
1+
const path = require('node:path');
22

33
/**
44
* @type {import("puppeteer").Configuration}

api/vercel.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path');
1+
const path = require('node:path');
22
const moduleAlias = require('module-alias');
33
moduleAlias.addAlias('@', path.join(__dirname, '../lib'));
44

eslint.config.mjs

+4-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default [{
2121
'**/.vscode',
2222
'**/docker-compose.yml',
2323
'!.github',
24-
'assets/build/radar-rules.js',
24+
'assets/build',
2525
'lib/routes-deprecated',
2626
'lib/router.js',
2727
'**/babel.config.js',
@@ -131,7 +131,6 @@ unicorn.configs.recommended,
131131
}],
132132

133133
// unicorn
134-
'unicorn/consistent-destructuring': 'warn',
135134
'unicorn/consistent-function-scoping': 'warn',
136135
'unicorn/explicit-length-check': 'off',
137136

@@ -140,7 +139,6 @@ unicorn.configs.recommended,
140139
ignore: [String.raw`.*\.(yaml|yml)$`, String.raw`RequestInProgress\.js$`],
141140
}],
142141

143-
'unicorn/new-for-builtins': 'off',
144142
'unicorn/no-array-callback-reference': 'warn',
145143
'unicorn/no-array-reduce': 'warn',
146144
'unicorn/no-await-expression-member': 'off',
@@ -183,19 +181,15 @@ unicorn.configs.recommended,
183181
'unicorn/prefer-code-point': 'warn',
184182
'unicorn/prefer-global-this': 'off',
185183
'unicorn/prefer-import-meta-properties': 'warn',
186-
'unicorn/prefer-logical-operator-over-ternary': 'warn',
187184
'unicorn/prefer-module': 'off',
188-
'unicorn/prefer-node-protocol': 'off',
189185

190-
'unicorn/prefer-number-properties': ['warn', {
186+
'unicorn/prefer-number-properties': ['error', {
191187
checkInfinity: false,
188+
checkNaN: false,
192189
}],
193190

194-
'unicorn/prefer-object-from-entries': 'warn',
195-
'unicorn/prefer-regexp-test': 'warn',
196191
'unicorn/prefer-spread': 'warn',
197-
'unicorn/prefer-string-replace-all': 'warn',
198-
'unicorn/prefer-string-slice': 'off',
192+
'unicorn/prefer-string-slice': 'warn',
199193

200194
'unicorn/prefer-switch': ['warn', {
201195
emptyDefaultCase: 'do-nothing-comment',

lib/middleware/parameter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,12 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
400400
if (ctx.req.query('brief')) {
401401
const num = /[1-9]\d{2,}/;
402402
if (num.test(ctx.req.query('brief')!)) {
403-
const brief = Number.parseInt(ctx.req.query('brief')!);
403+
const brief: number = Number.parseInt(ctx.req.query('brief')!);
404404
for (const item of data.item) {
405405
let text;
406406
if (item.description) {
407407
text = sanitizeHtml(item.description, { allowedTags: [], allowedAttributes: {} });
408-
item.description = text.length > brief ? `<p>${text.substring(0, brief)}…</p>` : `<p>${text}</p>`;
408+
item.description = text.length > brief ? `<p>${text.slice(0, brief)}…</p>` : `<p>${text}</p>`;
409409
}
410410
}
411411
} else {

lib/routes/1point3acres/section.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ async function handler(ctx) {
6666
const order = ctx.req.param('order') ?? '';
6767
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10;
6868

69-
const currentUrl = `${rootUrl}${id ? (isNaN(id) ? `/category/${id}` : `/section/${id}`) : ''}`;
70-
const apiUrl = `${apiRootUrl}/api${id ? (isNaN(id) ? `/tags/${id}/` : `/forums/${id}/`) : ''}threads?type=${type}&includes=tags,forum_name,summary&ps=${limit}&pg=1&order=${order === '' ? '' : 'time_desc'}&is_groupid=1`;
69+
const currentUrl = `${rootUrl}${id ? (Number.isNaN(id) ? `/category/${id}` : `/section/${id}`) : ''}`;
70+
const apiUrl = `${apiRootUrl}/api${id ? (Number.isNaN(id) ? `/tags/${id}/` : `/forums/${id}/`) : ''}threads?type=${type}&includes=tags,forum_name,summary&ps=${limit}&pg=1&order=${order === '' ? '' : 'time_desc'}&is_groupid=1`;
7171

7272
return {
7373
title: `一亩三分地 - ${Object.hasOwn(sections, id) ? sections[id] : id}${types[type]}`,

lib/routes/3dmgame/news-center.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const route: Route = {
3434

3535
async function handler(ctx) {
3636
const { category = '' } = ctx.req.param();
37-
const isArcPost = category && !isNaN(category); // https://www.3dmgame.com/news/\d+/
37+
const isArcPost = category && !Number.isNaN(category); // https://www.3dmgame.com/news/\d+/
3838
const url = `https://www.3dmgame.com/${category === 'news_36_1' ? category : 'news/' + category}`;
3939
const res = await got(url);
4040
const $ = load(res.data);

lib/routes/6park/news.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async function handler(ctx) {
3838

3939
const rootUrl = `https://${isLocal ? site : 'www'}.6parknews.com`;
4040
const indexUrl = `${rootUrl}${isLocal ? '' : '/newspark'}/index.php`;
41-
const currentUrl = `${indexUrl}${keyword ? `?act=newssearch&app=news&keywords=${keyword}&submit=查询` : id ? (isNaN(id) ? `?act=${id}` : isLocal ? `?type_id=${id}` : `?type=${id}`) : ''}`;
41+
const currentUrl = `${indexUrl}${keyword ? `?act=newssearch&app=news&keywords=${keyword}&submit=查询` : id ? (Number.isNaN(id) ? `?act=${id}` : isLocal ? `?type_id=${id}` : `?type=${id}`) : ''}`;
4242

4343
const response = await got({
4444
method: 'get',

lib/routes/abc/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function handler(ctx) {
4343
let currentUrl = '';
4444
let documentId;
4545

46-
if (isNaN(category)) {
46+
if (Number.isNaN(category)) {
4747
currentUrl = new URL(category, rootUrl).href;
4848
} else {
4949
documentId = category;

lib/routes/ainvest/utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import crypto from 'crypto';
1+
import crypto from 'node:crypto';
22
import CryptoJS from 'crypto-js';
33
import { KJUR, KEYUTIL, hextob64 } from 'jsrsasign';
44

55
const publicKey =
66
'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCARnxLlrhTK28bEV7s2IROjT73KLSjfqpKIvV8L+Yhe4BrF0Ut4oOH728HZlbSF0C3N0vXZjLAFesoS4v1pYOjVCPXl920Lh2seCv82m0cK78WMGuqZTfA44Nv7JsQMHC3+J6IZm8YD53ft2d8mYBFgKektduucjx8sObe7eRyoQIDAQAB';
77

8-
const randomString = (length) => {
8+
const randomString = (length: number) => {
99
if (length > 32) {
1010
throw new Error('Max length is 32.');
1111
}
12-
return uuidv4().replaceAll('-', '').substring(0, length);
12+
return uuidv4().replaceAll('-', '').slice(0, length);
1313
};
1414

1515
const uuidv4 = () => crypto.randomUUID();

lib/routes/bast/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function handler(ctx) {
1818
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50;
1919

2020
const rootUrl = 'https://www.bast.net.cn';
21-
const currentUrl = `${rootUrl}/${isNaN(colPath) ? colPath : `col/col${colPath}`}/`;
21+
const currentUrl = `${rootUrl}/${Number.isNaN(colPath) ? colPath : `col/col${colPath}`}/`;
2222

2323
const response = await got({
2424
method: 'get',

lib/routes/behance/user.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function handler(ctx) {
5454

5555
const uuid = crypto.randomUUID();
5656
const headers = {
57-
Cookie: `gk_suid=${Math.random().toString().substring(2, 10)}, gki=; originalReferrer=; bcp=${uuid}`,
57+
Cookie: `gk_suid=${Math.random().toString().slice(2, 10)}, gki=; originalReferrer=; bcp=${uuid}`,
5858
'X-BCP': uuid,
5959
'X-Requested-With': 'XMLHttpRequest',
6060
};

lib/routes/bilibili/danmaku.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Route } from '@/types';
22
import { load } from 'cheerio';
33
import cache from './cache';
44
import got from '@/utils/got';
5-
import zlib from 'zlib';
5+
import zlib from 'node:zlib';
66

77
const processFloatTime = (time) => {
88
const totalSeconds = Number.parseInt(time);

lib/routes/bilibili/followings-dynamic.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { config } from '@/config';
55
import utils from './utils';
66
import JSONbig from 'json-bigint';
77
import { fallback, queryToBoolean } from '@/utils/readable-social';
8-
import querystring from 'querystring';
8+
import querystring from 'node:querystring';
99
import ConfigNotFoundError from '@/errors/types/config-not-found';
1010

1111
export const route: Route = {

lib/routes/bilibili/wasm-exec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
outputBuf += decoder.decode(buf);
2424
const nl = outputBuf.lastIndexOf('\n');
2525
if (nl !== -1) {
26-
console.log(outputBuf.substring(0, nl));
27-
outputBuf = outputBuf.substring(nl + 1);
26+
console.log(outputBuf.slice(0, nl));
27+
outputBuf = outputBuf.slice(nl + 1);
2828
}
2929
return buf.length;
3030
},
@@ -552,7 +552,7 @@
552552
this.mem = new DataView(this._inst.exports.mem.buffer);
553553
this._values = [
554554
// JS values that Go currently has references to, indexed by reference id
555-
Number.NaN,
555+
NaN,
556556
0,
557557
null,
558558
true,

lib/routes/bnu/jwb.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async function handler() {
3131
const a = e.find('a');
3232
return {
3333
title: e.find('a span').text(),
34-
link: a.attr('href').startsWith('http') ? a.attr('href') : 'https://jwb.bnu.edu.cn' + a.attr('href').substring(2),
34+
link: a.attr('href').startsWith('http') ? a.attr('href') : 'https://jwb.bnu.edu.cn' + a.attr('href').slice(2),
3535
pubDate: parseDate(e.find('span.fr.text-muted').text(), 'YYYY-MM-DD'),
3636
};
3737
});

lib/routes/bsky/posts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { parseDate } from '@/utils/parse-date';
55
import { resolveHandle, getProfile, getAuthorFeed } from './utils';
66
import { art } from '@/utils/render';
77
import path from 'node:path';
8-
import querystring from 'querystring';
8+
import querystring from 'node:querystring';
99

1010
export const route: Route = {
1111
path: '/profile/:handle/:routeParams?',

lib/routes/caixin/blog.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async function handler(ctx) {
3838
const $ = load(response);
3939
const user = $('div.indexMainConri > script[type="text/javascript"]')
4040
.text()
41-
.substring('window.user = '.length + 1)
41+
.slice('window.user = '.length + 1)
4242
.split(';')[0]
4343
.replaceAll(/\s/g, '');
4444
const authorId = user.match(/id:"(\d+)"/)[1];

lib/routes/caixin/utils-fulltext.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import crypto from 'crypto';
1+
import crypto from 'node:crypto';
22
import { hextob64, KJUR } from 'jsrsasign';
33
import ofetch from '@/utils/ofetch';
44
import { config } from '@/config';

lib/routes/cas/genetics/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function handler(ctx) {
2222

2323
let items;
2424

25-
if (path.substring(0, 3) === 'edu') {
25+
if (path.slice(0, 3) === 'edu') {
2626
items = $('li.box-s.h16')
2727
.toArray()
2828
.map((item) => {
@@ -35,7 +35,7 @@ async function handler(ctx) {
3535
pubDate: parseDate(date.text(), 'YYYY-MM-DD'),
3636
};
3737
});
38-
} else if (path.substring(0, 4) === 'dqyd') {
38+
} else if (path.slice(0, 4) === 'dqyd') {
3939
items = $('div.list-tab ul li')
4040
.toArray()
4141
.map((item) => {

lib/routes/cebbank/all.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ async function handler(ctx) {
5555
exrt: c('td:nth-child(4)').text(),
5656
mc: c('td:nth-child(5)').text(),
5757
}),
58-
pubDate: timezone(parseDate($('#t_id span').text().substring(5), 'YYYY-MM-DD HH:mm', true), 8),
59-
guid: md5(c('td:nth-child(1)').text() + $('#t_id span').text().substring(5)),
58+
pubDate: timezone(parseDate($('#t_id span').text().slice(5), 'YYYY-MM-DD HH:mm', true), 8),
59+
guid: md5(c('td:nth-child(1)').text() + $('#t_id span').text().slice(5)),
6060
};
6161
})
6262
.get();
@@ -70,7 +70,7 @@ async function handler(ctx) {
7070

7171
ctx.set('json', {
7272
...ret,
73-
pubDate: timezone(parseDate($('#t_id span').text().substring(5), 'YYYY-MM-DD HH:mm', true), 0),
73+
pubDate: timezone(parseDate($('#t_id span').text().slice(5), 'YYYY-MM-DD HH:mm', true), 0),
7474
});
7575
return ret;
7676
}

lib/routes/cib/whpj.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import cache from '@/utils/cache';
33
import got from '@/utils/got';
44
import { load } from 'cheerio';
55
import { parseDate } from '@/utils/parse-date';
6-
import https from 'https';
7-
import crypto from 'crypto';
6+
import https from 'node:https';
7+
import crypto from 'node:crypto';
88
import { config } from '@/config';
99

1010
export const route: Route = {
@@ -47,7 +47,7 @@ async function handler(ctx) {
4747
const $ = load(response.data);
4848
let date = $('div.main-body').find('div.labe_text').text();
4949
date = date.split('\n\t')[1].replace('日期:', '').trim();
50-
date = date.substring(0, 11) + date.substring(15);
50+
date = date.slice(0, 11) + date.slice(15);
5151

5252
const link = 'https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery/list?_search=false&dataSet.rows=80&dataSet.page=1&dataSet.sidx=&dataSet.sord=asc';
5353
const data = await cache.tryGet(

lib/routes/ciweimao/chapter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async function handler(ctx) {
3939
const $ = load(response);
4040

4141
const firstChapterUrl = $('ul.catalogue-list li a').attr('href');
42-
const firstChapterId = firstChapterUrl.substring(firstChapterUrl.lastIndexOf('/') + 1);
42+
const firstChapterId = firstChapterUrl.slice(firstChapterUrl.lastIndexOf('/') + 1);
4343

4444
const { data: chapters } = await got(`${chapterUrl}/chapter/${id}/${firstChapterId}`);
4545
const $c = load(chapters);

lib/routes/clickme/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async function handler(ctx) {
2727
const grouping = ctx.req.param('grouping') === 'tag' ? 'tag' : 'category';
2828
const name = ctx.req.param('name');
2929

30-
const url = `https://${site ? 'r18.' : ''}clickme.net/${grouping.substring(0, 1)}/${encodeURIComponent(name)}`;
30+
const url = `https://${site ? 'r18.' : ''}clickme.net/${grouping.slice(0, 1)}/${encodeURIComponent(name)}`;
3131

3232
const { data: response } = await got.post('https://api.clickme.net/article/list', {
3333
headers: {

lib/routes/cntv/column.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const route: Route = {
4141

4242
async function handler(ctx) {
4343
const id = ctx.req.param('column');
44-
const limit = isNaN(Number.parseInt(ctx.req.query('limit'))) ? 25 : Number.parseInt(ctx.req.query('limit'));
44+
const limit = Number.isNaN(Number.parseInt(ctx.req.query('limit'))) ? 25 : Number.parseInt(ctx.req.query('limit'));
4545

4646
const response = await got({
4747
method: 'get',

lib/routes/comicskingdom/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async function handler(ctx) {
6363
image,
6464
});
6565
// Pull the date out of the URL
66-
const pubDate = parseDate(link.substring(link.lastIndexOf('/') + 1), 'YYYY-MM-DD');
66+
const pubDate = parseDate(link.slice(link.lastIndexOf('/') + 1), 'YYYY-MM-DD');
6767

6868
return {
6969
title,

lib/routes/creative-comic/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ const decrypt = (encrypted, secrets) =>
6767
const token2Key = (token) => {
6868
const t = CryptoJS.SHA512(token).toString();
6969
return {
70-
key: t.substring(0, 64),
71-
iv: t.substring(30, 62), // t.substr(30, 32)
70+
key: t.slice(0, 64),
71+
iv: t.slice(30, 62), // t.substr(30, 32)
7272
};
7373
};
7474

lib/routes/csu/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { inflateSync } from 'zlib';
1+
import { inflateSync } from 'node:zlib';
22

33
const unzip = (b64Data) => {
44
const strData = Buffer.from(b64Data, 'base64').toString('binary');

lib/routes/dnaindia/category.ts

Whitespace-only changes.

lib/routes/dockerhub/tag.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function handler(ctx) {
3030
const namespace = `${owner}/${image}`;
3131
const link = `https://hub.docker.com/r/${namespace}`;
3232

33-
const pageSize = isNaN(Number.parseInt(limits)) ? 10 : Number.parseInt(limits);
33+
const pageSize = Number.isNaN(Number.parseInt(limits)) ? 10 : Number.parseInt(limits);
3434

3535
const data = await got.get(`https://hub.docker.com/v2/repositories/${namespace}/tags/?page_size=${pageSize}`);
3636
const metadata = await got.get(`https://hub.docker.com/v2/repositories/${namespace}/`);

lib/routes/douban/people/status.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Route, ViewType } from '@/types';
22
import cache from '@/utils/cache';
3-
import querystring from 'querystring';
3+
import querystring from 'node:querystring';
44
import got from '@/utils/got';
55
import { fallback, queryToBoolean, queryToInteger } from '@/utils/readable-social';
66
import { config } from '@/config';

lib/routes/douban/people/wish.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Route } from '@/types';
22
import cache from '@/utils/cache';
3-
import querystring from 'querystring';
3+
import querystring from 'node:querystring';
44
import { load } from 'cheerio';
55
import got from '@/utils/got';
66
import { config } from '@/config';

lib/routes/douyin/hashtag.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const route: Route = {
3434

3535
async function handler(ctx) {
3636
const cid = ctx.req.param('cid');
37-
if (isNaN(cid)) {
37+
if (Number.isNaN(cid)) {
3838
throw new InvalidParameterError('Invalid tag ID. Tag ID should be a number.');
3939
}
4040
const routeParams = Object.fromEntries(new URLSearchParams(ctx.req.param('routeParams')));

lib/routes/douyin/live.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const route: Route = {
3131

3232
async function handler(ctx) {
3333
const rid = ctx.req.param('rid');
34-
if (isNaN(rid)) {
34+
if (Number.isNaN(rid)) {
3535
throw new InvalidParameterError('Invalid room ID. Room ID should be a number.');
3636
}
3737

lib/routes/dw/rss.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const route: Route = {
2323
handler,
2424
description: `
2525
For a full list of RSS Feed Channels in English, please refer to [DW RSS Feeds](https://corporate.dw.com/en/rss-feeds/a-68693346).
26-
RSS Feed Channels in other languages are also available, for example: \`rss-chi-all\` renders the RSS feed in Chinese and \`rss-de-all\` for the RSS Feed in German
26+
RSS Feed Channels in other languages are also available, for example: \`rss-chi-all\` renders the RSS feed in Chinese and \`rss-de-all\` for the RSS Feed in German
2727
`,
2828
};
2929

@@ -48,7 +48,7 @@ async function handler(ctx) {
4848
const link = new URL(item.link);
4949
link.search = '';
5050
item.link = link.href;
51-
item.type = link.pathname.substring(link.pathname.lastIndexOf('/') + 1).startsWith('live-') ? 'liveblog' : 'article'; // dw rss feed only includes liveblogs and articles
51+
item.type = link.pathname.slice(link.pathname.lastIndexOf('/') + 1).startsWith('live-') ? 'liveblog' : 'article'; // dw rss feed only includes liveblogs and articles
5252
return item;
5353
})
5454
);

0 commit comments

Comments
 (0)