From d77a039f052badb45bdf31aa614a73d7cee40b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Li=20=28=E6=9D=8E=E4=B8=B9=E9=98=B3=29?= Date: Wed, 15 Sep 2021 21:22:11 +0800 Subject: [PATCH] style(eslint): add no-implicit-coercion rule (#8175) * 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 * Update docs/joinus/quick-start.md Co-authored-by: Sukka * Update lib/routes/av01/tag.js Co-authored-by: Sukka * Update lib/routes/gov/taiwan/mnd.js Co-authored-by: Sukka * Update lib/routes/ps/product.js Co-authored-by: Sukka * refactor: minify html string Co-authored-by: Sukka --- .eslintrc | 9 +++++++++ assets/radar-rules.js | 6 +++--- docs/en/joinus/quick-start.md | 2 +- docs/joinus/quick-start.md | 2 +- lib/middleware/header.js | 2 +- lib/routes/1point3acres/post.js | 2 +- lib/routes/36kr/motif.js | 2 +- lib/routes/aliyun/developer/group.js | 2 +- lib/routes/asahi/index.js | 15 ++++++++++++++- lib/routes/av01/actor.js | 2 +- lib/routes/av01/tag.js | 2 +- lib/routes/avgle/videos.js | 4 ++-- lib/routes/axis-studios/work.js | 4 ++-- lib/routes/bangumi/calendar/today.js | 2 +- lib/routes/bangumi/group/topic.js | 2 +- lib/routes/bangumi/subject/ep.js | 2 +- lib/routes/behance/index.js | 8 ++++---- lib/routes/bilibili/blackboard.js | 4 ++-- lib/routes/bilibili/dynamic.js | 12 ++++++++---- lib/routes/bilibili/followings_dynamic.js | 11 ++++++++--- lib/routes/bilibili/liveArea.js | 2 +- lib/routes/bilibili/partion-ranking.js | 2 +- lib/routes/bilibili/partion.js | 2 +- lib/routes/bilibili/weekly_recommend.js | 7 ++++++- lib/routes/bjnews/epaper.js | 6 +++--- lib/routes/blow-studio/work.js | 8 ++++---- lib/routes/blur-studio/index.js | 6 +++--- lib/routes/chinafile/index.js | 2 +- lib/routes/coolapk/dyh.js | 2 +- lib/routes/coolapk/tuwen.js | 4 ++-- lib/routes/coronavirus/sg-moh.js | 2 +- lib/routes/digic-pictures/index.js | 6 +++--- lib/routes/digitaling/article.js | 2 +- lib/routes/douban/channel/subject.js | 4 ++-- lib/routes/douban/channel/topic.js | 6 +++--- lib/routes/douban/explore.js | 2 +- lib/routes/douban/people/status.js | 11 ++++++++++- lib/routes/douban/people/wish.js | 2 +- lib/routes/dxy/vaccine.js | 11 ++++++++++- lib/routes/fanbox/conv.js | 2 +- lib/routes/galgame/hhgal.js | 4 ++-- lib/routes/github/starred_repos.js | 4 ++-- lib/routes/github/topic.js | 2 +- lib/routes/gov/moa/sjzxfb.js | 6 +++--- lib/routes/gov/province/jiangsu/getContent.js | 3 +-- lib/routes/gov/taiwan/mnd.js | 2 +- lib/routes/gracg/user.js | 2 +- lib/routes/guancha/index.js | 2 +- lib/routes/guancha/personalpage.js | 2 +- lib/routes/hinatazaka46/blog.js | 2 +- lib/routes/hkepc/index.js | 2 +- lib/routes/hket/index.js | 8 ++++---- lib/routes/huxiu/collection.js | 2 +- lib/routes/ieee/author.js | 2 +- lib/routes/imaijia/category.js | 2 +- lib/routes/jandan/pic.js | 4 ++-- lib/routes/japanpost/track.js | 2 +- lib/routes/jike/user.js | 2 +- lib/routes/jinritoutiao/keyword.js | 8 ++++---- lib/routes/juejin/utils.js | 2 +- lib/routes/keyakizaka46/blog.js | 2 +- lib/routes/kongfz/people.js | 2 +- lib/routes/latepost/index.js | 2 +- lib/routes/leetcode/check-us.js | 2 +- lib/routes/lfsyd/index.js | 2 +- lib/routes/lizhi/user.js | 2 +- lib/routes/mastodon/account_id.js | 4 ++-- lib/routes/mastodon/acct.js | 4 ++-- lib/routes/matataki/site/posts/favorite.js | 4 ++-- lib/routes/matataki/utils/matataki-utils.js | 6 +++--- lib/routes/meipai/user.js | 2 +- lib/routes/method-studios/index.js | 6 +++--- lib/routes/mi/golden.js | 2 +- lib/routes/miniflux/get_entries.js | 8 ++++---- lib/routes/miniflux/get_feeds.js | 4 ++-- lib/routes/mp4ba/index.js | 2 +- lib/routes/mp4er/index.js | 9 ++++++++- lib/routes/mpaypass/news.js | 2 +- lib/routes/natgeo/natgeo.js | 2 +- lib/routes/neea/index.js | 6 +++--- lib/routes/notefolio/index.js | 2 +- lib/routes/novel/ptwxz.js | 2 +- lib/routes/novel/wenxuemi.js | 2 +- lib/routes/parcel/hermesuk.js | 2 +- lib/routes/pcr/news-cn.js | 4 ++-- lib/routes/pediy/topic.js | 4 ++-- lib/routes/pgyer/app.js | 16 ++++++++-------- lib/routes/pianyuan/app.js | 2 +- lib/routes/pixiv/bookmarks.js | 2 +- lib/routes/pixiv/ranking.js | 2 +- lib/routes/popiask/tapechat_questions.js | 4 ++-- lib/routes/ps/product.js | 6 +++--- lib/routes/sakurazaka46/blog.js | 2 +- lib/routes/showroom/room.js | 4 ++-- lib/routes/shuhui/comics.js | 4 ++-- lib/routes/siren/index.js | 2 +- lib/routes/sketch/updates.js | 6 +++--- lib/routes/smzdm/keyword.js | 2 +- lib/routes/soul/hot.js | 2 +- lib/routes/soul/index.js | 2 +- lib/routes/ssmh/category.js | 4 ++-- lib/routes/ssmh/index.js | 4 ++-- lib/routes/sspai/activity.js | 8 ++++---- lib/routes/szse/inquire.js | 2 +- lib/routes/taptap/changelog.js | 2 +- lib/routes/tencent/video/playlist.js | 2 +- lib/routes/tencent/wechat/csm.js | 2 +- lib/routes/tencent/wechat/feeds.js | 2 +- .../tencent/wechat/miniprogram/devtools.js | 4 ++-- .../tencent/wechat/miniprogram/framework.js | 4 ++-- .../tencent/wechat/miniprogram/wxcloud.js | 4 ++-- lib/routes/tencent/wechat/mp.js | 19 +++++++++++++------ lib/routes/tencent/wechat/msgalbum.js | 8 ++++---- .../wechat/wechat-open/community/question.js | 2 +- lib/routes/thepaper/839studio/category.js | 2 +- lib/routes/tieba/post.js | 14 +++++++------- lib/routes/tingshuitz/dalian.js | 2 +- lib/routes/tingshuitz/wuhan.js | 2 +- lib/routes/tuicool/mags.js | 2 +- lib/routes/uisdc/zt.js | 2 +- lib/routes/unit-image/films.js | 6 +++--- lib/routes/universities/bjtu/gs/index.js | 2 +- lib/routes/universities/bupt/yz.js | 4 ++-- lib/routes/universities/hbut/cs.js | 2 +- lib/routes/universities/hbut/news.js | 2 +- lib/routes/universities/jnu/yw/index.js | 6 +++--- lib/routes/universities/nku/jwc/index.js | 2 +- lib/routes/universities/sctu/jwc/index.js | 2 +- lib/routes/universities/sustech/newshub-zh.js | 2 +- lib/routes/universities/szu/yz/index.js | 4 ++-- lib/routes/universities/ustc/jwc/index.js | 6 +++--- lib/routes/universities/wtu/index.js | 6 +++--- lib/routes/universities/zju/career/index.js | 4 ++-- lib/routes/universities/zju/grs/index.js | 4 ++-- lib/routes/universities/zju/physics/index.js | 4 ++-- lib/routes/universities/zzuli/campus/index.js | 2 +- lib/routes/universities/zzuli/yjsc/index.js | 2 +- lib/routes/vol/lastupdate.js | 4 +++- lib/routes/weatheralarm/index.js | 4 ++-- lib/routes/weibo/timeline.js | 6 +++--- lib/routes/wukong/user.js | 6 +++--- lib/routes/xiaohongshu/board.js | 6 +++--- lib/routes/xiaohongshu/user.js | 4 ++-- lib/routes/ximalaya/album.js | 4 ++-- lib/routes/xuangubao/subject.js | 2 +- lib/routes/yande.re/post_popular_recent.js | 2 +- lib/routes/zfrontier/board_postlist.js | 2 +- lib/routes/zfrontier/postlist.js | 2 +- lib/routes/zhihu/collection.js | 10 +++++----- lib/routes/zhihu/posts.js | 6 +++--- lib/routes/zyshow/index.js | 2 +- lib/utils/dateParser.js | 2 +- lib/utils/torrent.js | 2 +- 153 files changed, 338 insertions(+), 269 deletions(-) diff --git a/.eslintrc b/.eslintrc index 12251efa9d..8acfcf95b7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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, diff --git a/assets/radar-rules.js b/assets/radar-rules.js index aaadae7bfc..820356b393 100644 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -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'); @@ -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'); @@ -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'); diff --git a/docs/en/joinus/quick-start.md b/docs/en/joinus/quick-start.md index 042a21a4d4..baaf61cdc0 100644 --- a/docs/en/joinus/quick-start.md +++ b/docs/en/joinus/quick-start.md @@ -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()}
描述:${item.find('.content p').text()}
`, diff --git a/docs/joinus/quick-start.md b/docs/joinus/quick-start.md index e493c1f77d..31508baf92 100644 --- a/docs/joinus/quick-start.md +++ b/docs/joinus/quick-start.md @@ -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()}
描述:${item.find('.content p').text()}
`, diff --git a/lib/middleware/header.js b/lib/middleware/header.js index 92817583d5..2292ddbed4 100644 --- a/lib/middleware/header.js +++ b/lib/middleware/header.js @@ -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(); diff --git a/lib/routes/1point3acres/post.js b/lib/routes/1point3acres/post.js index 7b3ed5b8a8..3f85db70e6 100644 --- a/lib/routes/1point3acres/post.js +++ b/lib/routes/1point3acres/post.js @@ -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}...

作者 ${item.author} · 回复 ${item.replies} · 查看 ${item.views}`, link: `https://instant.1point3acres.com/thread/${item.tid}`, }; diff --git a/lib/routes/36kr/motif.js b/lib/routes/36kr/motif.js index a60a0062f1..eaeea1c4c0 100644 --- a/lib/routes/36kr/motif.js +++ b/lib/routes/36kr/motif.js @@ -30,6 +30,6 @@ module.exports = async (ctx) => { }) ) ), - description: `${motifInfo.categoryTitle}`, + description: motifInfo.categoryTitle, }; }; diff --git a/lib/routes/aliyun/developer/group.js b/lib/routes/aliyun/developer/group.js index 235824be2b..940cb23e39 100644 --- a/lib/routes/aliyun/developer/group.js +++ b/lib/routes/aliyun/developer/group.js @@ -28,7 +28,7 @@ module.exports = async (ctx) => { ctx.state.data = { title: `阿里云开发者社区-${title}`, link, - description: `${desc}`, + description: desc, item: list && list diff --git a/lib/routes/asahi/index.js b/lib/routes/asahi/index.js index 7b65c638eb..da21e0d816 100644 --- a/lib/routes/asahi/index.js +++ b/lib/routes/asahi/index.js @@ -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', diff --git a/lib/routes/av01/actor.js b/lib/routes/av01/actor.js index de5d90270e..d5530a0f06 100644 --- a/lib/routes/av01/actor.js +++ b/lib/routes/av01/actor.js @@ -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()}
`, diff --git a/lib/routes/av01/tag.js b/lib/routes/av01/tag.js index 981300be8d..bbea8663d4 100644 --- a/lib/routes/av01/tag.js +++ b/lib/routes/av01/tag.js @@ -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()}
`, diff --git a/lib/routes/avgle/videos.js b/lib/routes/avgle/videos.js index 3ca77d83b5..3d08e3cc18 100644 --- a/lib/routes/avgle/videos.js +++ b/lib/routes/avgle/videos.js @@ -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 = { @@ -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 ? `