Skip to content

Commit

Permalink
style(eslint): add no-implicit-coercion rule (DIYgod#8175)
Browse files Browse the repository at this point in the history
* refactor: add no-implicit-coercion rule for ESLint

* fix: errors from deepscan

* fix: errors from deepscan

* fix: errors from deepscan

* fix: errors from deepscan

* fix: errors from deepscan

* Update docs/en/joinus/quick-start.md

Co-authored-by: Sukka <[email protected]>

* Update docs/joinus/quick-start.md

Co-authored-by: Sukka <[email protected]>

* Update lib/routes/av01/tag.js

Co-authored-by: Sukka <[email protected]>

* Update lib/routes/gov/taiwan/mnd.js

Co-authored-by: Sukka <[email protected]>

* Update lib/routes/ps/product.js

Co-authored-by: Sukka <[email protected]>

* refactor: minify html string

Co-authored-by: Sukka <[email protected]>
  • Loading branch information
libook and SukkaW authored Sep 15, 2021
1 parent a763546 commit d77a039
Show file tree
Hide file tree
Showing 153 changed files with 338 additions and 269 deletions.
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
"no-multi-str": 2,
"comma-spacing": 2,
"comma-style": 2,
"no-implicit-coercion": [
"error",
{
"boolean": false,
"number": false,
"string": false,
"disallowTemplateShorthand": true
}
],
"func-call-spacing": 2,
"keyword-spacing": 2,
"linebreak-style": 2,
Expand Down
6 changes: 3 additions & 3 deletions assets/radar-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -2183,7 +2183,7 @@
docs: 'https://docs.rsshub.app/multimedia.html#onejav',
source: ['/:type', '/:type/:key', '/:type/:key/:morekey'],
target: (params, url, document) => {
const itype = params.morekey === undefined ? `${params.type}` : params.type === 'tag' ? 'tag' : 'day';
const itype = params.morekey === undefined ? params.type : params.type === 'tag' ? 'tag' : 'day';
let ikey = `${itype === 'day' ? params.type : ''}${params.key || ''}${itype === 'tag' && params.morekey !== undefined ? '%2F' : ''}${params.morekey || ''}`;
if (ikey === '' && itype === 'tag') {
ikey = document.querySelector('div.thumbnail.is-inline > a').getAttribute('href').replace('/tag/', '').replace('/', '%2F');
Expand Down Expand Up @@ -2221,7 +2221,7 @@
docs: 'https://docs.rsshub.app/multimedia.html#141jav',
source: ['/:type', '/:type/:key', '/:type/:key/:morekey'],
target: (params, url, document) => {
const itype = params.morekey === undefined ? `${params.type}` : params.type === 'tag' ? 'tag' : 'day';
const itype = params.morekey === undefined ? params.type : params.type === 'tag' ? 'tag' : 'day';
let ikey = `${itype === 'day' ? params.type : ''}${params.key || ''}${itype === 'tag' && params.morekey !== undefined ? '%2F' : ''}${params.morekey || ''}`;
if (ikey === '' && itype === 'tag') {
ikey = document.querySelector('div.thumbnail.is-inline > a').getAttribute('href').replace('/tag/', '').replace('/', '%2F');
Expand Down Expand Up @@ -2259,7 +2259,7 @@
docs: 'https://docs.rsshub.app/multimedia.html#141ppv',
source: ['/:type', '/:type/:key', '/:type/:key/:morekey'],
target: (params, url, document) => {
const itype = params.morekey === undefined ? `${params.type}` : params.type === 'tag' ? 'tag' : 'day';
const itype = params.morekey === undefined ? params.type : params.type === 'tag' ? 'tag' : 'day';
let ikey = `${itype === 'day' ? params.type : ''}${params.key || ''}${itype === 'tag' && params.morekey !== undefined ? '%2F' : ''}${params.morekey || ''}`;
if (ikey === '' && itype === 'tag') {
ikey = document.querySelector('div.thumbnail.is-inline > a').getAttribute('href').replace('/tag/', '').replace('/', '%2F');
Expand Down
2 changes: 1 addition & 1 deletion docs/en/joinus/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Create a new js script in [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/m
list
.map((index, item) => {
item = $(item);
itemPicUrl = `${item.find('a.cover').attr('style')}`.replace('background-image:url(', '').replace(')', '');
itemPicUrl = item.find('a.cover').attr('style').replace('background-image:url(', '').replace(')', '');
return {
title: item.find('.title a').first().text(),
description: `作者:${item.find('.usr-pic a').last().text()}<br>描述:${item.find('.content p').text()}<br><img src="${itemPicUrl}">`,
Expand Down
2 changes: 1 addition & 1 deletion docs/joinus/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ sidebar: auto
list
.map((index, item) => {
item = $(item);
itemPicUrl = `${item.find('a.cover').attr('style')}`.replace('background-image:url(', '').replace(')', '');
itemPicUrl = item.find('a.cover').attr('style').replace('background-image:url(', '').replace(')', '');
return {
title: item.find('.title a').first().text(),
description: `作者:${item.find('.usr-pic a').last().text()}<br>描述:${item.find('.content p').text()}<br><img src="${itemPicUrl}">`,
Expand Down
2 changes: 1 addition & 1 deletion lib/middleware/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = async (ctx, next) => {
logger.info(`${ctx.url}, user IP: ${ctx.ips[0] || ctx.ip}`);
ctx.set(headers);
ctx.set({
'Access-Control-Allow-Origin': `${config.allowOrigin || ctx.host}`,
'Access-Control-Allow-Origin': config.allowOrigin || ctx.host,
});

await next();
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/1point3acres/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = async (ctx) => {
const items = await Promise.all(
data.map(async (item) => {
const result = {
title: `${item.subject}`,
title: item.subject,
description: `${item.summary}...<br><br><small>作者 ${item.author} · 回复 ${item.replies} · 查看 ${item.views}</small>`,
link: `https://instant.1point3acres.com/thread/${item.tid}`,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/36kr/motif.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ module.exports = async (ctx) => {
})
)
),
description: `${motifInfo.categoryTitle}`,
description: motifInfo.categoryTitle,
};
};
2 changes: 1 addition & 1 deletion lib/routes/aliyun/developer/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: `阿里云开发者社区-${title}`,
link,
description: `${desc}`,
description: desc,
item:
list &&
list
Expand Down
15 changes: 14 additions & 1 deletion lib/routes/asahi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,20 @@ module.exports = async (ctx) => {
const category = ctx.params.category || '';

const rootUrl = 'https://www.asahi.com';
const currentUrl = `${rootUrl}${genre ? `${category ? `${category in categories ? categories[category] : `/${genre}/list/${category}.html`}` : `/${genre}`}` : '/news/history.html'}`;
let currentUrl;
if (genre) {
if (category) {
if (category in categories) {
currentUrl = `${rootUrl}${categories[category]}`;
} else {
currentUrl = `${rootUrl}/${genre}/list/${category}.html`;
}
} else {
currentUrl = `${rootUrl}/${genre}`;
}
} else {
currentUrl = `${rootUrl}${'/news/history.html'}`;
}

const response = await got({
method: 'get',
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/av01/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = async (ctx) => {
list
.map((index, item) => {
item = $(item);
const itemPicUrl = `${item.find('img').attr('data-src')}`;
const itemPicUrl = item.find('img').attr('data-src');
return {
title: item.find('span.video-title.title-truncate.m-t-5').text(),
description: `翻译${item.find('div.video-added.title-truncate').text()}<br><img src="${itemPicUrl}">`,
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/av01/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = async (ctx) => {
list
.map((index, item) => {
item = $(item);
const itemPicUrl = `${item.find('img').attr('data-src')}`;
const itemPicUrl = item.find('img').attr('data-src');
return {
title: item.find('span.video-title.title-truncate.m-t-5').text(),
description: `翻译${item.find('div.video-added.title-truncate').text()}<br><img src="${itemPicUrl}">`,
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/avgle/videos.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = async (ctx) => {
});
const returnData = response.data.response.videos;

const compact_number = (number) => `${Intl.NumberFormat('en-US', { notation: 'compact', compactDisplay: 'short' }).format(number)}`;
const compact_number = (number) => String(Intl.NumberFormat('en-US', { notation: 'compact', compactDisplay: 'short' }).format(number));
const like = (item) => `[${Math.round((item.likes / (item.likes + item.dislikes)) * 100)}%/${compact_number(item.likes + item.dislikes)}/${compact_number(item.viewnumber)}]`;

ctx.state.data = {
Expand All @@ -37,7 +37,7 @@ module.exports = async (ctx) => {
description: `Avgle ${order}/${time}`,
item: returnData.map((item) => ({
title: like(item) + item.title,
description: `${item.preview_video_url ? `<video controls loop ${item.preview_url ? `poster="${item.preview_url}"` : ''} src="${item.preview_video_url}" />` : ''}`,
description: item.preview_video_url ? `<video controls loop ${item.preview_url ? `poster="${item.preview_url}"` : ''} src="${item.preview_video_url}" />` : '',
pubDate: new Date(item.addtime * 1000).toUTCString(),
link: item.video_url,
category: item.keyword.split(' '),
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/axis-studios/work.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ module.exports = async (ctx) => {
video = `<iframe id="ytplayer" type="text/html" width="640" height="360" src='https://youtube.com/embed/${articledata[index].youtube}' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe><br>`;
}
return {
title: `${articledata[index].title}`,
title: articledata[index].title,
description: `${video}+${articledata[index].describe}`,
link: `${articledata[index].link}`,
link: articledata[index].link,
};
}),
};
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/bangumi/calendar/today.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = async (ctx) => {

const todayList = list.filter((l) => l.weekday.id % 7 === day)[0];

const todayBgmId = todayList.items.map((t) => `${t.id}`);
const todayBgmId = todayList.items.map((t) => t.id);
const images = todayList.items.reduce((p, c) => {
p[c.id] = (c.images || {}).large;
return p;
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/bangumi/group/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = async (ctx) => {
const title = 'Bangumi - ' + $('.SecondaryNavTitle').text();

ctx.state.data = {
title: `${title}`,
title,
link,
item: $('.topic_list .topic')
.map((_, elem) => ({
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/bangumi/subject/ep.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = async (subjectID) => {
});

return {
title: `${epsInfo.name_cn}`,
title: epsInfo.name_cn,
link: `https://bgm.tv/subject/${subjectID}`,
description: epsInfo.summary,
item: activeEps.reverse().map((e) => ({
Expand Down
8 changes: 4 additions & 4 deletions lib/routes/behance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ module.exports = async (ctx) => {
);
ctx.state.data = {
title: `${data.profile.owner.first_name} ${data.profile.owner.last_name}'s Work`,
link: `${data.profile.owner.url}`,
link: data.profile.owner.url,
item: list.map((item, index) => {
if (type !== 'projects') {
item = item.project;
}
return {
title: `${item.name}`,
description: `${articledata[index].content}`,
link: `${item.url}`,
title: item.name,
description: articledata[index].content,
link: item.url,
pubDate: dayjs.unix(item.published_on).format(),
};
}),
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/bilibili/blackboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ module.exports = async (ctx) => {
!index || item.name !== array[index - 1].name
)
.map((item) => ({
title: `${item.name}`,
title: item.name,
description: `${item.name}<br> ${item.desc}`,
pubDate: new Date(item.ctime.replace(' ', 'T') + '+08:00').toUTCString(),
link: `${item.pc_url}`,
link: item.pc_url,
})),
};
};
12 changes: 8 additions & 4 deletions lib/routes/bilibili/dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,14 @@ module.exports = async (ctx) => {

return {
title: getTitle(data),
description: `${data_content || getDes(data)}${
origin && getOriginName(origin) ? `<br><br>//转发自: @${getOriginName(origin)}: ${getOriginTitle(origin.item || origin)}${getDes(origin.item || origin)}` : `${getOriginDes(origin)}`
}<br>${getUrl(data)}${getUrl(origin)}${getIframe(data)}${getIframe(origin)}${imgHTML ? `<br>${imgHTML}` : ''}${videoHTML ? `<br>${videoHTML}` : ''}`,
pubDate: new Date(item.desc.timestamp * 1000).toUTCString(),
description: (() => {
const description = data_content || getDes(data);
const originName = origin && getOriginName(origin) ? `<br><br>//转发自: @${getOriginName(origin)}: ${getOriginTitle(origin.item || origin)}${getDes(origin.item || origin)}` : getOriginDes(origin);
const imgHTMLSource = imgHTML ? `<br>${imgHTML}` : '';
const videoHTMLSource = videoHTML ? `<br>${videoHTML}` : '';
return `${description}${originName}<br>${getUrl(data)}${getUrl(origin)}${getIframe(data)}${getIframe(origin)}${imgHTMLSource}${videoHTMLSource}`;
})(),
pubDate: new Date(item.desc.timestamp * 1000),
link,
};
}),
Expand Down
11 changes: 8 additions & 3 deletions lib/routes/bilibili/followings_dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,14 @@ module.exports = async (ctx) => {
return {
title: getTitle(data),
author,
description: `${parsed.new_desc || data_content || getDes(data)}${
origin && getOriginName(origin) ? `<br><br>//转发自: @${getOriginName(origin)}: ${getOriginTitle(origin.item || origin)}${getDes(origin.item || origin)}` : `${getOriginDes(origin)}`
}${getIframe(data)}${getIframe(origin)}${imgHTML ? `<br>${imgHTML}` : ''}${videoHTML ? `<br>${videoHTML}` : ''}`,
description: (() => {
const description = parsed.new_desc || data_content || getDes(data);
const originName = origin && getOriginName(origin) ? `<br><br>//转发自: @${getOriginName(origin)}: ${getOriginTitle(origin.item || origin)}${getDes(origin.item || origin)}` : getOriginDes(origin);
const imgHTMLSource = imgHTML ? `<br>${imgHTML}` : '';
const videoHTMLSource = videoHTML ? `<br>${videoHTML}` : '';

return `${description}${originName}${getIframe(data)}${getIframe(origin)}${imgHTMLSource}${videoHTMLSource}`;
})(),
pubDate: new Date(item.desc.timestamp * 1000).toUTCString(),
link,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/bilibili/liveArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = async (ctx) => {

ctx.state.data = {
title: `哔哩哔哩直播-${parentTitle}·${areaTitle}分区-${orderTitle}`,
link: `${areaLink}`,
link: areaLink,
description: `哔哩哔哩直播-${parentTitle}·${areaTitle}分区-${orderTitle}`,
item: data.map((item) => ({
title: `${item.uname} ${item.title}`,
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/bilibili/partion-ranking.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = async (ctx) => {
let item = hotlist[i];

item = {
title: `${item.title}`,
title: item.title,
description: `${item.description}${!disableEmbed ? `<br><br>${utils.iframe(item.id)}` : ''}<br><img src="https:${item.pic}"><br/>Tags:${item.tag}`,
pubDate: new Date(item.pubdate).toUTCString(),
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.id}`,
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/bilibili/partion.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = async (ctx) => {
item:
list &&
list.map((item) => ({
title: `${item.title}`,
title: item.title,
description: `${item.desc}${!disableEmbed ? `<br><br>${utils.iframe(item.aid)}` : ''}<br><img src="${item.pic}">`,
pubDate: new Date(item.pubdate * 1000).toUTCString(),
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
Expand Down
7 changes: 6 additions & 1 deletion lib/routes/bilibili/weekly_recommend.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ module.exports = async (ctx) => {
description: 'B站每周必看',
item: data.map((item) => ({
title: item.title,
description: `${weekly_name} ${item.title}<br>${item.rcmd_reason}<br>${!disableEmbed ? `${utils.iframe(item.param)}` : ''}<img src="${item.cover}">`,
// description: `${weekly_name} ${item.title}<br>${item.rcmd_reason}<br>${!disableEmbed ? `${utils.iframe(item.param)}` : ''}<img src="${item.cover}">`,
description: `
${weekly_name} ${item.title}<br>
${item.rcmd_reason}<br>
${!disableEmbed ? utils.iframe(item.param) : ''}<img src="${item.cover}">
`,
link: weekly_number > 60 && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.param}`,
})),
};
Expand Down
6 changes: 3 additions & 3 deletions lib/routes/bjnews/epaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ module.exports = async (ctx) => {
title: `新京报电子报|${cat}叠`,
link: `http://epaper.bjnews.com.cn/html/${year}-${month}/${day}/node_1.htm`,
item: list.map((item, index) => ({
title: `${articledata[index].title}`,
description: `${articledata[index].description}`,
link: `${articledata[index].link}`,
title: articledata[index].title,
description: articledata[index].description,
link: articledata[index].link,
})),
};
};
8 changes: 4 additions & 4 deletions lib/routes/blow-studio/work.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = async (ctx) => {
const imgstyle = `style="max-width: 650px; height: auto; object-fit: contain; flex: 0 0 auto;"`;

content += `<iframe ${videostyle} src='https://player.vimeo.com/video/${articledata[index].mainvideo}' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe><br>`;
content += `${articledata[index].describe}`;
content += articledata[index].describe;

if (articledata[index].images) {
for (let p = 0; p < articledata[index].images.length; p++) {
Expand All @@ -62,9 +62,9 @@ module.exports = async (ctx) => {
}

return {
title: `${articledata[index].title}`,
description: `${content}`,
link: `${articledata[index].link}`,
title: articledata[index].title,
description: content,
link: articledata[index].link,
};
}),
};
Expand Down
6 changes: 3 additions & 3 deletions lib/routes/blur-studio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ module.exports = async (ctx) => {
}

return {
title: `${articledata[index].title}`,
description: `${content}`,
link: `${articledata[index].link}`,
title: articledata[index].title,
description: content,
link: articledata[index].link,
};
}),
};
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/chinafile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = async (ctx) => {

url = $('link[rel="canonical"]').attr('href');

const pubDate = dayjs(`${item.pubDate.replace(' - ', ' ').replace('am', ' am').replace('pm', ' pm')}`).toISOString();
const pubDate = dayjs(item.pubDate.replace(' - ', ' ').replace('am', ' am').replace('pm', ' pm'));

return {
title: item.title,
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/coolapk/dyh.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: `酷安看看号-${targetTitle}`,
link: `https://www.coolapk.com/dyh/${dyhId}`,
description: `${feedDescription}`,
description: feedDescription,
item: out,
};
};
4 changes: 2 additions & 2 deletions lib/routes/coolapk/tuwen.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ module.exports = async (ctx) => {
const out = await Promise.all(data.map((item) => utils.parseDynamic(item, ctx)));

ctx.state.data = {
title: `${feedTitle}`,
title: feedTitle,
link: 'https://www.coolapk.com/',
description: `${feedTitle}`,
description: feedTitle,
item: out,
};
};
Loading

0 comments on commit d77a039

Please sign in to comment.