style: replace .contents().remove() with .empty()

This commit is contained in:
Tony
2026-10-23 06:11:54 +08:00
parent 0b037cff3e
commit 7aaf94705e
4 changed files with 3 additions and 7 deletions
-4
View File
@@ -606,10 +606,6 @@
"selector": "CallExpression[callee.property.name='clone'][arguments.length=0]:not([callee.object.name=/^(request|response|req|res)$/])",
"message": "Usage of .clone() in cheerio is not allowed."
},
{
"selector": "CallExpression[callee.property.name='empty'][arguments.length=0]",
"message": "Usage of .empty() in cheerio is not allowed."
},
{
"selector": "CallExpression[callee.property.name='toArray'] MemberExpression[object.callee.property.name='map']",
"message": "Use .toArray() before .map()."
+1 -1
View File
@@ -35,7 +35,7 @@ const parseArticle = async (link: string, excerpt?: string): Promise<Pick<DataIt
content.find('.share-container, .addthis_tool').remove();
// The site's YouTube embeds leak their attributes into the iframe as text.
content.find('iframe').contents().remove();
content.find('iframe').empty();
content.find('.wp-caption-text').each((_, el) => {
$(el).replaceWith($('<figcaption>').append($(el).contents()));
});
+1 -1
View File
@@ -95,7 +95,7 @@ async function handler(ctx) {
const video = content(element);
const poster = copyNodes(video.find('.sdc-site-video__poster img').first());
const caption = copyNodes(video.find('.sdc-site-video__caption').first());
video.contents().remove();
video.empty();
video.append(poster, caption);
});
+1 -1
View File
@@ -103,6 +103,6 @@ function copyContent<T extends AnyNode>(selection: Cheerio<T>, $: CheerioAPI): C
return $(nodes);
}
function clearContent<T extends AnyNode>(selection: Cheerio<T>): Cheerio<T> {
selection.contents().remove();
selection.empty();
return selection;
}