Skip to content

Commit a98de2e

Browse files
committed
refactor: use arrow function
1 parent 3b0d76a commit a98de2e

83 files changed

Lines changed: 290 additions & 287 deletions

File tree

Some content is hidden

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

.oxlintrc.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,22 @@
360360
{
361361
"selector": "CallExpression[callee.name=\"load\"] AwaitExpression > CallExpression",
362362
"message": "Do not use await in call expressions. Extract the result into a variable first."
363+
},
364+
{
365+
"selector": "Identifier[name=\"_ctx\"]",
366+
"message": "Usage of `_ctx` is not allowed."
367+
},
368+
{
369+
"selector": "CallExpression[callee.property.name=\"each\"] > FunctionExpression",
370+
"message": "Use an arrow function instead."
371+
},
372+
{
373+
"selector": "CallExpression[callee.property.name=\"filter\"] > FunctionExpression",
374+
"message": "Use an arrow function instead."
375+
},
376+
{
377+
"selector": "CallExpression[callee.property.name=\"map\"] > FunctionExpression",
378+
"message": "Use an arrow function instead."
363379
}
364380
],
365381

lib/middleware/anti-hotlink.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ const replaceUrl = (template?: string, url?: string) => {
5959
};
6060

6161
const replaceUrls = ($: CheerioAPI, selector: string, template: string, attribute = 'src') => {
62-
$(selector).each(function () {
63-
const oldSrc = $(this).attr(attribute);
62+
$(selector).each((_, el) => {
63+
const oldSrc = $(el).attr(attribute);
6464
if (oldSrc) {
6565
const url = parseUrl(oldSrc);
6666
if (url && url.protocol !== 'data:') {
6767
// Cheerio will do the right thing to prohibit XSS.
68-
$(this).attr(attribute, interpolate(template, url));
68+
$(el).attr(attribute, interpolate(template, url));
6969
}
7070
}
7171
});

lib/routes/163/exclusive.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ async function handler(ctx) {
163163

164164
content('.m-linkCard').remove();
165165

166-
content('.m-photo').each(function () {
167-
content(this).html(
166+
content('.m-photo').each((_, el) => {
167+
content(el).html(
168168
renderExclusiveDescription({
169-
image: content(this).find('img').attr('data-src'),
169+
image: content(el).find('img').attr('data-src'),
170170
})
171171
);
172172
});

lib/routes/163/news/rank.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ async function handler(ctx) {
167167
const content = load(detailResponse.data);
168168

169169
content('.bot_word, .js-open-app, .s-img').remove();
170-
content('video').each(function () {
171-
content(this).attr('src', content(this).attr('data-src'));
170+
content('video').each((_, el) => {
171+
content(el).attr('src', content(el).attr('data-src'));
172172
});
173173
content('.article-body .image-lazy').each((_, elem) => {
174174
elem.attribs.src = elem.attribs['data-src'] ?? elem.attribs.src;

lib/routes/2048/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ async function handler(ctx) {
133133

134134
content('.ads, .tips').remove();
135135

136-
content('ignore_js_op').each(function () {
137-
const img = content(this).find('img');
136+
content('ignore_js_op').each((_, el) => {
137+
const img = content(el).find('img');
138138
const originalSrc = img.attr('data-original');
139139
const fallbackSrc = img.attr('src');
140140
// 判断是否有 data-original 属性,若有则使用其值,否则使用 src 属性值
141141
const imgSrc = originalSrc || fallbackSrc;
142-
content(this).replaceWith(`<img src="${imgSrc}">`);
142+
content(el).replaceWith(`<img src="${imgSrc}">`);
143143
});
144144

145145
item.author = content('.fl.black').first().text();
@@ -174,8 +174,8 @@ async function handler(ctx) {
174174
}
175175
}
176176

177-
content('.showhide img').each(function () {
178-
readTpc.append(`<br><img style="max-width: 100%;" src="${content(this).attr('src')}">`);
177+
content('.showhide img').each((_, el) => {
178+
readTpc.append(`<br><img style="max-width: 100%;" src="${content(el).attr('src')}">`);
179179
});
180180

181181
item.description = readTpc.html();

lib/routes/8264/list.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ async function handler(ctx) {
129129

130130
const pubDate = content('span.pub-time').text() || content('span.fby span').first().prop('title') || content('span.fby').first().text().split('发表于').pop().trim();
131131

132-
content('img').each(function () {
133-
content(this).replaceWith(
132+
content('img').each((_, el) => {
133+
content(el).replaceWith(
134134
renderToString(
135135
<figure>
136-
<img src={content(this).prop('file')} alt={content(this).prop('alt')} />
136+
<img src={content(el).prop('file')} alt={content(el).prop('alt')} />
137137
</figure>
138138
)
139139
);

lib/routes/abc/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ async function handler(ctx) {
105105

106106
content('#body *, div[data-component="FeatureMedia"]')
107107
.children()
108-
.each(function () {
109-
const element = content(this);
108+
.each((_, el) => {
109+
const element = content(el);
110110
if (element.prop('tagName').toLowerCase() === 'figure') {
111111
element.replaceWith(
112112
renderDescription({

lib/routes/abskoop/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ async function handler(ctx) {
4848
$detail('article.post-content').find('.lwptoc').remove();
4949
$detail('article.post-content').find('#related_posts').remove();
5050
$detail('article.post-content').find('.entry-copyright').remove();
51-
$detail('article.post-content img').each(function () {
52-
$detail(this).replaceWith(`<img src=https:${$detail(this).attr('src')}>`);
51+
$detail('article.post-content img').each((_, el) => {
52+
$detail(el).replaceWith(`<img src=https:${$detail(el).attr('src')}>`);
5353
});
5454
item.description = $detail('article.post-content').html();
5555
return item;

lib/routes/android/platform-tools-releases.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ async function handler() {
5353
const title = item.attr('data-text');
5454

5555
let description = '';
56-
item.nextUntil('h4').each(function () {
57-
description += $(this).html();
56+
item.nextUntil('h4').each((_, el) => {
57+
description += $(el).html();
5858
});
5959

6060
return {

lib/routes/aqara/post.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ async function handler(ctx) {
5252

5353
// To handle lazy-loaded images.
5454

55-
content('figure').each(function () {
56-
const image = content(this).find('img');
55+
content('figure').each((_, el) => {
56+
const image = content(el).find('img');
5757
const src = (image.prop('data-actualsrc') ?? image.prop('data-original') ?? image.prop('src')).replace(/(-\d+x\d+)/, '');
5858
const width = image.prop('data-rawwidth') ?? image.prop('width');
5959
const height = image.prop('data-rawheight') ?? image.prop('height');
6060

61-
content(this).replaceWith(
61+
content(el).replaceWith(
6262
renderToString(
6363
<figure>
6464
<img src={src} width={width} height={height} />

0 commit comments

Comments
 (0)